diff --git a/examples/cwebp.c b/examples/cwebp.c index 47a9c3b5..745380d4 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -33,11 +33,14 @@ #include "webp/encode.h" -#include "./jpegdec.h" + #include "./metadata.h" -#include "./pngdec.h" #include "./stopwatch.h" + +#include "./jpegdec.h" +#include "./pngdec.h" #include "./tiffdec.h" + #ifndef WEBP_DLL #if defined(__cplusplus) || defined(c_plusplus) extern "C" { diff --git a/examples/jpegdec.c b/examples/jpegdec.c index b2797582..d6f35c52 100644 --- a/examples/jpegdec.c +++ b/examples/jpegdec.c @@ -30,18 +30,17 @@ struct my_error_mgr { static void my_error_exit(j_common_ptr dinfo) { struct my_error_mgr* myerr = (struct my_error_mgr*)dinfo->err; - (*dinfo->err->output_message)(dinfo); + dinfo->err->output_message(dinfo); longjmp(myerr->setjmp_buffer, 1); } int ReadJPEG(FILE* in_file, WebPPicture* const pic) { int ok = 0; int stride, width, height; - uint8_t* rgb = NULL; - uint8_t* row_ptr = NULL; struct jpeg_decompress_struct dinfo; struct my_error_mgr jerr; - JSAMPARRAY buffer; + uint8_t* rgb = NULL; + JSAMPROW buffer[1]; dinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; @@ -74,20 +73,13 @@ int ReadJPEG(FILE* in_file, WebPPicture* const pic) { if (rgb == NULL) { goto End; } - row_ptr = rgb; - - buffer = (*dinfo.mem->alloc_sarray)((j_common_ptr)&dinfo, - JPOOL_IMAGE, stride, 1); - if (buffer == NULL) { - goto End; - } + buffer[0] = (JSAMPLE*)rgb; while (dinfo.output_scanline < dinfo.output_height) { if (jpeg_read_scanlines(&dinfo, buffer, 1) != 1) { goto End; } - memcpy(row_ptr, buffer[0], stride); - row_ptr += stride; + buffer[0] += stride; } jpeg_finish_decompress(&dinfo);