|
|
@@ -47,13 +47,14 @@ pipi_image_t *pipi_load_jpeg(const char *name) |
|
|
|
FILE *fp = fopen(name, "rb"); |
|
|
|
if(!fp) goto end; |
|
|
|
|
|
|
|
|
|
|
|
/* Set callbacks */ |
|
|
|
cinfo.err = jpeg_std_error(&jerr); |
|
|
|
jerr.error_exit = error_msg; |
|
|
|
jerr.emit_message = emit_msg; |
|
|
|
jerr.output_message = output_msg; |
|
|
|
jerr.format_message = format_msg; |
|
|
|
|
|
|
|
/* Initialize libjpeg */ |
|
|
|
jpeg_create_decompress(&cinfo); |
|
|
|
cinfo.client_data = 0x0; |
|
|
|
jpeg_stdio_src(&cinfo, fp); |
|
|
@@ -69,12 +70,13 @@ pipi_image_t *pipi_load_jpeg(const char *name) |
|
|
|
goto end; |
|
|
|
} |
|
|
|
|
|
|
|
/* One scanline */ |
|
|
|
image = malloc(cinfo.output_width * cinfo.output_height * 4); |
|
|
|
if(!image) goto end; |
|
|
|
|
|
|
|
scanline = malloc(cinfo.output_width * 3); |
|
|
|
|
|
|
|
/* Read scanlines, converting them to RGBA */ |
|
|
|
|
|
|
|
for(i=0; i < cinfo.output_height; i++) |
|
|
|
{ |
|
|
|
jpeg_read_scanlines(&cinfo, &scanline, 1); |
|
|
@@ -133,7 +135,6 @@ int pipi_save_jpeg(pipi_image_t *img, const char *name) |
|
|
|
|
|
|
|
data = pixels->pixels; |
|
|
|
|
|
|
|
|
|
|
|
line = malloc(img->w * 3 * sizeof(unsigned char)); |
|
|
|
if (!line) |
|
|
|
return 0; |
|
|
@@ -174,7 +175,6 @@ int pipi_save_jpeg(pipi_image_t *img, const char *name) |
|
|
|
line[j++] = ((*ptr)) & 0xff; |
|
|
|
ptr++; |
|
|
|
} |
|
|
|
/* write scanline */ |
|
|
|
jbuf = (JSAMPROW *) (&line); |
|
|
|
jpeg_write_scanlines(&cinfo, jbuf, 1); |
|
|
|
y++; |
|
|
|