From: Bastian Dehn Date: Sun, 26 Jan 2025 09:02:42 +0000 (+0100) Subject: fix convert jpg to pnm X-Git-Tag: v1.0.29^2~3^2~27 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=33a77ecfcb1e5aa94987958bb21e9ecf155f6ea4;p=sane-kds-s2000w-net.git fix convert jpg to pnm --- diff --git a/src/kds_s2000w_image_converter_netpbm.c b/src/kds_s2000w_image_converter_netpbm.c index a1c331b..937aeac 100644 --- a/src/kds_s2000w_image_converter_netpbm.c +++ b/src/kds_s2000w_image_converter_netpbm.c @@ -102,12 +102,12 @@ void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int dept jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); - int decompress_size = RGB * cinfo.output_width * cinfo.output_height; + size_t decompress_size = RGB * cinfo.output_width * cinfo.output_height; unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size); unsigned char* row = NULL; while (cinfo.output_scanline < cinfo.output_height) { - row = &decompress_data[cinfo.output_width * cinfo.output_scanline]; + row = &decompress_data[cinfo.output_width * cinfo.output_scanline * RGB]; jpeg_read_scanlines(&cinfo, &row, 1); } fclose(jpeg_stream); @@ -130,13 +130,27 @@ void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int dept } } - char* outdata = (char*) out->data; - FILE* pnm_stream = open_memstream(&outdata, &out->size); + char** outdata = malloc(sizeof(char*)); + FILE* pnm_stream = open_memstream(outdata, &out->size); pnm_writepnm(pnm_stream, pixels, cinfo.output_width, cinfo.output_height, PNM_MAXMAXVAL, PPM_FORMAT, 0); fclose(pnm_stream); + out->data = malloc(sizeof(char) * out->size); + memcpy(out->data, *outdata, out->size); + free(*outdata); + *outdata = NULL; + free(outdata); + outdata = NULL; + for (int i = 0; i < cinfo.output_height; i++) { + free(pixels[i]); + pixels[i] = NULL; + } + free(pixels); + pixels = NULL; jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); + free(decompress_data); + decompress_data = NULL; } void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out)