FreeRDP
Loading...
Searching...
No Matches
jpeg.c
1
19
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#if !defined(WITHOUT_FREERDP_3x_DEPRECATED)
30#ifdef WITH_JPEG
31
32/* jpeg decompress */
33BOOL jpeg_decompress(const BYTE* input, BYTE* output, int width, int height, int size, int bpp)
34{
35 BOOL rc = FALSE;
36
37 if (bpp != 24)
38 return FALSE;
39 if (width <= 0)
40 return FALSE;
41 if (height <= 0)
42 return FALSE;
43 if (size <= 0)
44 return FALSE;
45
46 wImage* image = winpr_image_new();
47 if (!image)
48 goto fail;
49
50 if (winpr_image_read_buffer(image, input, WINPR_ASSERTING_INT_CAST(size_t, size)) <= 0)
51 goto fail;
52
53 if ((image->width != WINPR_ASSERTING_INT_CAST(size_t, width)) ||
54 (image->height != WINPR_ASSERTING_INT_CAST(size_t, height)) ||
55 (image->bitsPerPixel != WINPR_ASSERTING_INT_CAST(size_t, bpp)))
56 goto fail;
57
58 const size_t stride = image->width * image->bitsPerPixel / 8;
59 if (stride < image->scanline)
60 goto fail;
61
62 for (UINT32 y = 0; y < image->height; y++)
63 {
64 const void* src = &image->data[y * image->scanline];
65 void* dst = &output[y * stride];
66 memcpy(dst, src, stride);
67 }
68 rc = TRUE;
69
70fail:
71 winpr_image_free(image, TRUE);
72 return rc;
73}
74
75#else
76
77BOOL jpeg_decompress(WINPR_ATTR_UNUSED const BYTE* input, WINPR_ATTR_UNUSED BYTE* output,
78 WINPR_ATTR_UNUSED int width, WINPR_ATTR_UNUSED int height,
79 WINPR_ATTR_UNUSED int size, WINPR_ATTR_UNUSED int bpp)
80{
81 WLog_ERR("TODO", "TODO: implement");
82 return 0;
83}
84
85#endif
86#endif