X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fio-libjpeg.c;h=be394c95b393a9152fe300c60bd1adbdc9391e30;hb=10eb212c1d1d1386cb2d7c57f34565802da19a74;hp=144e0b0e0a039f066099d1009513a1f57e18eef4;hpb=403cbecdeaf3cd76c845205c52818e4c6a64c15e;p=libucw.git diff --git a/images/io-libjpeg.c b/images/io-libjpeg.c index 144e0b0e..be394c95 100644 --- a/images/io-libjpeg.c +++ b/images/io-libjpeg.c @@ -75,7 +75,7 @@ libjpeg_emit_message(j_common_ptr cinfo UNUSED, int msg_level UNUSED) cinfo->err->format_message(cinfo, buf); DBG("libjpeg_emit_message(): [%d] %s", msg_level, buf); #endif -#if 1 +#if 0 // Terminate on warning? if (unlikely(msg_level == -1)) { @@ -91,8 +91,16 @@ libjpeg_emit_message(j_common_ptr cinfo UNUSED, int msg_level UNUSED) static inline uns libjpeg_fastbuf_read_prepare(struct libjpeg_read_internals *i) { + DBG("libjpeg_fb_read_prepare()"); byte *start; uns len = bdirect_read_prepare(i->fastbuf, &start); + DBG("readed %u bytes at %p", len, start); + if (!len) + { + // XXX: maybe only generate a warning and return EOI markers to recover from such errors (also in skip_input_data) + IMAGE_ERROR(i->err.io->context, IMAGE_ERROR_READ_FAILED, "Incomplete JPEG file"); + longjmp(i->err.setjmp_buf, 1); + } i->fastbuf_pos = start + len; i->src.next_input_byte = start; i->src.bytes_in_buffer = len; @@ -102,6 +110,7 @@ libjpeg_fastbuf_read_prepare(struct libjpeg_read_internals *i) static inline void libjpeg_fastbuf_read_commit(struct libjpeg_read_internals *i) { + DBG("libjpeg_fb_read_commit()"); bdirect_read_commit(i->fastbuf, i->fastbuf_pos); } @@ -125,7 +134,8 @@ libjpeg_fill_input_buffer(j_decompress_ptr cinfo) DBG("libjpeg_fill_input_buffer()"); struct libjpeg_read_internals *i = (struct libjpeg_read_internals *)cinfo; libjpeg_fastbuf_read_commit(i); - return !!libjpeg_fastbuf_read_prepare(i); + libjpeg_fastbuf_read_prepare(i); + return 1; } static void @@ -367,7 +377,11 @@ libjpeg_read_data(struct image_io *io) { case JCS_CMYK: read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_CMYK; - i->cinfo.out_color_space = JCS_YCbCr; + i->cinfo.out_color_space = JCS_CMYK; + break; + case JCS_YCCK: + read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_YCCK; + i->cinfo.out_color_space = JCS_YCCK; break; default: read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_RGB; @@ -529,6 +543,7 @@ libjpeg_write(struct image_io *io) } i.cinfo.input_components = color_space_channels[img->flags & IMAGE_COLOR_SPACE]; jpeg_set_defaults(&i.cinfo); + jpeg_set_colorspace(&i.cinfo, i.cinfo.in_color_space); if (io->jpeg_quality) jpeg_set_quality(&i.cinfo, MIN(io->jpeg_quality, 100), 1); if (io->exif_size)