#include "lib/mempool.h"
#include "lib/fastbuf.h"
#include "images/images.h"
+#include "images/error.h"
+#include "images/color.h"
#include "images/io-main.h"
+
#include <stdio.h>
#include <sys/types.h>
#include <jpeglib.h>
struct libjpeg_err *e = (struct libjpeg_err *)cinfo->err;
byte buf[JMSG_LENGTH_MAX];
e->pub.format_message(cinfo, buf);
- image_thread_err_dup(e->io->thread, IMAGE_ERR_READ_FAILED, buf);
+ IMAGE_ERROR(e->io->context, IMAGE_ERROR_READ_FAILED, "%s", buf);
longjmp(e->setjmp_buf, 1);
}
struct libjpeg_err *e = (struct libjpeg_err *)cinfo->err;
byte buf[JMSG_LENGTH_MAX];
e->pub.format_message(cinfo, buf);
- image_thread_err_dup(e->io->thread, IMAGE_ERR_WRITE_FAILED, buf);
+ IMAGE_ERROR(e->io->context, IMAGE_ERROR_WRITE_FAILED, "%s", buf);
longjmp(e->setjmp_buf, 1);
}
{
num_bytes -= i->src.bytes_in_buffer;
libjpeg_fastbuf_read_commit(i);
- bskip(i->fastbuf, num_bytes);
+ if (!bskip(i->fastbuf, num_bytes))
+ {
+ IMAGE_ERROR(i->err.io->context, IMAGE_ERROR_READ_FAILED, "Incomplete JPEG file");
+ longjmp(i->err.setjmp_buf, 1);
+ }
libjpeg_fastbuf_read_prepare(i);
}
}
i->dest.free_in_buffer = len;
if (!len)
{
- image_thread_err(i->err.io->thread, IMAGE_ERR_WRITE_FAILED, "Unexpected end of stream");
+ IMAGE_ERROR(i->err.io->context, IMAGE_ERROR_WRITE_FAILED, "Unexpected end of stream");
longjmp(i->err.setjmp_buf, 1);
}
}
return TRUE;
}
-#ifdef CONFIG_IMAGES_EXIF
-
static inline uns
libjpeg_read_byte(struct libjpeg_read_internals *i)
{
return TRUE;
}
byte header[6];
- for (uns j = 0; j < 6; j++)
- {
- header[j] = libjpeg_read_byte(i);
- DBG("0x%02x", header[j]);
- }
- //libjpeg_read_buf(i, header, 6);
+ libjpeg_read_buf(i, header, 6);
if (memcmp(header, libjpeg_exif_header, 6))
{
libjpeg_skip_input_data(cinfo, len - 6);
return TRUE;
}
-#endif
-
static void
libjpeg_read_cancel(struct image_io *io)
{
i->src.resync_to_restart = jpeg_resync_to_restart;
i->src.term_source = libjpeg_term_source;
-#ifdef CONFIG_IMAGES_EXIF
if (io->flags & IMAGE_IO_WANT_EXIF)
jpeg_set_marker_processor(&i->cinfo, JPEG_APP0 + 1, libjpeg_app1_preprocessor);
-#endif
/* Read JPEG header and setup decompression options */
DBG("Reading image header");
break;
default:
jpeg_destroy_decompress(&i->cinfo);
- image_thread_err(io->thread, IMAGE_ERR_INVALID_PIXEL_FORMAT, "Unsupported color space.");
+ IMAGE_ERROR(io->context, IMAGE_ERROR_INVALID_PIXEL_FORMAT, "Unsupported color space.");
return 0;
}
break;
default:
jpeg_destroy_compress(&i.cinfo);
- image_thread_err(io->thread, IMAGE_ERR_INVALID_PIXEL_FORMAT, "Unsupported pixel format.");
+ IMAGE_ERROR(io->context, IMAGE_ERROR_INVALID_PIXEL_FORMAT, "Unsupported pixel format.");
return 0;
}
jpeg_set_defaults(&i.cinfo);
if (io->jpeg_quality)
jpeg_set_quality(&i.cinfo, MIN(io->jpeg_quality, 100), 1);
-#ifdef CONFIG_IMAGES_EXIF
if (io->exif_size)
{
/* According to the Exif specification, the Exif APP1 marker has to follow immediately after the SOI,
i.cinfo.write_JFIF_header = FALSE;
i.cinfo.write_Adobe_marker = FALSE;
}
-#endif
/* Compress the image */
jpeg_start_compress(&i.cinfo, TRUE);
-#ifdef CONFIG_IMAGES_EXIF
if (io->exif_size)
{
DBG("Writing EXIF");
jpeg_write_marker(&i.cinfo, JPEG_APP0 + 1, io->exif_data, io->exif_size);
}
-#endif
switch (img->pixel_size)
{
/* grayscale or RGB */