return 0;
}
- /* Prepare the image ... FIXME: use libjpeg feature to speed up downscale */
+ /* Prepare the image */
struct image_io_read_data_internals rdi;
- if (unlikely(!image_io_read_data_prepare(&rdi, io, i->cinfo.image_width, i->cinfo.image_height, io->flags)))
+ if (io->cols <= (i->cinfo.image_width >> 3) && io->rows <= (i->cinfo.image_height >> 3))
+ {
+ DBG("Scaling to 1/8");
+ i->cinfo.scale_num = 1;
+ i->cinfo.scale_denom = 8;
+ }
+ else if (io->cols <= (i->cinfo.image_width >> 2) && io->rows <= (i->cinfo.image_height >> 2))
+ {
+ DBG("Scaling to 1/4");
+ i->cinfo.scale_num = 1;
+ i->cinfo.scale_denom = 4;
+ }
+ else if (io->cols <= (i->cinfo.image_width >> 1) && io->rows <= (i->cinfo.image_height >> 1))
+ {
+ DBG("Scaling to 1/2");
+ i->cinfo.scale_num = 1;
+ i->cinfo.scale_denom = 2;
+ }
+ jpeg_calc_output_dimensions(&i->cinfo);
+ DBG("Output dimensions %ux%u", (uns)i->cinfo.output_width, (uns)i->cinfo.output_height);
+ if (unlikely(!image_io_read_data_prepare(&rdi, io, i->cinfo.output_width, i->cinfo.output_height, io->flags)))
{
jpeg_destroy_decompress(&i->cinfo);
return 0;
if (io->cols != rdi->image->cols || io->rows != rdi->image->rows)
{
DBG("Scaling image");
- rdi->need_transformations = io->flags != rdi->image->flags;
rdi->need_destroy = rdi->need_transformations || !io->pool;
struct image *img = image_new(io->thread, io->cols, io->rows, rdi->image->flags, rdi->need_transformations ? NULL : io->pool);
if (unlikely(!img))
if ((io->flags ^ rdi->image->flags) & IMAGE_ALPHA)
{
DBG("Aplying background");
- rdi->need_transformations = 0;
rdi->need_destroy = rdi->need_transformations || !io->pool;
struct image *img = image_new(io->thread, io->cols, io->rows, io->flags, rdi->need_transformations ? NULL : io->pool);
if (unlikely(!img))
}
rdi->image = img;
}
-
- ASSERT(!rdi->need_transformations);
}
/* Success */