From 9a51830434619045656ef4af9ae9fe6bdc414972 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 2 Feb 2024 13:01:36 +0100 Subject: [PATCH] [codec,jpeg] use winpr image for jpeg --- include/freerdp/codec/jpeg.h | 4 +- libfreerdp/CMakeLists.txt | 5 -- libfreerdp/codec/jpeg.c | 129 ++++++----------------------------- 3 files changed, 24 insertions(+), 114 deletions(-) diff --git a/include/freerdp/codec/jpeg.h b/include/freerdp/codec/jpeg.h index 2371e4889..b9621fd99 100644 --- a/include/freerdp/codec/jpeg.h +++ b/include/freerdp/codec/jpeg.h @@ -28,8 +28,8 @@ extern "C" { #endif - FREERDP_API BOOL jpeg_decompress(BYTE* input, BYTE* output, int width, int height, int size, - int bpp); + FREERDP_API BOOL jpeg_decompress(const BYTE* input, BYTE* output, int width, int height, + int size, int bpp); #ifdef __cplusplus } diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt index 168401c28..5b47d98f6 100644 --- a/libfreerdp/CMakeLists.txt +++ b/libfreerdp/CMakeLists.txt @@ -287,11 +287,6 @@ if(WITH_NEON) set(CODEC_SRCS ${CODEC_SRCS} ${CODEC_NEON_SRCS}) endif() -if(WITH_JPEG) - freerdp_include_directory_add(${JPEG_INCLUDE_DIR}) - freerdp_library_add(${JPEG_LIBRARIES}) -endif() - if(WITH_OPENH264) set(CODEC_SRCS ${CODEC_SRCS} codec/h264_openh264.c) freerdp_include_directory_add(${OPENH264_INCLUDE_DIR}) diff --git a/libfreerdp/codec/jpeg.c b/libfreerdp/codec/jpeg.c index 152095808..65c8d281e 100644 --- a/libfreerdp/codec/jpeg.c +++ b/libfreerdp/codec/jpeg.c @@ -20,6 +20,7 @@ #include #include +#include #include @@ -27,121 +28,35 @@ #ifdef WITH_JPEG -#define XMD_H - -#include - -struct mydata_decomp -{ - char* data; - int data_bytes; -}; - -/*****************************************************************************/ -static void my_init_source(j_decompress_ptr cinfo) -{ -} - -/*****************************************************************************/ -static boolean my_fill_input_buffer(j_decompress_ptr cinfo) -{ - struct mydata_decomp* md; - - md = (struct mydata_decomp*)(cinfo->client_data); - cinfo->src->next_input_byte = (unsigned char*)(md->data); - cinfo->src->bytes_in_buffer = md->data_bytes; - return 1; -} - -/*****************************************************************************/ -static void my_skip_input_data(j_decompress_ptr cinfo, long num_bytes) -{ -} - -/*****************************************************************************/ -static boolean my_resync_to_restart(j_decompress_ptr cinfo, int desired) -{ - return 1; -} - -/*****************************************************************************/ -static void my_term_source(j_decompress_ptr cinfo) -{ -} - -/*****************************************************************************/ -static int do_decompress(char* comp_data, int comp_data_bytes, int* width, int* height, int* bpp, - char* decomp_data, int* decomp_data_bytes) -{ - struct jpeg_decompress_struct cinfo = { 0 }; - struct jpeg_error_mgr jerr; - struct jpeg_source_mgr src_mgr = { 0 }; - struct mydata_decomp md = { 0 }; - JSAMPROW row_pointer[1] = { 0 }; - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - - cinfo.src = &src_mgr; - src_mgr.init_source = my_init_source; - src_mgr.fill_input_buffer = my_fill_input_buffer; - src_mgr.skip_input_data = my_skip_input_data; - src_mgr.resync_to_restart = my_resync_to_restart; - src_mgr.term_source = my_term_source; - - md.data = comp_data; - md.data_bytes = comp_data_bytes; - cinfo.client_data = &md; - - jpeg_read_header(&cinfo, 1); - - cinfo.out_color_space = JCS_RGB; - - *width = cinfo.image_width; - *height = cinfo.image_height; - *bpp = cinfo.num_components * 8; - - jpeg_start_decompress(&cinfo); - - while (cinfo.output_scanline < cinfo.image_height) - { - row_pointer[0] = (JSAMPROW)decomp_data; - jpeg_read_scanlines(&cinfo, row_pointer, 1); - decomp_data += cinfo.image_width * cinfo.num_components; - } - *decomp_data_bytes = cinfo.output_width * cinfo.output_height * cinfo.num_components; - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - return 0; -} - /* jpeg decompress */ -BOOL jpeg_decompress(BYTE* input, BYTE* output, int width, int height, int size, int bpp) +BOOL jpeg_decompress(const BYTE* input, BYTE* output, int width, int height, int size, int bpp) { - int lwidth; - int lheight; - int lbpp; - int ldecomp_data_bytes; + BOOL rc = FALSE; if (bpp != 24) - { - return 0; - } - if (do_decompress((char*)input, size, &lwidth, &lheight, &lbpp, (char*)output, - &ldecomp_data_bytes) != 0) - { - return 0; - } - if (lwidth != width || lheight != height || lbpp != bpp) - { - return 0; - } - return 1; + return FALSE; + + wImage* image = winpr_image_new(); + if (!image) + goto fail; + + if (winpr_image_read_buffer(image, input, size) <= 0) + goto fail; + + if ((image->width != width) || (image->height != height) || (image->bitsPerPixel != bpp)) + goto fail; + + memcpy(output, image->data, 1ull * image->scanline * image->height); + rc = TRUE; + +fail: + winpr_image_free(image, TRUE); + return rc; } #else -BOOL jpeg_decompress(BYTE* input, BYTE* output, int width, int height, int size, int bpp) +BOOL jpeg_decompress(const BYTE* input, BYTE* output, int width, int height, int size, int bpp) { return 0; }