1 Short README, perhaps not too useful.
3 qscale (the "q" is for "quick" -- the confusion with "quantization scale" is
4 unfortunate, but there are only so many short names in the world) is a fast
5 JPEG-to-JPEG-only up- and downscaler. On my 1.2GHz Core Duo laptop (using
6 only one core), qscale is 3-4 times as fast as ImageMagick for downscaling
7 large JPEGs (~10Mpix from my digital camera) to more moderate-sized JPEGs
8 for web use etc. (like 640x480) without sacrificing quality. (Benchmarking must
9 be done with a bit of care, though, in particular due to different subsampling
10 options possible etc.) Most of the time in qscale's case is used on reading in
11 the original image using libjpeg, which is shared among the two. However, it
12 would probably not be realistic to exclude the libjpeg time, as most (although
13 not all) real-world scaling tasks would indeed need to read and decode the
16 Note: This is not to denounce ImageMagick in any way. It is a fine library,
17 capable of doing much more than qscale can ever hope to do. Comparison between
18 the two are mainly to provide a well-known reference, and to demonstrate that
19 more specific tools than usually be made faster than generic tools.
21 qscale is not novel in any way, nor is it perfect (far from it; it's more of a
22 proof of concept than anything else) -- it is mainly a piece of engineering.
23 However, the following techniques deserve some kind of mention:
25 - qscale recognizes that JPEGs are usually stored in the YCbCr colorspace and
26 not RGB. (ImageMagick can, too, if you give it the right flags, but not all
27 its operations are well-defined in YCbCr.) Although conversion between the
28 two is cheap, it is not free, and it is not needed for scaling. Thus, qscale
30 - qscale recognizes that JPEGs are stored with the color channels mostly
31 separate (planar) and not chunked. Scaling does not need to be done on
32 chunked data -- in fact, mostly, scaling is easier to do on planar data.
33 Thus, no conversion to chunked before scaling (and no need to convert back
34 to planar afterwards). (Note: Some SIMD properties might be easier to
35 exploit on a chunked representation. It's usually not worth it in total,
37 - qscale can utilize the SSE instruction set found in almost all modern
38 x86-compatible processors to do more work in the same amount of instructions
39 (It can also use the SSE3 instruction set, although the extra boost on top
40 of SSE is smaller. In time, it will utilize the SSE extensions known as
41 SSE4.1, which can help even more.) It takes care to align the image data and
42 memory accesses on the right boundaries wherever it makes sense.
43 - qscale recognizes (like almost any decent scaling program) that most
44 practical filter kernels are separable, so scaling can be done in two
45 sequential simpler passes (horizontal and vertical) instead of one. The
46 order does matter, though -- I've found doing the vertical pass (in
47 cache-friendly order, doing multiple neighboring pixels at a time to
48 exploit that the processor reads in entire cache lines and not individual
49 bytes at a time) before the horizontal to be superior, in particular
50 because this case is easier to SIMD-wise.
51 - qscale understands that JPEGs are typically subsampled; ie., that the
52 different color components are not stored at the same resolution. On
53 the web, this is typically because the eye is less sensitive to color
54 (chroma) information and as such much of it can safely be stored in
55 a lower resolution to reduce file size without much visible quality
56 degradation; in the JPEGs stored by a digital camera, it is simply
57 because much of the color information is interpolated anyway (since
58 the individual CCD dots are sensitive to either red, green or blue,
59 not all at the same time), so it would not make much sense to pretend
60 there is full color information. qscale does not ask libjpeg to
61 interpolate the "missing" color information nor to downscale the
62 already-downscaled color channels as ImageMagick does, but instead
63 does a single scaling pass from the original resolution to the final
64 subsampled resolution. (This is impossible for any program working
65 in RGB mode, or chunked YCbCr.) This increases both speed and quality,
66 although the effect on the latter is not particularly large.
68 The following optimizations are possible but not done (yet?):
70 - qscale does not do the IDCT itself, even though there is improvement
71 potential over libjpeg's IDCT. (There is an unmaintained and little-used fork
72 of libjpeg called libjpeg-mmx that demonstrates this quite well.) In fact,
73 since the DCT can be viewed as just another (separable, but not
74 time-invariant) FIR filter, the quantization scaling and IDCT could probably
75 be folded into the scaling in many cases, in particular those where the
76 filter kernel is large (ie. large amounts of scaling).
77 - qscale does not use multiple processors or cores (although different cores
78 can of course work on different images at the same time).
79 - qscale does not make very good use of the extra eight SSE registers found
80 on 64-bit x86-compatible (usually called amd64 or x86-64) machines. In
81 fact, out of the box it might not even compile on such machines.
83 Finally, a word of advice: Even the fastest scaler can never be as fast as not
84 scaling. If you can do less work, or move it to a time where it is less user
85 visible, do that no matter how you scale your pictures. In particular, cache
86 your downscaled pictures if you can, preferrably ahead of time. If you cannot
87 predict in advance exactly what size (or sizes) you'll need, consider making
88 mipmaps (ie. one image of half the resolution each way, another one of a quarter
89 the resolution each way etc., down to a reasonable size) and scaling from them
90 instead. It will be much faster (primarily due to less loading time) and the
91 difference in quality is nearly impossible to detect, at least in my tests.
93 qscale is Copyright 2008 Steinar H. Gunderson <sgunderson@bigfoot.com>, and
94 licensed under the GNU General Public License, version 2. The full text of
95 the GPLv2 can be found in the included COPYING file.