1 | /*
|
---|
2 | * jfdctfst.c
|
---|
3 | *
|
---|
4 | * Copyright (C) 1994-1996, Thomas G. Lane.
|
---|
5 | * This file is part of the Independent JPEG Group's software.
|
---|
6 | * For conditions of distribution and use, see the accompanying README file.
|
---|
7 | *
|
---|
8 | * This file contains a fast, not so accurate integer implementation of the
|
---|
9 | * forward DCT (Discrete Cosine Transform).
|
---|
10 | *
|
---|
11 | * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
|
---|
12 | * on each column. Direct algorithms are also available, but they are
|
---|
13 | * much more complex and seem not to be any faster when reduced to code.
|
---|
14 | *
|
---|
15 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for
|
---|
16 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
|
---|
17 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell
|
---|
18 | * JPEG textbook (see REFERENCES section in file README). The following code
|
---|
19 | * is based directly on figure 4-8 in P&M.
|
---|
20 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is
|
---|
21 | * possible to arrange the computation so that many of the multiplies are
|
---|
22 | * simple scalings of the final outputs. These multiplies can then be
|
---|
23 | * folded into the multiplications or divisions by the JPEG quantization
|
---|
24 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds
|
---|
25 | * to be done in the DCT itself.
|
---|
26 | * The primary disadvantage of this method is that with fixed-point math,
|
---|
27 | * accuracy is lost due to imprecise representation of the scaled
|
---|
28 | * quantization values. The smaller the quantization table entry, the less
|
---|
29 | * precise the scaled value, so this implementation does worse with high-
|
---|
30 | * quality-setting files than with low-quality ones.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #define JPEG_INTERNALS
|
---|
34 | #include "jinclude.h"
|
---|
35 | #include "jpeglib.h"
|
---|
36 | #include "jdct.h" /* Private declarations for DCT subsystem */
|
---|
37 |
|
---|
38 | #ifdef DCT_IFAST_SUPPORTED
|
---|
39 |
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * This module is specialized to the case DCTSIZE = 8.
|
---|
43 | */
|
---|
44 |
|
---|
45 | #if DCTSIZE != 8
|
---|
46 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
|
---|
47 | #endif
|
---|
48 |
|
---|
49 |
|
---|
50 | /* Scaling decisions are generally the same as in the LL&M algorithm;
|
---|
51 | * see jfdctint.c for more details. However, we choose to descale
|
---|
52 | * (right shift) multiplication products as soon as they are formed,
|
---|
53 | * rather than carrying additional fractional bits into subsequent additions.
|
---|
54 | * This compromises accuracy slightly, but it lets us save a few shifts.
|
---|
55 | * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
|
---|
56 | * everywhere except in the multiplications proper; this saves a good deal
|
---|
57 | * of work on 16-bit-int machines.
|
---|
58 | *
|
---|
59 | * Again to save a few shifts, the intermediate results between pass 1 and
|
---|
60 | * pass 2 are not upscaled, but are represented only to integral precision.
|
---|
61 | *
|
---|
62 | * A final compromise is to represent the multiplicative constants to only
|
---|
63 | * 8 fractional bits, rather than 13. This saves some shifting work on some
|
---|
64 | * machines, and may also reduce the cost of multiplication (since there
|
---|
65 | * are fewer one-bits in the constants).
|
---|
|
---|