ext/webp_ffi/util.c in webp-ffi-0.2.2 vs ext/webp_ffi/util.c in webp-ffi-0.2.3
- old
+ new
@@ -61,14 +61,13 @@
static int UtilReadJPEG(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;
+ JSAMPROW buffer[1];
dinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer)) {
@@ -80,11 +79,10 @@
jpeg_create_decompress(&dinfo);
jpeg_stdio_src(&dinfo, in_file);
jpeg_read_header(&dinfo, TRUE);
dinfo.out_color_space = JCS_RGB;
- dinfo.dct_method = JDCT_IFAST;
dinfo.do_fancy_upsampling = TRUE;
jpeg_start_decompress(&dinfo);
if (dinfo.output_components != 3) {
@@ -97,37 +95,29 @@
rgb = (uint8_t*)malloc(stride * height);
if (rgb == NULL) {
goto End;
}
- row_ptr = rgb;
+ buffer[0] = (JSAMPLE*)rgb;
- buffer = (*dinfo.mem->alloc_sarray) ((j_common_ptr) &dinfo,
- JPOOL_IMAGE, stride, 1);
- if (buffer == NULL) {
- goto End;
- }
-
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);
jpeg_destroy_decompress(&dinfo);
// WebP conversion.
pic->width = width;
pic->height = height;
ok = WebPPictureImportRGB(pic, rgb, stride);
+ if (!ok) goto Error;
End:
- if (rgb) {
- free(rgb);
- }
+ free(rgb);
return ok;
}
static void PNGAPI error_function(png_structp png, png_const_charp dummy) {
(void)dummy; // remove variable-unused warning