FreeRDP
Loading...
Searching...
No Matches
jpeg.c
1
20#include <freerdp/config.h>
21
22#include <winpr/stream.h>
23#include <winpr/image.h>
24
25#include <freerdp/codec/color.h>
26
27#include <freerdp/codec/jpeg.h>
28
29#ifdef WITH_JPEG
30
31/* jpeg decompress */
32BOOL jpeg_decompress(const BYTE* input, BYTE* output, int width, int height, int size, int bpp)
33{
34 BOOL rc = FALSE;
35
36 if (bpp != 24)
37 return FALSE;
38 if (width <= 0)
39 return FALSE;
40 if (height <= 0)
41 return FALSE;
42 if (size <= 0)
43 return FALSE;
44
45 wImage* image = winpr_image_new();
46 if (!image)
47 goto fail;
48
49 if (winpr_image_read_buffer(image, input, WINPR_ASSERTING_INT_CAST(size_t, size)) <= 0)
50 goto fail;
51
52 if ((image->width != WINPR_ASSERTING_INT_CAST(size_t, width)) ||
53 (image->height != WINPR_ASSERTING_INT_CAST(size_t, height)) ||
54 (image->bitsPerPixel != WINPR_ASSERTING_INT_CAST(size_t, bpp)))
55 goto fail;
56
57 memcpy(output, image->data, 1ull * image->scanline * image->height);
58 rc = TRUE;
59
60fail:
61 winpr_image_free(image, TRUE);
62 return rc;
63}
64
65#else
66
67BOOL jpeg_decompress(WINPR_ATTR_UNUSED const BYTE* input, WINPR_ATTR_UNUSED BYTE* output,
68 WINPR_ATTR_UNUSED int width, WINPR_ATTR_UNUSED int height,
69 WINPR_ATTR_UNUSED int size, WINPR_ATTR_UNUSED int bpp)
70{
71 WLog_ERR("TODO", "TODO: implement");
72 return 0;
73}
74
75#endif