From 2ec3431fa58fe844c56b59eb2ad72a84b9cf7451 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Mon, 31 Jul 2006 15:08:02 +0200 Subject: [PATCH] much faster downscaling of JPEGs --- images/io-libjpeg.c | 24 ++++++++++++++++++++++-- images/io-main.c | 4 ---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/images/io-libjpeg.c b/images/io-libjpeg.c index f7458124..876c1720 100644 --- a/images/io-libjpeg.c +++ b/images/io-libjpeg.c @@ -257,9 +257,29 @@ libjpeg_read_data(struct image_io *io) 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; diff --git a/images/io-main.c b/images/io-main.c index 15e76fbb..03a36cc2 100644 --- a/images/io-main.c +++ b/images/io-main.c @@ -264,7 +264,6 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image 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)) @@ -286,7 +285,6 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image 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)) @@ -303,8 +301,6 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image } rdi->image = img; } - - ASSERT(!rdi->need_transformations); } /* Success */ -- 2.39.5