4
* This file is part of the Independent JPEG Group's software.
5
* The IJG code is distributed under the terms reproduced here:
12
* 1. We don't promise that this software works. (But if you find any bugs,
13
* please let us know!)
14
* 2. You can use this software for whatever you want. You don't have to
16
* 3. You may not pretend that you wrote this software. If you use it in a
17
* program, you must acknowledge somewhere in your documentation that
18
* you've used the IJG code.
22
* The authors make NO WARRANTY or representation, either express or implied,
23
* with respect to this software, its quality, accuracy, merchantability, or
24
* fitness for a particular purpose. This software is provided "AS IS", and
25
* you, its user, assume the entire risk as to its quality and accuracy.
27
* This software is copyright (C) 1991, 1992, Thomas G. Lane.
28
* All Rights Reserved except as specified below.
30
* Permission is hereby granted to use, copy, modify, and distribute this
31
* software (or portions thereof) for any purpose, without fee, subject to
33
* (1) If any part of the source code for this software is distributed, then
34
* this copyright and no-warranty notice must be included unaltered; and any
35
* additions, deletions, or changes to the original files must be clearly
36
* indicated in accompanying documentation.
37
* (2) If only executable code is distributed, then the accompanying
38
* documentation must state that "this software is based in part on the
39
* work of the Independent JPEG Group".
40
* (3) Permission for use of this software is granted only if the user
41
* accepts full responsibility for any undesirable consequences; the authors
42
* accept NO LIABILITY for damages of any kind.
44
* These conditions apply to any software derived from or based on the IJG
45
* code, not just to the unmodified library. If you use our work, you ought
48
* Permission is NOT granted for the use of any IJG author's name or company
49
* name in advertising or publicity relating to this software or products
50
* derived from it. This software may be referred to only as
51
* "the Independent JPEG Group's software".
53
* We specifically permit and encourage the use of this software as the
54
* basis of commercial products, provided that all warranty or liability
55
* claims are assumed by the product vendor.
61
* The "official" archive site for this software is ftp.uu.net (Internet
62
* address 192.48.96.9). The most recent released version can always be
63
* found there in directory graphics/jpeg. This particular version will
64
* be archived as graphics/jpeg/jpegsrc.v6a.tar.gz. If you are on the
65
* Internet, you can retrieve files from ftp.uu.net by standard anonymous
66
* FTP. If you don't have FTP access, UUNET's archives are also available
67
* via UUCP; contact help@uunet.uu.net for information on retrieving files
70
* Numerous Internet sites maintain copies of the UUNET files. However,
71
* only ftp.uu.net is guaranteed to have the latest official version.
73
* You can also obtain this software in DOS-compatible "zip" archive
74
* format from the SimTel archives (ftp.coast.net:/SimTel/msdos/graphics/),
75
* or on CompuServe in the Graphics Support forum (GO CIS:GRAPHSUP),
76
* library 12 "JPEG Tools". Again, these versions may sometimes lag behind
77
* the ftp.uu.net release.
79
* The JPEG FAQ (Frequently Asked Questions) article is a useful source of
80
* general information about JPEG. It is updated constantly and therefore
81
* is not included in this distribution. The FAQ is posted every two weeks
82
* to Usenet newsgroups comp.graphics.misc, news.answers, and other groups.
83
* You can always obtain the latest version from the news.answers archive
84
* at rtfm.mit.edu. By FTP, fetch /pub/usenet/news.answers/jpeg-faq/part1
85
* and .../part2. If you don't have FTP, send e-mail to
86
* mail-server@rtfm.mit.edu with body
87
* send usenet/news.answers/jpeg-faq/part1
88
* send usenet/news.answers/jpeg-faq/part2
93
* This file contains the basic inverse-DCT transformation subroutine.
95
* This implementation is based on an algorithm described in
96
* C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
97
* Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
98
* Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
99
* The primary algorithm described there uses 11 multiplies and 29 adds.
100
* We use their alternate method with 12 multiplies and 32 adds.
101
* The advantage of this method is that no data path contains more than one
102
* multiplication; this allows a very simple and accurate implementation in
103
* scaled fixed-point arithmetic, with a minimal number of shifts.
106
* CHANGES FOR BERKELEY MPEG
107
* =========================
109
* This file has been altered to use the Berkeley MPEG header files,
110
* to add the capability to handle sparse DCT matrices efficiently,
111
* and to relabel the inverse DCT function as well as the file
112
* (formerly jidctint.c).
114
* I've made lots of modifications to attempt to take advantage of the
115
* sparse nature of the DCT matrices we're getting. Although the logic
116
* is cumbersome, it's straightforward and the resulting code is much
119
* A better way to do this would be to pass in the DCT block as a sparse
120
* matrix, perhaps with the difference cases encoded.
128
/* We assume that right shift corresponds to signed division by 2 with
129
* rounding towards minus infinity. This is correct for typical "arithmetic
130
* shift" instructions that shift in copies of the sign bit. But some
131
* C compilers implement >> with an unsigned shift. For these machines you
132
* must define RIGHT_SHIFT_IS_UNSIGNED.
133
* RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
134
* It is only applied with constant shift counts. SHIFT_TEMPS must be
135
* included in the variables of any routine using RIGHT_SHIFT.
138
#ifdef RIGHT_SHIFT_IS_UNSIGNED
139
#define SHIFT_TEMPS INT32 shift_temp;
140
#define RIGHT_SHIFT(x,shft) \
141
((shift_temp = (x)) < 0 ? \
142
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
143
(shift_temp >> (shft)))
146
#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
150
* This routine is specialized to the case DCTSIZE = 8.
154
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
159
* A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT
160
* on each column. Direct algorithms are also available, but they are
161
* much more complex and seem not to be any faster when reduced to code.
163
* The poop on this scaling stuff is as follows:
165
* Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
166
* larger than the true IDCT outputs. The final outputs are therefore
167
* a factor of N larger than desired; since N=8 this can be cured by
168
* a simple right shift at the end of the algorithm. The advantage of
169
* this arrangement is that we save two multiplications per 1-D IDCT,
170
* because the y0 and y4 inputs need not be divided by sqrt(N).
172
* We have to do addition and subtraction of the integer inputs, which
173
* is no problem, and multiplication by fractional constants, which is
174
* a problem to do in integer arithmetic. We multiply all the constants
175
* by CONST_SCALE and convert them to integer constants (thus retaining
176
* CONST_BITS bits of precision in the constants). After doing a
177
* multiplication we have to divide the product by CONST_SCALE, with proper
178
* rounding, to produce the correct output. This division can be done
179
* cheaply as a right shift of CONST_BITS bits. We postpone shifting
180
* as long as possible so that partial sums can be added together with
181
* full fractional precision.
183
* The outputs of the first pass are scaled up by PASS1_BITS bits so that
184
* they are represented to better-than-integral precision. These outputs
185
* require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
186
* with the recommended scaling. (To scale up 12-bit sample data further, an
187
* intermediate INT32 array would be needed.)
189
* To avoid overflow of the 32-bit intermediate results in pass 2, we must
190
* have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
191
* shows that the values given below are the most effective.
194
#ifdef EIGHT_BIT_SAMPLES
197
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
200
#define ONE ((INT32) 1)
202
#define CONST_SCALE (ONE << CONST_BITS)
204
/* Convert a positive real constant to an integer scaled by CONST_SCALE.
205
* IMPORTANT: if your compiler doesn't do this arithmetic at compile time,
206
* you will pay a significant penalty in run time. In that case, figure
207
* the correct integer constant values and insert them by hand.
210
#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
212
/* When adding two opposite-signed fixes, the 0.5 cancels */
213
#define FIX2(x) ((INT32) ((x) * CONST_SCALE))
215
/* Descale and correctly round an INT32 value that's scaled by N bits.
216
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding
217
* the fudge factor is correct for either sign of X.
220
#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
222
/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
223
* For 8-bit samples with the recommended scaling, all the variable
224
* and constant values involved are no more than 16 bits wide, so a
225
* 16x16->32 bit multiply can be used instead of a full 32x32 multiply;
226
* this provides a useful speedup on many machines.
227
* There is no way to specify a 16x16->32 multiply in portable C, but
228
* some C compilers will do the right thing if you provide the correct
229
* combination of casts.
230
* NB: for 12-bit samples, a full 32-bit multiplication will be needed.
233
#ifdef EIGHT_BIT_SAMPLES
234
#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
235
#define MULTIPLY(var,const) (((INT16) (var)) * ((INT16) (const)))
237
#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
238
#define MULTIPLY(var,const) (((INT16) (var)) * ((INT32) (const)))
242
#ifndef MULTIPLY /* default definition */
243
#define MULTIPLY(var,const) ((var) * (const))
246
#ifndef NO_SPARSE_DCT
247
#define SPARSE_SCALE_FACTOR 8
250
/* Precomputed idct value arrays. */
252
static DCTELEM PreIDCT[64][64];
256
*--------------------------------------------------------------
260
* Pre-computes singleton coefficient IDCT values.
268
*--------------------------------------------------------------
270
void init_pre_idct() {
273
for (i=0; i<64; i++) {
274
memset((char *) PreIDCT[i], 0, 64*sizeof(DCTELEM));
275
PreIDCT[i][i] = 1 << SPARSE_SCALE_FACTOR;
276
j_rev_dct(PreIDCT[i]);
283
for(pos=0;pos<64;pos++) {
284
ndataptr = PreIDCT[pos];
286
for(rr=0; rr<4; rr++) {
288
ndataptr[i] = ndataptr[i]/256;
302
#ifndef NO_SPARSE_DCT
306
*--------------------------------------------------------------
308
* j_rev_dct_sparse --
310
* Performs the inverse DCT on one block of coefficients.
318
*--------------------------------------------------------------
321
void j_rev_dct_sparse (DCTBLOCK data, int pos) {
327
// cout << "j_rev_dct_sparse"<<endl;
329
/* If DC Coefficient. */
336
/* Compute 32 bit value to assign. This speeds things up a bit */
344
val = (v + (quant / 2)) / quant;
347
v = ((val & 0xffff) | (val << 16));
349
dp[0] = v; dp[1] = v; dp[2] = v; dp[3] = v;
350
dp[4] = v; dp[5] = v; dp[6] = v; dp[7] = v;
351
dp[8] = v; dp[9] = v; dp[10] = v; dp[11] = v;
352
dp[12] = v; dp[13] = v; dp[14] = v; dp[15] = v;
353
dp[16] = v; dp[17] = v; dp[18] = v; dp[19] = v;
354
dp[20] = v; dp[21] = v; dp[22] = v; dp[23] = v;
355
dp[24] = v; dp[25] = v; dp[26] = v; dp[27] = v;
356
dp[28] = v; dp[29] = v; dp[30] = v; dp[31] = v;
360
//printf("sparse is: %d val:%8x\n",pos,data[pos]);
367
/* Some other coefficient. */
375
dataptr = (DCTELEM *)data;
376
coeff = dataptr[pos];
377
ndataptr = PreIDCT[pos];
379
//printf ("COEFFICIENT = %3d, POSITION = %2d\n", coeff, pos);
382
for (rr=0; rr<4; rr++) {
384
dataptr[0] = (ndataptr[0] * coeff);
385
dataptr[1] = (ndataptr[1] * coeff);
386
dataptr[2] = (ndataptr[2] * coeff);
387
dataptr[3] = (ndataptr[3] * coeff);
388
dataptr[4] = (ndataptr[4] * coeff);
389
dataptr[5] = (ndataptr[5] * coeff);
390
dataptr[6] = (ndataptr[6] * coeff);
391
dataptr[7] = (ndataptr[7] * coeff);
392
dataptr[8] = (ndataptr[8] * coeff);
393
dataptr[9] = (ndataptr[9] * coeff);
394
dataptr[10] = (ndataptr[10] * coeff);
395
dataptr[11] = (ndataptr[11] * coeff);
396
dataptr[12] = (ndataptr[12] * coeff);
397
dataptr[13] = (ndataptr[13] * coeff);
398
dataptr[14] = (ndataptr[14] * coeff);
399
dataptr[15] = (ndataptr[15] * coeff);
406
dataptr = (DCTELEM *) data;
417
*--------------------------------------------------------------
419
* j_rev_dct_sparse --
421
* Performs the original inverse DCT on one block of
430
*--------------------------------------------------------------
432
void j_rev_dct_sparse (DCTBLOCK data,int pos) {
435
#endif /* SPARSE_DCT */
444
*--------------------------------------------------------------
448
* The inverse DCT function.
456
*--------------------------------------------------------------
458
void j_rev_dct (DCTBLOCK data) {
461
INT32 tmp0, tmp1, tmp2, tmp3;
462
INT32 tmp10, tmp11, tmp12, tmp13;
463
INT32 z1, z2, z3, z4, z5;
464
INT32 d0, d1, d2, d3, d4, d5, d6, d7;
465
register DCTELEM *dataptr;
470
/* Pass 1: process rows. */
471
/* Note results are scaled up by sqrt(8) compared to a true IDCT; */
472
/* furthermore, we scale the results by 2**PASS1_BITS. */
476
for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
477
/* Due to quantization, we will usually find that many of the input
478
* coefficients are zero, especially the AC terms. We can exploit this
479
* by short-circuiting the IDCT calculation for any row in which all
480
* the AC terms are zero. In that case each output is equal to the
481
* DC coefficient (with scale factor as needed).
482
* With typical images and quantization tables, half or more of the
483
* row DCT calculations can be simplified this way.
486
register int *idataptr = (int*)dataptr;
489
if ((d1 == 0) && (idataptr[1] + idataptr[2] + idataptr[3]) == 0) {
490
/* AC terms all zero */
492
/* Compute a 32 bit value to assign. */
493
DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
494
register int v = (dcval & 0xffff) + (dcval << 16);
502
dataptr += DCTSIZE; /* advance pointer to next row */
512
/* Even part: reverse the even part of the forward DCT. */
513
/* The rotator is sqrt(2)*c(-6). */
518
/* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
519
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
520
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
521
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
523
tmp0 = (d0 + d4) << CONST_BITS;
524
tmp1 = (d0 - d4) << CONST_BITS;
531
/* d0 == 0, d2 != 0, d4 != 0, d6 != 0 */
532
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
533
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
534
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
536
tmp0 = d4 << CONST_BITS;
541
tmp12 = -(tmp0 + tmp2);
545
/* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
546
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
547
tmp3 = MULTIPLY(d6, FIX(0.541196100));
549
tmp0 = (d0 + d4) << CONST_BITS;
550
tmp1 = (d0 - d4) << CONST_BITS;
557
/* d0 == 0, d2 == 0, d4 != 0, d6 != 0 */
558
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
559
tmp3 = MULTIPLY(d6, FIX(0.541196100));
561
tmp0 = d4 << CONST_BITS;
566
tmp12 = -(tmp0 + tmp2);
572
/* d0 != 0, d2 != 0, d4 == 0, d6 != 0 */
573
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
574
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
575
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
577
tmp0 = d0 << CONST_BITS;
584
/* d0 == 0, d2 != 0, d4 == 0, d6 != 0 */
585
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
586
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
587
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
596
/* d0 != 0, d2 == 0, d4 == 0, d6 != 0 */
597
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
598
tmp3 = MULTIPLY(d6, FIX(0.541196100));
600
tmp0 = d0 << CONST_BITS;
607
/* d0 == 0, d2 == 0, d4 == 0, d6 != 0 */
608
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
609
tmp3 = MULTIPLY(d6, FIX(0.541196100));
622
/* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
623
tmp2 = MULTIPLY(d2, FIX(0.541196100));
624
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
626
tmp0 = (d0 + d4) << CONST_BITS;
627
tmp1 = (d0 - d4) << CONST_BITS;
634
/* d0 == 0, d2 != 0, d4 != 0, d6 == 0 */
635
tmp2 = MULTIPLY(d2, FIX(0.541196100));
636
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
638
tmp0 = d4 << CONST_BITS;
643
tmp12 = -(tmp0 + tmp2);
647
/* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
648
tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
649
tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
651
/* d0 == 0, d2 == 0, d4 != 0, d6 == 0 */
652
tmp10 = tmp13 = d4 << CONST_BITS;
653
tmp11 = tmp12 = -tmp10;
659
/* d0 != 0, d2 != 0, d4 == 0, d6 == 0 */
660
tmp2 = MULTIPLY(d2, FIX(0.541196100));
661
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
663
tmp0 = d0 << CONST_BITS;
670
/* d0 == 0, d2 != 0, d4 == 0, d6 == 0 */
671
tmp2 = MULTIPLY(d2, FIX(0.541196100));
672
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
681
/* d0 != 0, d2 == 0, d4 == 0, d6 == 0 */
682
tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
684
/* d0 == 0, d2 == 0, d4 == 0, d6 == 0 */
685
tmp10 = tmp13 = tmp11 = tmp12 = 0;
692
/* Odd part per figure 8; the matrix is unitary and hence its
693
* transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
700
/* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
705
z5 = MULTIPLY(z3 + z4, FIX(1.175875602));
707
tmp0 = MULTIPLY(d7, FIX(0.298631336));
708
tmp1 = MULTIPLY(d5, FIX(2.053119869));
709
tmp2 = MULTIPLY(d3, FIX(3.072711026));
710
tmp3 = MULTIPLY(d1, FIX(1.501321110));
711
z1 = MULTIPLY(z1, - FIX(0.899976223));
712
z2 = MULTIPLY(z2, - FIX(2.562915447));
713
z3 = MULTIPLY(z3, - FIX(1.961570560));
714
z4 = MULTIPLY(z4, - FIX(0.390180644));
724
/* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
727
z5 = MULTIPLY(z3 + d5, FIX(1.175875602));
729
tmp0 = MULTIPLY(d7, FIX(0.298631336));
730
tmp1 = MULTIPLY(d5, FIX(2.053119869));
731
tmp2 = MULTIPLY(d3, FIX(3.072711026));
732
z1 = MULTIPLY(d7, - FIX(0.899976223));
733
z2 = MULTIPLY(z2, - FIX(2.562915447));
734
z3 = MULTIPLY(z3, - FIX(1.961570560));
735
z4 = MULTIPLY(d5, - FIX(0.390180644));
747
/* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
750
z5 = MULTIPLY(d7 + z4, FIX(1.175875602));
752
tmp0 = MULTIPLY(d7, FIX(0.298631336));
753
tmp1 = MULTIPLY(d5, FIX(2.053119869));
754
tmp3 = MULTIPLY(d1, FIX(1.501321110));
755
z1 = MULTIPLY(z1, - FIX(0.899976223));
756
z2 = MULTIPLY(d5, - FIX(2.562915447));
757
z3 = MULTIPLY(d7, - FIX(1.961570560));
758
z4 = MULTIPLY(z4, - FIX(0.390180644));
768
/* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
769
z5 = MULTIPLY(d7 + d5, FIX(1.175875602));
771
tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
772
tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
773
z1 = MULTIPLY(d7, - FIX(0.899976223));
774
z3 = MULTIPLY(d7, - FIX(1.961570560));
775
z2 = MULTIPLY(d5, - FIX(2.562915447));
776
z4 = MULTIPLY(d5, - FIX(0.390180644));
790
/* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
793
z5 = MULTIPLY(z3 + d1, FIX(1.175875602));
795
tmp0 = MULTIPLY(d7, FIX(0.298631336));
796
tmp2 = MULTIPLY(d3, FIX(3.072711026));
797
tmp3 = MULTIPLY(d1, FIX(1.501321110));
798
z1 = MULTIPLY(z1, - FIX(0.899976223));
799
z2 = MULTIPLY(d3, - FIX(2.562915447));
800
z3 = MULTIPLY(z3, - FIX(1.961570560));
801
z4 = MULTIPLY(d1, - FIX(0.390180644));
811
/* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
813
z5 = MULTIPLY(z3, FIX(1.175875602));
815
tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
816
tmp2 = MULTIPLY(d3, FIX(0.509795579));
817
z1 = MULTIPLY(d7, - FIX(0.899976223));
818
z2 = MULTIPLY(d3, - FIX(2.562915447));
819
z3 = MULTIPLY(z3, - FIX2(0.785694958));
828
/* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
830
z5 = MULTIPLY(z1, FIX(1.175875602));
832
tmp0 = MULTIPLY(d7, - FIX2(1.662939224));
833
tmp3 = MULTIPLY(d1, FIX2(1.111140466));
834
z1 = MULTIPLY(z1, FIX2(0.275899379));
835
z3 = MULTIPLY(d7, - FIX(1.961570560));
836
z4 = MULTIPLY(d1, - FIX(0.390180644));
843
/* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
844
tmp0 = MULTIPLY(d7, - FIX2(1.387039845));
845
tmp1 = MULTIPLY(d7, FIX(1.175875602));
846
tmp2 = MULTIPLY(d7, - FIX2(0.785694958));
847
tmp3 = MULTIPLY(d7, FIX2(0.275899379));
855
/* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
858
z5 = MULTIPLY(d3 + z4, FIX(1.175875602));
860
tmp1 = MULTIPLY(d5, FIX(2.053119869));
861
tmp2 = MULTIPLY(d3, FIX(3.072711026));
862
tmp3 = MULTIPLY(d1, FIX(1.501321110));
863
z1 = MULTIPLY(d1, - FIX(0.899976223));
864
z2 = MULTIPLY(z2, - FIX(2.562915447));
865
z3 = MULTIPLY(d3, - FIX(1.961570560));
866
z4 = MULTIPLY(z4, - FIX(0.390180644));
876
/* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
878
z5 = MULTIPLY(z2, FIX(1.175875602));
880
tmp1 = MULTIPLY(d5, FIX2(1.662939225));
881
tmp2 = MULTIPLY(d3, FIX2(1.111140466));
882
z2 = MULTIPLY(z2, - FIX2(1.387039845));
883
z3 = MULTIPLY(d3, - FIX(1.961570560));
884
z4 = MULTIPLY(d5, - FIX(0.390180644));
893
/* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
895
z5 = MULTIPLY(z4, FIX(1.175875602));
897
tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
898
tmp3 = MULTIPLY(d1, FIX2(0.601344887));
899
z1 = MULTIPLY(d1, - FIX(0.899976223));
900
z2 = MULTIPLY(d5, - FIX(2.562915447));
901
z4 = MULTIPLY(z4, FIX2(0.785694958));
908
/* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
909
tmp0 = MULTIPLY(d5, FIX(1.175875602));
910
tmp1 = MULTIPLY(d5, FIX2(0.275899380));
911
tmp2 = MULTIPLY(d5, - FIX2(1.387039845));
912
tmp3 = MULTIPLY(d5, FIX2(0.785694958));
918
/* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
921
tmp2 = MULTIPLY(d3, - FIX(1.451774981));
922
tmp3 = MULTIPLY(d1, (FIX(0.211164243) - 1));
923
z1 = MULTIPLY(d1, FIX(1.061594337));
924
z2 = MULTIPLY(d3, - FIX(2.172734803));
925
z4 = MULTIPLY(z5, FIX(0.785694958));
926
z5 = MULTIPLY(z5, FIX(1.175875602));
933
/* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
934
tmp0 = MULTIPLY(d3, - FIX2(0.785694958));
935
tmp1 = MULTIPLY(d3, - FIX2(1.387039845));
936
tmp2 = MULTIPLY(d3, - FIX2(0.275899379));
937
tmp3 = MULTIPLY(d3, FIX(1.175875602));
941
/* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
942
tmp0 = MULTIPLY(d1, FIX2(0.275899379));
943
tmp1 = MULTIPLY(d1, FIX2(0.785694958));
944
tmp2 = MULTIPLY(d1, FIX(1.175875602));
945
tmp3 = MULTIPLY(d1, FIX2(1.387039845));
947
/* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
948
tmp0 = tmp1 = tmp2 = tmp3 = 0;
954
/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
956
dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
957
dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
958
dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
959
dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
960
dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
961
dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
962
dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
963
dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
965
dataptr += DCTSIZE; /* advance pointer to next row */
968
/* Pass 2: process columns. */
969
/* Note that we must descale the results by a factor of 8 == 2**3, */
970
/* and also undo the PASS1_BITS scaling. */
973
for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
974
/* Columns of zeroes can be exploited in the same way as we did with rows.
975
* However, the row calculation has created many nonzero AC terms, so the
976
* simplification applies less often (typically 5% to 10% of the time).
977
* On machines with very fast multiplication, it's possible that the
978
* test takes more time than it's worth. In that case this section
979
* may be commented out.
982
d0 = dataptr[DCTSIZE*0];
983
d1 = dataptr[DCTSIZE*1];
984
d2 = dataptr[DCTSIZE*2];
985
d3 = dataptr[DCTSIZE*3];
986
d4 = dataptr[DCTSIZE*4];
987
d5 = dataptr[DCTSIZE*5];
988
d6 = dataptr[DCTSIZE*6];
989
d7 = dataptr[DCTSIZE*7];
991
/* Even part: reverse the even part of the forward DCT. */
992
/* The rotator is sqrt(2)*c(-6). */
997
/* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
998
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
999
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
1000
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
1002
tmp0 = (d0 + d4) << CONST_BITS;
1003
tmp1 = (d0 - d4) << CONST_BITS;
1005
tmp10 = tmp0 + tmp3;
1006
tmp13 = tmp0 - tmp3;
1007
tmp11 = tmp1 + tmp2;
1008
tmp12 = tmp1 - tmp2;
1010
/* d0 == 0, d2 != 0, d4 != 0, d6 != 0 */
1011
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
1012
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
1013
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
1015
tmp0 = d4 << CONST_BITS;
1017
tmp10 = tmp0 + tmp3;
1018
tmp13 = tmp0 - tmp3;
1019
tmp11 = tmp2 - tmp0;
1020
tmp12 = -(tmp0 + tmp2);
1024
/* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
1025
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
1026
tmp3 = MULTIPLY(d6, FIX(0.541196100));
1028
tmp0 = (d0 + d4) << CONST_BITS;
1029
tmp1 = (d0 - d4) << CONST_BITS;
1031
tmp10 = tmp0 + tmp3;
1032
tmp13 = tmp0 - tmp3;
1033
tmp11 = tmp1 + tmp2;
1034
tmp12 = tmp1 - tmp2;
1036
/* d0 == 0, d2 == 0, d4 != 0, d6 != 0 */
1037
tmp2 = MULTIPLY(d6, -FIX2(1.306562965));
1038
tmp3 = MULTIPLY(d6, FIX(0.541196100));
1040
tmp0 = d4 << CONST_BITS;
1042
tmp10 = tmp0 + tmp3;
1043
tmp13 = tmp0 - tmp3;
1044
tmp11 = tmp2 - tmp0;
1045
tmp12 = -(tmp0 + tmp2);
1051
/* d0 != 0, d2 != 0, d4 == 0, d6 != 0 */
1052
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
1053
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
1054
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
1056
tmp0 = d0 << CONST_BITS;
1058
tmp10 = tmp0 + tmp3;
1059
tmp13 = tmp0 - tmp3;
1060
tmp11 = tmp0 + tmp2;
1061
tmp12 = tmp0 - tmp2;
1063
/* d0 == 0, d2 != 0, d4 == 0, d6 != 0 */
1064
z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
1065
tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
1066
tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
1075
/* d0 != 0, d2 == 0, d4 == 0, d6 != 0 */
1076
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
1077
tmp3 = MULTIPLY(d6, FIX(0.541196100));
1079
tmp0 = d0 << CONST_BITS;
1081
tmp10 = tmp0 + tmp3;
1082
tmp13 = tmp0 - tmp3;
1083
tmp11 = tmp0 + tmp2;
1084
tmp12 = tmp0 - tmp2;
1086
/* d0 == 0, d2 == 0, d4 == 0, d6 != 0 */
1087
tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
1088
tmp3 = MULTIPLY(d6, FIX(0.541196100));
1101
/* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
1102
tmp2 = MULTIPLY(d2, FIX(0.541196100));
1103
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
1105
tmp0 = (d0 + d4) << CONST_BITS;
1106
tmp1 = (d0 - d4) << CONST_BITS;
1108
tmp10 = tmp0 + tmp3;
1109
tmp13 = tmp0 - tmp3;
1110
tmp11 = tmp1 + tmp2;
1111
tmp12 = tmp1 - tmp2;
1113
/* d0 == 0, d2 != 0, d4 != 0, d6 == 0 */
1114
tmp2 = MULTIPLY(d2, FIX(0.541196100));
1115
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
1117
tmp0 = d4 << CONST_BITS;
1119
tmp10 = tmp0 + tmp3;
1120
tmp13 = tmp0 - tmp3;
1121
tmp11 = tmp2 - tmp0;
1122
tmp12 = -(tmp0 + tmp2);
1126
/* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
1127
tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
1128
tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
1130
/* d0 == 0, d2 == 0, d4 != 0, d6 == 0 */
1131
tmp10 = tmp13 = d4 << CONST_BITS;
1132
tmp11 = tmp12 = -tmp10;
1138
/* d0 != 0, d2 != 0, d4 == 0, d6 == 0 */
1139
tmp2 = MULTIPLY(d2, FIX(0.541196100));
1140
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
1142
tmp0 = d0 << CONST_BITS;
1144
tmp10 = tmp0 + tmp3;
1145
tmp13 = tmp0 - tmp3;
1146
tmp11 = tmp0 + tmp2;
1147
tmp12 = tmp0 - tmp2;
1149
/* d0 == 0, d2 != 0, d4 == 0, d6 == 0 */
1150
tmp2 = MULTIPLY(d2, FIX(0.541196100));
1151
tmp3 = (INT32) (MULTIPLY(d2, (FIX(1.306562965) + .5)));
1160
/* d0 != 0, d2 == 0, d4 == 0, d6 == 0 */
1161
tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
1163
/* d0 == 0, d2 == 0, d4 == 0, d6 == 0 */
1164
tmp10 = tmp13 = tmp11 = tmp12 = 0;
1170
/* Odd part per figure 8; the matrix is unitary and hence its
1171
* transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
1177
/* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
1182
z5 = MULTIPLY(z3 + z4, FIX(1.175875602));
1184
tmp0 = MULTIPLY(d7, FIX(0.298631336));
1185
tmp1 = MULTIPLY(d5, FIX(2.053119869));
1186
tmp2 = MULTIPLY(d3, FIX(3.072711026));
1187
tmp3 = MULTIPLY(d1, FIX(1.501321110));
1188
z1 = MULTIPLY(z1, - FIX(0.899976223));
1189
z2 = MULTIPLY(z2, - FIX(2.562915447));
1190
z3 = MULTIPLY(z3, - FIX(1.961570560));
1191
z4 = MULTIPLY(z4, - FIX(0.390180644));
1201
/* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
1204
z5 = MULTIPLY(z3 + d5, FIX(1.175875602));
1206
tmp0 = MULTIPLY(d7, FIX(0.298631336));
1207
tmp1 = MULTIPLY(d5, FIX(2.053119869));
1208
tmp2 = MULTIPLY(d3, FIX(3.072711026));
1209
z1 = MULTIPLY(d7, - FIX(0.899976223));
1210
z2 = MULTIPLY(z2, - FIX(2.562915447));
1211
z3 = MULTIPLY(z3, - FIX(1.961570560));
1212
z4 = MULTIPLY(d5, - FIX(0.390180644));
1224
/* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
1227
z5 = MULTIPLY(d7 + z4, FIX(1.175875602));
1229
tmp0 = MULTIPLY(d7, FIX(0.298631336));
1230
tmp1 = MULTIPLY(d5, FIX(2.053119869));
1231
tmp3 = MULTIPLY(d1, FIX(1.501321110));
1232
z1 = MULTIPLY(z1, - FIX(0.899976223));
1233
z2 = MULTIPLY(d5, - FIX(2.562915447));
1234
z3 = MULTIPLY(d7, - FIX(1.961570560));
1235
z4 = MULTIPLY(z4, - FIX(0.390180644));
1245
/* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
1246
z5 = MULTIPLY(d5 + d7, FIX(1.175875602));
1248
tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
1249
tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
1250
z1 = MULTIPLY(d7, - FIX(0.899976223));
1251
z3 = MULTIPLY(d7, - FIX(1.961570560));
1252
z2 = MULTIPLY(d5, - FIX(2.562915447));
1253
z4 = MULTIPLY(d5, - FIX(0.390180644));
1267
/* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
1270
z5 = MULTIPLY(z3 + d1, FIX(1.175875602));
1272
tmp0 = MULTIPLY(d7, FIX(0.298631336));
1273
tmp2 = MULTIPLY(d3, FIX(3.072711026));
1274
tmp3 = MULTIPLY(d1, FIX(1.501321110));
1275
z1 = MULTIPLY(z1, - FIX(0.899976223));
1276
z2 = MULTIPLY(d3, - FIX(2.562915447));
1277
z3 = MULTIPLY(z3, - FIX(1.961570560));
1278
z4 = MULTIPLY(d1, - FIX(0.390180644));
1288
/* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
1290
z5 = MULTIPLY(z3, FIX(1.175875602));
1292
tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
1293
z1 = MULTIPLY(d7, - FIX(0.899976223));
1294
tmp2 = MULTIPLY(d3, FIX(0.509795579));
1295
z2 = MULTIPLY(d3, - FIX(2.562915447));
1296
z3 = MULTIPLY(z3, - FIX2(0.785694958));
1305
/* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
1307
z5 = MULTIPLY(z1, FIX(1.175875602));
1309
tmp0 = MULTIPLY(d7, - FIX2(1.662939224));
1310
tmp3 = MULTIPLY(d1, FIX2(1.111140466));
1311
z1 = MULTIPLY(z1, FIX2(0.275899379));
1312
z3 = MULTIPLY(d7, - FIX(1.961570560));
1313
z4 = MULTIPLY(d1, - FIX(0.390180644));
1320
/* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
1321
tmp0 = MULTIPLY(d7, - FIX2(1.387039845));
1322
tmp1 = MULTIPLY(d7, FIX(1.175875602));
1323
tmp2 = MULTIPLY(d7, - FIX2(0.785694958));
1324
tmp3 = MULTIPLY(d7, FIX2(0.275899379));
1332
/* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
1335
z5 = MULTIPLY(d3 + z4, FIX(1.175875602));
1337
tmp1 = MULTIPLY(d5, FIX(2.053119869));
1338
tmp2 = MULTIPLY(d3, FIX(3.072711026));
1339
tmp3 = MULTIPLY(d1, FIX(1.501321110));
1340
z1 = MULTIPLY(d1, - FIX(0.899976223));
1341
z2 = MULTIPLY(z2, - FIX(2.562915447));
1342
z3 = MULTIPLY(d3, - FIX(1.961570560));
1343
z4 = MULTIPLY(z4, - FIX(0.390180644));
1353
/* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
1355
z5 = MULTIPLY(z2, FIX(1.175875602));
1357
tmp1 = MULTIPLY(d5, FIX2(1.662939225));
1358
tmp2 = MULTIPLY(d3, FIX2(1.111140466));
1359
z2 = MULTIPLY(z2, - FIX2(1.387039845));
1360
z3 = MULTIPLY(d3, - FIX(1.961570560));
1361
z4 = MULTIPLY(d5, - FIX(0.390180644));
1370
/* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
1372
z5 = MULTIPLY(z4, FIX(1.175875602));
1374
tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
1375
tmp3 = MULTIPLY(d1, FIX2(0.601344887));
1376
z1 = MULTIPLY(d1, - FIX(0.899976223));
1377
z2 = MULTIPLY(d5, - FIX(2.562915447));
1378
z4 = MULTIPLY(z4, FIX2(0.785694958));
1385
/* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
1386
tmp0 = MULTIPLY(d5, FIX(1.175875602));
1387
tmp1 = MULTIPLY(d5, FIX2(0.275899380));
1388
tmp2 = MULTIPLY(d5, - FIX2(1.387039845));
1389
tmp3 = MULTIPLY(d5, FIX2(0.785694958));
1395
/* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
1398
tmp2 = MULTIPLY(d3, - FIX(1.451774981));
1399
tmp3 = MULTIPLY(d1, (FIX(0.211164243) - 1));
1400
z1 = MULTIPLY(d1, FIX(1.061594337));
1401
z2 = MULTIPLY(d3, - FIX(2.172734803));
1402
z4 = MULTIPLY(z5, FIX(0.785694958));
1403
z5 = MULTIPLY(z5, FIX(1.175875602));
1410
/* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
1411
tmp0 = MULTIPLY(d3, - FIX2(0.785694958));
1412
tmp1 = MULTIPLY(d3, - FIX2(1.387039845));
1413
tmp2 = MULTIPLY(d3, - FIX2(0.275899379));
1414
tmp3 = MULTIPLY(d3, FIX(1.175875602));
1418
/* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
1419
tmp0 = MULTIPLY(d1, FIX2(0.275899379));
1420
tmp1 = MULTIPLY(d1, FIX2(0.785694958));
1421
tmp2 = MULTIPLY(d1, FIX(1.175875602));
1422
tmp3 = MULTIPLY(d1, FIX2(1.387039845));
1424
/* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
1425
tmp0 = tmp1 = tmp2 = tmp3 = 0;
1431
/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
1433
dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
1434
CONST_BITS+PASS1_BITS+3);
1435
dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
1436
CONST_BITS+PASS1_BITS+3);
1437
dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
1438
CONST_BITS+PASS1_BITS+3);
1439
dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
1440
CONST_BITS+PASS1_BITS+3);
1441
dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
1442
CONST_BITS+PASS1_BITS+3);
1443
dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
1444
CONST_BITS+PASS1_BITS+3);
1445
dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
1446
CONST_BITS+PASS1_BITS+3);
1447
dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
1448
CONST_BITS+PASS1_BITS+3);
1450
dataptr++; /* advance pointer to next column */
1459
*--------------------------------------------------------------
1463
* The original inverse DCT function.
1471
*--------------------------------------------------------------
1473
void j_rev_dct (DCTBLOCK data)
1475
INT32 tmp0, tmp1, tmp2, tmp3;
1476
INT32 tmp10, tmp11, tmp12, tmp13;
1477
INT32 z1, z2, z3, z4, z5;
1478
register DCTELEM *dataptr;
1482
/* Pass 1: process rows. */
1483
/* Note results are scaled up by sqrt(8) compared to a true IDCT; */
1484
/* furthermore, we scale the results by 2**PASS1_BITS. */
1487
for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
1488
/* Due to quantization, we will usually find that many of the input
1489
* coefficients are zero, especially the AC terms. We can exploit this
1490
* by short-circuiting the IDCT calculation for any row in which all
1491
* the AC terms are zero. In that case each output is equal to the
1492
* DC coefficient (with scale factor as needed).
1493
* With typical images and quantization tables, half or more of the
1494
* row DCT calculations can be simplified this way.
1497
if ((dataptr[1] | dataptr[2] | dataptr[3] | dataptr[4] |
1498
dataptr[5] | dataptr[6] | dataptr[7]) == 0) {
1499
/* AC terms all zero */
1500
DCTELEM dcval = (DCTELEM) (dataptr[0] << PASS1_BITS);
1511
dataptr += DCTSIZE; /* advance pointer to next row */
1515
/* Even part: reverse the even part of the forward DCT. */
1516
/* The rotator is sqrt(2)*c(-6). */
1518
z2 = (INT32) dataptr[2];
1519
z3 = (INT32) dataptr[6];
1521
z1 = MULTIPLY(z2 + z3, FIX(0.541196100));
1522
tmp2 = z1 + MULTIPLY(z3, - FIX(1.847759065));
1523
tmp3 = z1 + MULTIPLY(z2, FIX(0.765366865));
1525
tmp0 = ((INT32) dataptr[0] + (INT32) dataptr[4]) << CONST_BITS;
1526
tmp1 = ((INT32) dataptr[0] - (INT32) dataptr[4]) << CONST_BITS;
1528
tmp10 = tmp0 + tmp3;
1529
tmp13 = tmp0 - tmp3;
1530
tmp11 = tmp1 + tmp2;
1531
tmp12 = tmp1 - tmp2;
1533
/* Odd part per figure 8; the matrix is unitary and hence its
1534
* transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
1537
tmp0 = (INT32) dataptr[7];
1538
tmp1 = (INT32) dataptr[5];
1539
tmp2 = (INT32) dataptr[3];
1540
tmp3 = (INT32) dataptr[1];
1546
z5 = MULTIPLY(z3 + z4, FIX(1.175875602)); /* sqrt(2) * c3 */
1548
tmp0 = MULTIPLY(tmp0, FIX(0.298631336)); /* sqrt(2) * (-c1+c3+c5-c7) */
1549
tmp1 = MULTIPLY(tmp1, FIX(2.053119869)); /* sqrt(2) * ( c1+c3-c5+c7) */
1550
tmp2 = MULTIPLY(tmp2, FIX(3.072711026)); /* sqrt(2) * ( c1+c3+c5-c7) */
1551
tmp3 = MULTIPLY(tmp3, FIX(1.501321110)); /* sqrt(2) * ( c1+c3-c5-c7) */
1552
z1 = MULTIPLY(z1, - FIX(0.899976223)); /* sqrt(2) * (c7-c3) */
1553
z2 = MULTIPLY(z2, - FIX(2.562915447)); /* sqrt(2) * (-c1-c3) */
1554
z3 = MULTIPLY(z3, - FIX(1.961570560)); /* sqrt(2) * (-c3-c5) */
1555
z4 = MULTIPLY(z4, - FIX(0.390180644)); /* sqrt(2) * (c5-c3) */
1565
/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
1567
dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
1568
dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
1569
dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
1570
dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
1571
dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
1572
dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
1573
dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
1574
dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
1576
dataptr += DCTSIZE; /* advance pointer to next row */
1579
/* Pass 2: process columns. */
1580
/* Note that we must descale the results by a factor of 8 == 2**3, */
1581
/* and also undo the PASS1_BITS scaling. */
1584
for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
1585
/* Columns of zeroes can be exploited in the same way as we did with rows.
1586
* However, the row calculation has created many nonzero AC terms, so the
1587
* simplification applies less often (typically 5% to 10% of the time).
1588
* On machines with very fast multiplication, it's possible that the
1589
* test takes more time than it's worth. In that case this section
1590
* may be commented out.
1593
#ifndef NO_ZERO_COLUMN_TEST
1594
if ((dataptr[DCTSIZE*1] | dataptr[DCTSIZE*2] | dataptr[DCTSIZE*3] |
1595
dataptr[DCTSIZE*4] | dataptr[DCTSIZE*5] | dataptr[DCTSIZE*6] |
1596
dataptr[DCTSIZE*7]) == 0) {
1597
/* AC terms all zero */
1598
DCTELEM dcval = (DCTELEM) DESCALE((INT32) dataptr[0], PASS1_BITS+3);
1600
dataptr[DCTSIZE*0] = dcval;
1601
dataptr[DCTSIZE*1] = dcval;
1602
dataptr[DCTSIZE*2] = dcval;
1603
dataptr[DCTSIZE*3] = dcval;
1604
dataptr[DCTSIZE*4] = dcval;
1605
dataptr[DCTSIZE*5] = dcval;
1606
dataptr[DCTSIZE*6] = dcval;
1607
dataptr[DCTSIZE*7] = dcval;
1609
dataptr++; /* advance pointer to next column */
1614
/* Even part: reverse the even part of the forward DCT. */
1615
/* The rotator is sqrt(2)*c(-6). */
1617
z2 = (INT32) dataptr[DCTSIZE*2];
1618
z3 = (INT32) dataptr[DCTSIZE*6];
1620
z1 = MULTIPLY(z2 + z3, FIX(0.541196100));
1621
tmp2 = z1 + MULTIPLY(z3, - FIX(1.847759065));
1622
tmp3 = z1 + MULTIPLY(z2, FIX(0.765366865));
1624
tmp0 = ((INT32) dataptr[DCTSIZE*0] + (INT32) dataptr[DCTSIZE*4]) << CONST_BITS;
1625
tmp1 = ((INT32) dataptr[DCTSIZE*0] - (INT32) dataptr[DCTSIZE*4]) << CONST_BITS;
1627
tmp10 = tmp0 + tmp3;
1628
tmp13 = tmp0 - tmp3;
1629
tmp11 = tmp1 + tmp2;
1630
tmp12 = tmp1 - tmp2;
1632
/* Odd part per figure 8; the matrix is unitary and hence its
1633
* transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
1636
tmp0 = (INT32) dataptr[DCTSIZE*7];
1637
tmp1 = (INT32) dataptr[DCTSIZE*5];
1638
tmp2 = (INT32) dataptr[DCTSIZE*3];
1639
tmp3 = (INT32) dataptr[DCTSIZE*1];
1645
z5 = MULTIPLY(z3 + z4, FIX(1.175875602)); /* sqrt(2) * c3 */
1647
tmp0 = MULTIPLY(tmp0, FIX(0.298631336)); /* sqrt(2) * (-c1+c3+c5-c7) */
1648
tmp1 = MULTIPLY(tmp1, FIX(2.053119869)); /* sqrt(2) * ( c1+c3-c5+c7) */
1649
tmp2 = MULTIPLY(tmp2, FIX(3.072711026)); /* sqrt(2) * ( c1+c3+c5-c7) */
1650
tmp3 = MULTIPLY(tmp3, FIX(1.501321110)); /* sqrt(2) * ( c1+c3-c5-c7) */
1651
z1 = MULTIPLY(z1, - FIX(0.899976223)); /* sqrt(2) * (c7-c3) */
1652
z2 = MULTIPLY(z2, - FIX(2.562915447)); /* sqrt(2) * (-c1-c3) */
1653
z3 = MULTIPLY(z3, - FIX(1.961570560)); /* sqrt(2) * (-c3-c5) */
1654
z4 = MULTIPLY(z4, - FIX(0.390180644)); /* sqrt(2) * (c5-c3) */
1664
/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
1666
dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
1667
CONST_BITS+PASS1_BITS+3);
1668
dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
1669
CONST_BITS+PASS1_BITS+3);
1670
dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
1671
CONST_BITS+PASS1_BITS+3);
1672
dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
1673
CONST_BITS+PASS1_BITS+3);
1674
dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
1675
CONST_BITS+PASS1_BITS+3);
1676
dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
1677
CONST_BITS+PASS1_BITS+3);
1678
dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
1679
CONST_BITS+PASS1_BITS+3);
1680
dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
1681
CONST_BITS+PASS1_BITS+3);
1683
dataptr++; /* advance pointer to next column */
1688
#endif /* ORIG_DCT */
1689
#endif /* FIVE_DCT */