3

I'm currently implementing a jpeg resizer in C++ using the jpeglib-turbo library.

I've been given the target of 100 milli-seconds for JPEG decompression and recompression using the library. The best I can come up with using the recommended optimisation settings (documented in jpeglib-turbo usage.txt) is around 320ms, so I'm wondering is 100ms even possible/realistic? This would be to decompress/recompress an image of 3000x4000 px from around 6Mb in size to 130Kb.

The code that I'm using for fast decompression is:

    dinfo.dct_method = JDCT_IFAST;
    dinfo.do_fancy_upsampling = FALSE;
    dinfo.two_pass_quantize = FALSE;
    dinfo.dither_mode = JDITHER_ORDERED;
    dinfo.scale_num = 1/8;
Damien
  • 1,490
  • 1
  • 8
  • 17
Kevin Colgan
  • 199
  • 2
  • 6
  • Out of curiosity, why do you need it to be so fast? 320ms for a 6MB JPEG is pretty speedy. – Bojangles Apr 13 '12 at 18:41
  • 1
    You haven't mentioned a platform. Is this for mobile? desktop? single or multithreaded? I have some fast "DCT thumbnail" code that I've been working on. On my 2GHz Core i7 (using a single thread), it can extract a 1/8 sized RGB32 image from 6 megabytes of JPEG data (a 4000x4000 image) in about 120ms. To recompress that 500x500 image to 130KB would probably take another 40-100ms (I haven't done extreme optimization on the compressor yet). The time-critical portion of thumbnail extract code is written in 64-bit assembly language. Contact me for more info (bitbank@pobox.com). – BitBank May 08 '12 at 19:21
  • 2
    is this project open source by any chance? post a link :) – kritzikratzi Jul 20 '12 at 12:59
  • The first thing I notice is that `dinfo.scale_num = 1/8` is in fact equivalent to `dinfo.scale_num = 0` because of integer aritmetics in C++. – Antonio Aug 04 '22 at 12:11
  • What type is `dinfo`? Which machine were you running your code? And, you should make clear you were targeting to downscale the input image by a factor 8, which is not really jpeg compression (although supported by the libjpeg library). – Antonio Aug 04 '22 at 12:25

1 Answers1

4

Thanks for the answers.

It is actually possible to decompress and re-compress in around 100ms. After contacting the writer of libjpeg-turbo he told me that the dinfo.scale_num property I was using was wrong. This property is the scale numerator - I also needed to set the scale_denom (denominator) property.

So the good code would be:

 dinfo.dct_method = JDCT_IFAST;
 dinfo.do_fancy_upsampling = FALSE;
 dinfo.two_pass_quantize = FALSE;
 dinfo.dither_mode = JDITHER_ORDERED;
 dinfo.scale_num = 1;
 dinfo.scale_denom = 8;

I want the code to be so fast as the image scaling should be imperceptible for the user as it's in a client application where speed/user-experience is the most important thing.

Kevin Colgan
  • 199
  • 2
  • 6