~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/mpegplay/jrevdct.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * jrevdct.c
 
3
 *
 
4
 * This file is part of the Independent JPEG Group's software.
 
5
 * The IJG code is distributed under the terms reproduced here:
 
6
 * 
 
7
 * LEGAL ISSUES
 
8
 * ============
 
9
 *
 
10
 * In plain English:
 
11
 * 
 
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
 
15
 *    pay us.
 
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.
 
19
 * 
 
20
 * In legalese:
 
21
 * 
 
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.
 
26
 * 
 
27
 * This software is copyright (C) 1991, 1992, Thomas G. Lane.
 
28
 * All Rights Reserved except as specified below.
 
29
 * 
 
30
 * Permission is hereby granted to use, copy, modify, and distribute this
 
31
 * software (or portions thereof) for any purpose, without fee, subject to
 
32
 * these conditions:
 
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.
 
43
 * 
 
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
 
46
 * to acknowledge us.
 
47
 * 
 
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".
 
52
 * 
 
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.
 
56
 *
 
57
 * 
 
58
 * ARCHIVE LOCATIONS
 
59
 * =================
 
60
 * 
 
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
 
68
 * that way.
 
69
 * 
 
70
 * Numerous Internet sites maintain copies of the UUNET files.  However,
 
71
 * only ftp.uu.net is guaranteed to have the latest official version.
 
72
 * 
 
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.
 
78
 * 
 
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
 
89
 * 
 
90
 * ==============
 
91
 * 
 
92
 *
 
93
 * This file contains the basic inverse-DCT transformation subroutine.
 
94
 *
 
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.
 
104
 * 
 
105
 *
 
106
 * CHANGES FOR BERKELEY MPEG
 
107
 * =========================
 
108
 *
 
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).
 
113
 *
 
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
 
117
 * faster.
 
118
 *
 
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.
 
121
 */
 
122
 
 
123
#include "jrevdct.h"
 
124
 
 
125
 
 
126
 
 
127
  
 
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.
 
136
 */
 
137
  
 
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)))
 
144
#else
 
145
#define SHIFT_TEMPS
 
146
#define RIGHT_SHIFT(x,shft)     ((x) >> (shft))
 
147
#endif
 
148
 
 
149
/*
 
150
 * This routine is specialized to the case DCTSIZE = 8.
 
151
 */
 
152
 
 
153
#if DCTSIZE != 8
 
154
  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
 
155
#endif
 
156
 
 
157
 
 
158
/*
 
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.
 
162
 *
 
163
 * The poop on this scaling stuff is as follows:
 
164
 *
 
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).
 
171
 *
 
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.
 
182
 *
 
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.)
 
188
 *
 
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.
 
192
 */
 
193
 
 
194
#ifdef EIGHT_BIT_SAMPLES
 
195
#define PASS1_BITS  2
 
196
#else
 
197
#define PASS1_BITS  1           /* lose a little precision to avoid overflow */
 
198
#endif
 
199
 
 
200
#define ONE     ((INT32) 1)
 
201
 
 
202
#define CONST_SCALE (ONE << CONST_BITS)
 
203
 
 
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.
 
208
 */
 
209
 
 
210
#define FIX(x)  ((INT32) ((x) * CONST_SCALE + 0.5))
 
211
 
 
212
/* When adding two opposite-signed fixes, the 0.5 cancels */
 
213
#define FIX2(x) ((INT32) ((x) * CONST_SCALE))
 
214
 
 
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.
 
218
 */
 
219
 
 
220
#define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
 
221
 
 
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.
 
231
 */
 
232
 
 
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)))
 
236
#endif
 
237
#ifdef SHORTxLCONST_32          /* known to work with Microsoft C 6.0 */
 
238
#define MULTIPLY(var,const)  (((INT16) (var)) * ((INT32) (const)))
 
239
#endif
 
240
#endif
 
241
 
 
242
#ifndef MULTIPLY                /* default definition */
 
243
#define MULTIPLY(var,const)  ((var) * (const))
 
244
#endif
 
245
 
 
246
#ifndef NO_SPARSE_DCT
 
247
#define SPARSE_SCALE_FACTOR  8 
 
248
#endif
 
249
 
 
250
/* Precomputed idct value arrays. */
 
251
 
 
252
static DCTELEM PreIDCT[64][64];
 
253
 
 
254
 
 
255
/*
 
256
 *--------------------------------------------------------------
 
257
 *
 
258
 * init_pre_idct --
 
259
 *
 
260
 *  Pre-computes singleton coefficient IDCT values.
 
261
 *
 
262
 * Results:
 
263
 *      None.
 
264
 *
 
265
 * Side effects:
 
266
 *      None.
 
267
 *
 
268
 *--------------------------------------------------------------
 
269
 */
 
270
void init_pre_idct() {
 
271
  int i;
 
272
 
 
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]);
 
277
  }
 
278
 
 
279
  int pos;
 
280
  int rr;
 
281
  DCTELEM *ndataptr;
 
282
 
 
283
  for(pos=0;pos<64;pos++) {
 
284
    ndataptr = PreIDCT[pos];
 
285
    
 
286
    for(rr=0; rr<4; rr++) {
 
287
      for(i=0;i<16;i++) {
 
288
        ndataptr[i] = ndataptr[i]/256;
 
289
      }
 
290
      ndataptr += 16;
 
291
 
 
292
    }
 
293
  }
 
294
 
 
295
 
 
296
    
 
297
 
 
298
 
 
299
 
 
300
}
 
301
 
 
302
#ifndef NO_SPARSE_DCT
 
303
  
 
304
 
 
305
/*
 
306
 *--------------------------------------------------------------
 
307
 *
 
308
 * j_rev_dct_sparse --
 
309
 *
 
310
 *  Performs the inverse DCT on one block of coefficients.
 
311
 *
 
312
 * Results:
 
313
 *      None.
 
314
 *
 
315
 * Side effects:
 
316
 *      None.
 
317
 *
 
318
 *--------------------------------------------------------------
 
319
 */
 
320
 
 
321
void j_rev_dct_sparse (DCTBLOCK data, int pos) {
 
322
  short int val;
 
323
  register int *dp;
 
324
  register int v;
 
325
  int quant;
 
326
 
 
327
  //  cout << "j_rev_dct_sparse"<<endl;
 
328
 
 
329
  /* If DC Coefficient. */
 
330
  
 
331
  if (pos == 0) {
 
332
    dp = (int *)data;
 
333
    v = *data;
 
334
    quant = 8;
 
335
 
 
336
    /* Compute 32 bit value to assign.  This speeds things up a bit */
 
337
    if (v < 0) {
 
338
        val = -v;
 
339
        val += (quant / 2);
 
340
        val /= quant;
 
341
        val = -val;
 
342
    }
 
343
    else {
 
344
        val = (v + (quant / 2)) / quant;
 
345
    }
 
346
 
 
347
    v = ((val & 0xffff) | (val << 16));
 
348
 
 
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;
 
357
 
 
358
    return;
 
359
  }
 
360
  //printf("sparse is: %d  val:%8x\n",pos,data[pos]); 
 
361
 
 
362
  /*
 
363
  j_rev_dct(data);
 
364
  return;
 
365
  */
 
366
 
 
367
  /* Some other coefficient. */
 
368
 
 
369
  DCTELEM *dataptr;
 
370
  DCTELEM *ndataptr;
 
371
  int coeff, rr;
 
372
 
 
373
 
 
374
 
 
375
  dataptr = (DCTELEM *)data;
 
376
  coeff = dataptr[pos];
 
377
  ndataptr = PreIDCT[pos];
 
378
 
 
379
  //printf ("COEFFICIENT = %3d, POSITION = %2d\n", coeff, pos);
 
380
  coeff=coeff/256;
 
381
 
 
382
  for (rr=0; rr<4; rr++) {
 
383
 
 
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); 
 
400
 
 
401
    
 
402
    dataptr += 16;
 
403
    ndataptr += 16;
 
404
  }
 
405
 
 
406
  dataptr = (DCTELEM *) data;
 
407
 
 
408
 
 
409
 
 
410
  return;
 
411
 
 
412
}
 
413
 
 
414
#else
 
415
 
 
416
/*
 
417
 *--------------------------------------------------------------
 
418
 *
 
419
 * j_rev_dct_sparse --
 
420
 *
 
421
 *  Performs the original inverse DCT on one block of 
 
422
 *  coefficients.
 
423
 *
 
424
 * Results:
 
425
 *      None.
 
426
 *
 
427
 * Side effects:
 
428
 *      None.
 
429
 *
 
430
 *--------------------------------------------------------------
 
431
 */
 
432
void j_rev_dct_sparse (DCTBLOCK data,int  pos) {
 
433
  j_rev_dct(data);
 
434
}
 
435
#endif /* SPARSE_DCT */
 
436
 
 
437
 
 
438
#ifndef FIVE_DCT
 
439
 
 
440
#ifndef ORIG_DCT
 
441
 
 
442
 
 
443
/*
 
444
 *--------------------------------------------------------------
 
445
 *
 
446
 * j_rev_dct --
 
447
 *
 
448
 *  The inverse DCT function.
 
449
 *
 
450
 * Results:
 
451
 *      None.
 
452
 *
 
453
 * Side effects:
 
454
 *      None.
 
455
 *
 
456
 *--------------------------------------------------------------
 
457
 */
 
458
void j_rev_dct (DCTBLOCK data) {
 
459
 
 
460
 
 
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;
 
466
  int rowctr;
 
467
  SHIFT_TEMPS
 
468
 
 
469
 
 
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. */
 
473
 
 
474
  dataptr = data;
 
475
 
 
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.
 
484
     */
 
485
 
 
486
    register int *idataptr = (int*)dataptr;
 
487
    d0 = dataptr[0];
 
488
    d1 = dataptr[1];
 
489
    if ((d1 == 0) && (idataptr[1] + idataptr[2] + idataptr[3]) == 0) {
 
490
      /* AC terms all zero */
 
491
      if (d0) {
 
492
          /* Compute a 32 bit value to assign. */
 
493
          DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
 
494
          register int v = (dcval & 0xffff) + (dcval << 16);
 
495
          
 
496
          idataptr[0] = v;
 
497
          idataptr[1] = v;
 
498
          idataptr[2] = v;
 
499
          idataptr[3] = v;
 
500
      }
 
501
      
 
502
      dataptr += DCTSIZE;       /* advance pointer to next row */
 
503
      continue;
 
504
    }
 
505
    d2 = dataptr[2];
 
506
    d3 = dataptr[3];
 
507
    d4 = dataptr[4];
 
508
    d5 = dataptr[5];
 
509
    d6 = dataptr[6];
 
510
    d7 = dataptr[7];
 
511
 
 
512
    /* Even part: reverse the even part of the forward DCT. */
 
513
    /* The rotator is sqrt(2)*c(-6). */
 
514
    if (d6) {
 
515
        if (d4) {
 
516
            if (d2) {
 
517
                if (d0) {
 
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));
 
522
 
 
523
                    tmp0 = (d0 + d4) << CONST_BITS;
 
524
                    tmp1 = (d0 - d4) << CONST_BITS;
 
525
 
 
526
                    tmp10 = tmp0 + tmp3;
 
527
                    tmp13 = tmp0 - tmp3;
 
528
                    tmp11 = tmp1 + tmp2;
 
529
                    tmp12 = tmp1 - tmp2;
 
530
                } else {
 
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));
 
535
 
 
536
                    tmp0 = d4 << CONST_BITS;
 
537
 
 
538
                    tmp10 = tmp0 + tmp3;
 
539
                    tmp13 = tmp0 - tmp3;
 
540
                    tmp11 = tmp2 - tmp0;
 
541
                    tmp12 = -(tmp0 + tmp2);
 
542
                }
 
543
            } else {
 
544
                if (d0) {
 
545
                    /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
 
546
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
547
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
548
 
 
549
                    tmp0 = (d0 + d4) << CONST_BITS;
 
550
                    tmp1 = (d0 - d4) << CONST_BITS;
 
551
 
 
552
                    tmp10 = tmp0 + tmp3;
 
553
                    tmp13 = tmp0 - tmp3;
 
554
                    tmp11 = tmp1 + tmp2;
 
555
                    tmp12 = tmp1 - tmp2;
 
556
                } else {
 
557
                    /* d0 == 0, d2 == 0, d4 != 0, d6 != 0 */
 
558
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
559
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
560
 
 
561
                    tmp0 = d4 << CONST_BITS;
 
562
 
 
563
                    tmp10 = tmp0 + tmp3;
 
564
                    tmp13 = tmp0 - tmp3;
 
565
                    tmp11 = tmp2 - tmp0;
 
566
                    tmp12 = -(tmp0 + tmp2);
 
567
                }
 
568
            }
 
569
        } else {
 
570
            if (d2) {
 
571
                if (d0) {
 
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));
 
576
 
 
577
                    tmp0 = d0 << CONST_BITS;
 
578
 
 
579
                    tmp10 = tmp0 + tmp3;
 
580
                    tmp13 = tmp0 - tmp3;
 
581
                    tmp11 = tmp0 + tmp2;
 
582
                    tmp12 = tmp0 - tmp2;
 
583
                } else {
 
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));
 
588
 
 
589
                    tmp10 = tmp3;
 
590
                    tmp13 = -tmp3;
 
591
                    tmp11 = tmp2;
 
592
                    tmp12 = -tmp2;
 
593
                }
 
594
            } else {
 
595
                if (d0) {
 
596
                    /* d0 != 0, d2 == 0, d4 == 0, d6 != 0 */
 
597
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
598
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
599
 
 
600
                    tmp0 = d0 << CONST_BITS;
 
601
 
 
602
                    tmp10 = tmp0 + tmp3;
 
603
                    tmp13 = tmp0 - tmp3;
 
604
                    tmp11 = tmp0 + tmp2;
 
605
                    tmp12 = tmp0 - tmp2;
 
606
                } else {
 
607
                    /* d0 == 0, d2 == 0, d4 == 0, d6 != 0 */
 
608
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
609
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
610
 
 
611
                    tmp10 = tmp3;
 
612
                    tmp13 = -tmp3;
 
613
                    tmp11 = tmp2;
 
614
                    tmp12 = -tmp2;
 
615
                }
 
616
            }
 
617
        }
 
618
    } else {
 
619
        if (d4) {
 
620
            if (d2) {
 
621
                if (d0) {
 
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)));
 
625
 
 
626
                    tmp0 = (d0 + d4) << CONST_BITS;
 
627
                    tmp1 = (d0 - d4) << CONST_BITS;
 
628
 
 
629
                    tmp10 = tmp0 + tmp3;
 
630
                    tmp13 = tmp0 - tmp3;
 
631
                    tmp11 = tmp1 + tmp2;
 
632
                    tmp12 = tmp1 - tmp2;
 
633
                } else {
 
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)));
 
637
 
 
638
                    tmp0 = d4 << CONST_BITS;
 
639
 
 
640
                    tmp10 = tmp0 + tmp3;
 
641
                    tmp13 = tmp0 - tmp3;
 
642
                    tmp11 = tmp2 - tmp0;
 
643
                    tmp12 = -(tmp0 + tmp2);
 
644
                }
 
645
            } else {
 
646
                if (d0) {
 
647
                    /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
 
648
                    tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
 
649
                    tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
 
650
                } else {
 
651
                    /* d0 == 0, d2 == 0, d4 != 0, d6 == 0 */
 
652
                    tmp10 = tmp13 = d4 << CONST_BITS;
 
653
                    tmp11 = tmp12 = -tmp10;
 
654
                }
 
655
            }
 
656
        } else {
 
657
            if (d2) {
 
658
                if (d0) {
 
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)));
 
662
 
 
663
                    tmp0 = d0 << CONST_BITS;
 
664
 
 
665
                    tmp10 = tmp0 + tmp3;
 
666
                    tmp13 = tmp0 - tmp3;
 
667
                    tmp11 = tmp0 + tmp2;
 
668
                    tmp12 = tmp0 - tmp2;
 
669
                } else {
 
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)));
 
673
 
 
674
                    tmp10 = tmp3;
 
675
                    tmp13 = -tmp3;
 
676
                    tmp11 = tmp2;
 
677
                    tmp12 = -tmp2;
 
678
                }
 
679
            } else {
 
680
                if (d0) {
 
681
                    /* d0 != 0, d2 == 0, d4 == 0, d6 == 0 */
 
682
                    tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
 
683
                } else {
 
684
                    /* d0 == 0, d2 == 0, d4 == 0, d6 == 0 */
 
685
                    tmp10 = tmp13 = tmp11 = tmp12 = 0;
 
686
                }
 
687
            }
 
688
        }
 
689
    }
 
690
 
 
691
 
 
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.
 
694
     */
 
695
 
 
696
    if (d7) {
 
697
        if (d5) {
 
698
            if (d3) {
 
699
                if (d1) {
 
700
                    /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
 
701
                    z1 = d7 + d1;
 
702
                    z2 = d5 + d3;
 
703
                    z3 = d7 + d3;
 
704
                    z4 = d5 + d1;
 
705
                    z5 = MULTIPLY(z3 + z4, FIX(1.175875602));
 
706
                    
 
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));
 
715
                    
 
716
                    z3 += z5;
 
717
                    z4 += z5;
 
718
                    
 
719
                    tmp0 += z1 + z3;
 
720
                    tmp1 += z2 + z4;
 
721
                    tmp2 += z2 + z3;
 
722
                    tmp3 += z1 + z4;
 
723
                } else {
 
724
                    /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
 
725
                    z2 = d5 + d3;
 
726
                    z3 = d7 + d3;
 
727
                    z5 = MULTIPLY(z3 + d5, FIX(1.175875602));
 
728
                    
 
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));
 
736
                    
 
737
                    z3 += z5;
 
738
                    z4 += z5;
 
739
                    
 
740
                    tmp0 += z1 + z3;
 
741
                    tmp1 += z2 + z4;
 
742
                    tmp2 += z2 + z3;
 
743
                    tmp3 = z1 + z4;
 
744
                }
 
745
            } else {
 
746
                if (d1) {
 
747
                    /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
 
748
                    z1 = d7 + d1;
 
749
                    z4 = d5 + d1;
 
750
                    z5 = MULTIPLY(d7 + z4, FIX(1.175875602));
 
751
                    
 
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));
 
759
                    
 
760
                    z3 += z5;
 
761
                    z4 += z5;
 
762
                    
 
763
                    tmp0 += z1 + z3;
 
764
                    tmp1 += z2 + z4;
 
765
                    tmp2 = z2 + z3;
 
766
                    tmp3 += z1 + z4;
 
767
                } else {
 
768
                    /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
 
769
                    z5 = MULTIPLY(d7 + d5, FIX(1.175875602));
 
770
 
 
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));
 
777
                    
 
778
                    z3 += z5;
 
779
                    z4 += z5;
 
780
                    
 
781
                    tmp0 += z3;
 
782
                    tmp1 += z4;
 
783
                    tmp2 = z2 + z3;
 
784
                    tmp3 = z1 + z4;
 
785
                }
 
786
            }
 
787
        } else {
 
788
            if (d3) {
 
789
                if (d1) {
 
790
                    /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
 
791
                    z1 = d7 + d1;
 
792
                    z3 = d7 + d3;
 
793
                    z5 = MULTIPLY(z3 + d1, FIX(1.175875602));
 
794
                    
 
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));
 
802
                    
 
803
                    z3 += z5;
 
804
                    z4 += z5;
 
805
                    
 
806
                    tmp0 += z1 + z3;
 
807
                    tmp1 = z2 + z4;
 
808
                    tmp2 += z2 + z3;
 
809
                    tmp3 += z1 + z4;
 
810
                } else {
 
811
                    /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
 
812
                    z3 = d7 + d3;
 
813
                    z5 = MULTIPLY(z3, FIX(1.175875602));
 
814
                    
 
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));
 
820
                    
 
821
                    tmp0 += z3;
 
822
                    tmp1 = z2 + z5;
 
823
                    tmp2 += z3;
 
824
                    tmp3 = z1 + z5;
 
825
                }
 
826
            } else {
 
827
                if (d1) {
 
828
                    /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
 
829
                    z1 = d7 + d1;
 
830
                    z5 = MULTIPLY(z1, FIX(1.175875602));
 
831
 
 
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));
 
837
 
 
838
                    tmp0 += z1;
 
839
                    tmp1 = z4 + z5;
 
840
                    tmp2 = z3 + z5;
 
841
                    tmp3 += z1;
 
842
                } else {
 
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));
 
848
                }
 
849
            }
 
850
        }
 
851
    } else {
 
852
        if (d5) {
 
853
            if (d3) {
 
854
                if (d1) {
 
855
                    /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
 
856
                    z2 = d5 + d3;
 
857
                    z4 = d5 + d1;
 
858
                    z5 = MULTIPLY(d3 + z4, FIX(1.175875602));
 
859
                    
 
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));
 
867
                    
 
868
                    z3 += z5;
 
869
                    z4 += z5;
 
870
                    
 
871
                    tmp0 = z1 + z3;
 
872
                    tmp1 += z2 + z4;
 
873
                    tmp2 += z2 + z3;
 
874
                    tmp3 += z1 + z4;
 
875
                } else {
 
876
                    /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
 
877
                    z2 = d5 + d3;
 
878
                    z5 = MULTIPLY(z2, FIX(1.175875602));
 
879
                    
 
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));
 
885
                    
 
886
                    tmp0 = z3 + z5;
 
887
                    tmp1 += z2;
 
888
                    tmp2 += z2;
 
889
                    tmp3 = z4 + z5;
 
890
                }
 
891
            } else {
 
892
                if (d1) {
 
893
                    /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
 
894
                    z4 = d5 + d1;
 
895
                    z5 = MULTIPLY(z4, FIX(1.175875602));
 
896
                    
 
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));
 
902
                    
 
903
                    tmp0 = z1 + z5;
 
904
                    tmp2 = z2 + z5;
 
905
                    tmp1 += z4;
 
906
                    tmp3 += z4;
 
907
                } else {
 
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));
 
913
                }
 
914
            }
 
915
        } else {
 
916
            if (d3) {
 
917
                if (d1) {
 
918
                    /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
 
919
                    z5 = d3 + d1;
 
920
 
 
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));
 
927
                    
 
928
                    tmp0 = z1 - z4;
 
929
                    tmp1 = z2 + z4;
 
930
                    tmp2 += z5;
 
931
                    tmp3 += z5;
 
932
                } else {
 
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));
 
938
                }
 
939
            } else {
 
940
                if (d1) {
 
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));
 
946
                } else {
 
947
                    /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
 
948
                    tmp0 = tmp1 = tmp2 = tmp3 = 0;
 
949
                }
 
950
            }
 
951
        }
 
952
    }
 
953
 
 
954
    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
 
955
 
 
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);
 
964
 
 
965
    dataptr += DCTSIZE;         /* advance pointer to next row */
 
966
  }
 
967
 
 
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. */
 
971
 
 
972
  dataptr = data;
 
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.
 
980
     */
 
981
 
 
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];
 
990
 
 
991
    /* Even part: reverse the even part of the forward DCT. */
 
992
    /* The rotator is sqrt(2)*c(-6). */
 
993
    if (d6) {
 
994
        if (d4) {
 
995
            if (d2) {
 
996
                if (d0) {
 
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));
 
1001
 
 
1002
                    tmp0 = (d0 + d4) << CONST_BITS;
 
1003
                    tmp1 = (d0 - d4) << CONST_BITS;
 
1004
 
 
1005
                    tmp10 = tmp0 + tmp3;
 
1006
                    tmp13 = tmp0 - tmp3;
 
1007
                    tmp11 = tmp1 + tmp2;
 
1008
                    tmp12 = tmp1 - tmp2;
 
1009
                } else {
 
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));
 
1014
 
 
1015
                    tmp0 = d4 << CONST_BITS;
 
1016
 
 
1017
                    tmp10 = tmp0 + tmp3;
 
1018
                    tmp13 = tmp0 - tmp3;
 
1019
                    tmp11 = tmp2 - tmp0;
 
1020
                    tmp12 = -(tmp0 + tmp2);
 
1021
                }
 
1022
            } else {
 
1023
                if (d0) {
 
1024
                    /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
 
1025
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
1026
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
1027
 
 
1028
                    tmp0 = (d0 + d4) << CONST_BITS;
 
1029
                    tmp1 = (d0 - d4) << CONST_BITS;
 
1030
 
 
1031
                    tmp10 = tmp0 + tmp3;
 
1032
                    tmp13 = tmp0 - tmp3;
 
1033
                    tmp11 = tmp1 + tmp2;
 
1034
                    tmp12 = tmp1 - tmp2;
 
1035
                } else {
 
1036
                    /* d0 == 0, d2 == 0, d4 != 0, d6 != 0 */
 
1037
                    tmp2 = MULTIPLY(d6, -FIX2(1.306562965));
 
1038
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
1039
 
 
1040
                    tmp0 = d4 << CONST_BITS;
 
1041
 
 
1042
                    tmp10 = tmp0 + tmp3;
 
1043
                    tmp13 = tmp0 - tmp3;
 
1044
                    tmp11 = tmp2 - tmp0;
 
1045
                    tmp12 = -(tmp0 + tmp2);
 
1046
                }
 
1047
            }
 
1048
        } else {
 
1049
            if (d2) {
 
1050
                if (d0) {
 
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));
 
1055
 
 
1056
                    tmp0 = d0 << CONST_BITS;
 
1057
 
 
1058
                    tmp10 = tmp0 + tmp3;
 
1059
                    tmp13 = tmp0 - tmp3;
 
1060
                    tmp11 = tmp0 + tmp2;
 
1061
                    tmp12 = tmp0 - tmp2;
 
1062
                } else {
 
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));
 
1067
 
 
1068
                    tmp10 = tmp3;
 
1069
                    tmp13 = -tmp3;
 
1070
                    tmp11 = tmp2;
 
1071
                    tmp12 = -tmp2;
 
1072
                }
 
1073
            } else {
 
1074
                if (d0) {
 
1075
                    /* d0 != 0, d2 == 0, d4 == 0, d6 != 0 */
 
1076
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
1077
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
1078
 
 
1079
                    tmp0 = d0 << CONST_BITS;
 
1080
 
 
1081
                    tmp10 = tmp0 + tmp3;
 
1082
                    tmp13 = tmp0 - tmp3;
 
1083
                    tmp11 = tmp0 + tmp2;
 
1084
                    tmp12 = tmp0 - tmp2;
 
1085
                } else {
 
1086
                    /* d0 == 0, d2 == 0, d4 == 0, d6 != 0 */
 
1087
                    tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
 
1088
                    tmp3 = MULTIPLY(d6, FIX(0.541196100));
 
1089
 
 
1090
                    tmp10 = tmp3;
 
1091
                    tmp13 = -tmp3;
 
1092
                    tmp11 = tmp2;
 
1093
                    tmp12 = -tmp2;
 
1094
                }
 
1095
            }
 
1096
        }
 
1097
    } else {
 
1098
        if (d4) {
 
1099
            if (d2) {
 
1100
                if (d0) {
 
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)));
 
1104
 
 
1105
                    tmp0 = (d0 + d4) << CONST_BITS;
 
1106
                    tmp1 = (d0 - d4) << CONST_BITS;
 
1107
 
 
1108
                    tmp10 = tmp0 + tmp3;
 
1109
                    tmp13 = tmp0 - tmp3;
 
1110
                    tmp11 = tmp1 + tmp2;
 
1111
                    tmp12 = tmp1 - tmp2;
 
1112
                } else {
 
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)));
 
1116
 
 
1117
                    tmp0 = d4 << CONST_BITS;
 
1118
 
 
1119
                    tmp10 = tmp0 + tmp3;
 
1120
                    tmp13 = tmp0 - tmp3;
 
1121
                    tmp11 = tmp2 - tmp0;
 
1122
                    tmp12 = -(tmp0 + tmp2);
 
1123
                }
 
1124
            } else {
 
1125
                if (d0) {
 
1126
                    /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
 
1127
                    tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
 
1128
                    tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
 
1129
                } else {
 
1130
                    /* d0 == 0, d2 == 0, d4 != 0, d6 == 0 */
 
1131
                    tmp10 = tmp13 = d4 << CONST_BITS;
 
1132
                    tmp11 = tmp12 = -tmp10;
 
1133
                }
 
1134
            }
 
1135
        } else {
 
1136
            if (d2) {
 
1137
                if (d0) {
 
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)));
 
1141
 
 
1142
                    tmp0 = d0 << CONST_BITS;
 
1143
 
 
1144
                    tmp10 = tmp0 + tmp3;
 
1145
                    tmp13 = tmp0 - tmp3;
 
1146
                    tmp11 = tmp0 + tmp2;
 
1147
                    tmp12 = tmp0 - tmp2;
 
1148
                } else {
 
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)));
 
1152
 
 
1153
                    tmp10 = tmp3;
 
1154
                    tmp13 = -tmp3;
 
1155
                    tmp11 = tmp2;
 
1156
                    tmp12 = -tmp2;
 
1157
                }
 
1158
            } else {
 
1159
                if (d0) {
 
1160
                    /* d0 != 0, d2 == 0, d4 == 0, d6 == 0 */
 
1161
                    tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
 
1162
                } else {
 
1163
                    /* d0 == 0, d2 == 0, d4 == 0, d6 == 0 */
 
1164
                    tmp10 = tmp13 = tmp11 = tmp12 = 0;
 
1165
                }
 
1166
            }
 
1167
        }
 
1168
    }
 
1169
 
 
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.
 
1172
     */
 
1173
    if (d7) {
 
1174
        if (d5) {
 
1175
            if (d3) {
 
1176
                if (d1) {
 
1177
                    /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
 
1178
                    z1 = d7 + d1;
 
1179
                    z2 = d5 + d3;
 
1180
                    z3 = d7 + d3;
 
1181
                    z4 = d5 + d1;
 
1182
                    z5 = MULTIPLY(z3 + z4, FIX(1.175875602));
 
1183
                    
 
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));
 
1192
                    
 
1193
                    z3 += z5;
 
1194
                    z4 += z5;
 
1195
                    
 
1196
                    tmp0 += z1 + z3;
 
1197
                    tmp1 += z2 + z4;
 
1198
                    tmp2 += z2 + z3;
 
1199
                    tmp3 += z1 + z4;
 
1200
                } else {
 
1201
                    /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
 
1202
                    z2 = d5 + d3;
 
1203
                    z3 = d7 + d3;
 
1204
                    z5 = MULTIPLY(z3 + d5, FIX(1.175875602));
 
1205
                    
 
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));
 
1213
                    
 
1214
                    z3 += z5;
 
1215
                    z4 += z5;
 
1216
                    
 
1217
                    tmp0 += z1 + z3;
 
1218
                    tmp1 += z2 + z4;
 
1219
                    tmp2 += z2 + z3;
 
1220
                    tmp3 = z1 + z4;
 
1221
                }
 
1222
            } else {
 
1223
                if (d1) {
 
1224
                    /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
 
1225
                    z1 = d7 + d1;
 
1226
                    z4 = d5 + d1;
 
1227
                    z5 = MULTIPLY(d7 + z4, FIX(1.175875602));
 
1228
                    
 
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));
 
1236
                    
 
1237
                    z3 += z5;
 
1238
                    z4 += z5;
 
1239
                    
 
1240
                    tmp0 += z1 + z3;
 
1241
                    tmp1 += z2 + z4;
 
1242
                    tmp2 = z2 + z3;
 
1243
                    tmp3 += z1 + z4;
 
1244
                } else {
 
1245
                    /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
 
1246
                    z5 = MULTIPLY(d5 + d7, FIX(1.175875602));
 
1247
 
 
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));
 
1254
                    
 
1255
                    z3 += z5;
 
1256
                    z4 += z5;
 
1257
                    
 
1258
                    tmp0 += z3;
 
1259
                    tmp1 += z4;
 
1260
                    tmp2 = z2 + z3;
 
1261
                    tmp3 = z1 + z4;
 
1262
                }
 
1263
            }
 
1264
        } else {
 
1265
            if (d3) {
 
1266
                if (d1) {
 
1267
                    /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
 
1268
                    z1 = d7 + d1;
 
1269
                    z3 = d7 + d3;
 
1270
                    z5 = MULTIPLY(z3 + d1, FIX(1.175875602));
 
1271
                    
 
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));
 
1279
                    
 
1280
                    z3 += z5;
 
1281
                    z4 += z5;
 
1282
                    
 
1283
                    tmp0 += z1 + z3;
 
1284
                    tmp1 = z2 + z4;
 
1285
                    tmp2 += z2 + z3;
 
1286
                    tmp3 += z1 + z4;
 
1287
                } else {
 
1288
                    /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
 
1289
                    z3 = d7 + d3;
 
1290
                    z5 = MULTIPLY(z3, FIX(1.175875602));
 
1291
                    
 
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));
 
1297
                    
 
1298
                    tmp0 += z3;
 
1299
                    tmp1 = z2 + z5;
 
1300
                    tmp2 += z3;
 
1301
                    tmp3 = z1 + z5;
 
1302
                }
 
1303
            } else {
 
1304
                if (d1) {
 
1305
                    /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
 
1306
                    z1 = d7 + d1;
 
1307
                    z5 = MULTIPLY(z1, FIX(1.175875602));
 
1308
 
 
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));
 
1314
 
 
1315
                    tmp0 += z1;
 
1316
                    tmp1 = z4 + z5;
 
1317
                    tmp2 = z3 + z5;
 
1318
                    tmp3 += z1;
 
1319
                } else {
 
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));
 
1325
                }
 
1326
            }
 
1327
        }
 
1328
    } else {
 
1329
        if (d5) {
 
1330
            if (d3) {
 
1331
                if (d1) {
 
1332
                    /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
 
1333
                    z2 = d5 + d3;
 
1334
                    z4 = d5 + d1;
 
1335
                    z5 = MULTIPLY(d3 + z4, FIX(1.175875602));
 
1336
                    
 
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));
 
1344
                    
 
1345
                    z3 += z5;
 
1346
                    z4 += z5;
 
1347
                    
 
1348
                    tmp0 = z1 + z3;
 
1349
                    tmp1 += z2 + z4;
 
1350
                    tmp2 += z2 + z3;
 
1351
                    tmp3 += z1 + z4;
 
1352
                } else {
 
1353
                    /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
 
1354
                    z2 = d5 + d3;
 
1355
                    z5 = MULTIPLY(z2, FIX(1.175875602));
 
1356
 
 
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));
 
1362
                    
 
1363
                    tmp0 = z3 + z5;
 
1364
                    tmp1 += z2;
 
1365
                    tmp2 += z2;
 
1366
                    tmp3 = z4 + z5;
 
1367
                }
 
1368
            } else {
 
1369
                if (d1) {
 
1370
                    /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
 
1371
                    z4 = d5 + d1;
 
1372
                    z5 = MULTIPLY(z4, FIX(1.175875602));
 
1373
                    
 
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));
 
1379
                    
 
1380
                    tmp0 = z1 + z5;
 
1381
                    tmp1 += z4;
 
1382
                    tmp2 = z2 + z5;
 
1383
                    tmp3 += z4;
 
1384
                } else {
 
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));
 
1390
                }
 
1391
            }
 
1392
        } else {
 
1393
            if (d3) {
 
1394
                if (d1) {
 
1395
                    /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
 
1396
                    z5 = d3 + d1;
 
1397
 
 
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));
 
1404
                    
 
1405
                    tmp0 = z1 - z4;
 
1406
                    tmp1 = z2 + z4;
 
1407
                    tmp2 += z5;
 
1408
                    tmp3 += z5;
 
1409
                } else {
 
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));
 
1415
                }
 
1416
            } else {
 
1417
                if (d1) {
 
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));
 
1423
                } else {
 
1424
                    /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
 
1425
                    tmp0 = tmp1 = tmp2 = tmp3 = 0;
 
1426
                }
 
1427
            }
 
1428
        }
 
1429
    }
 
1430
 
 
1431
    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
 
1432
 
 
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);
 
1449
    
 
1450
    dataptr++;                  /* advance pointer to next column */
 
1451
  }
 
1452
}
 
1453
 
 
1454
#else
 
1455
 
 
1456
 
 
1457
 
 
1458
/*
 
1459
 *--------------------------------------------------------------
 
1460
 *
 
1461
 * j_rev_dct --
 
1462
 *
 
1463
 *  The original inverse DCT function.
 
1464
 *
 
1465
 * Results:
 
1466
 *      None.
 
1467
 *
 
1468
 * Side effects:
 
1469
 *      None.
 
1470
 *
 
1471
 *--------------------------------------------------------------
 
1472
 */
 
1473
void j_rev_dct (DCTBLOCK data)
 
1474
{
 
1475
  INT32 tmp0, tmp1, tmp2, tmp3;
 
1476
  INT32 tmp10, tmp11, tmp12, tmp13;
 
1477
  INT32 z1, z2, z3, z4, z5;
 
1478
  register DCTELEM *dataptr;
 
1479
  int rowctr;
 
1480
  SHIFT_TEMPS
 
1481
 
 
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. */
 
1485
 
 
1486
  dataptr = data;
 
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.
 
1495
     */
 
1496
 
 
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);
 
1501
      
 
1502
      dataptr[0] = dcval;
 
1503
      dataptr[1] = dcval;
 
1504
      dataptr[2] = dcval;
 
1505
      dataptr[3] = dcval;
 
1506
      dataptr[4] = dcval;
 
1507
      dataptr[5] = dcval;
 
1508
      dataptr[6] = dcval;
 
1509
      dataptr[7] = dcval;
 
1510
      
 
1511
      dataptr += DCTSIZE;       /* advance pointer to next row */
 
1512
      continue;
 
1513
    }
 
1514
 
 
1515
    /* Even part: reverse the even part of the forward DCT. */
 
1516
    /* The rotator is sqrt(2)*c(-6). */
 
1517
 
 
1518
    z2 = (INT32) dataptr[2];
 
1519
    z3 = (INT32) dataptr[6];
 
1520
 
 
1521
    z1 = MULTIPLY(z2 + z3, FIX(0.541196100));
 
1522
    tmp2 = z1 + MULTIPLY(z3, - FIX(1.847759065));
 
1523
    tmp3 = z1 + MULTIPLY(z2, FIX(0.765366865));
 
1524
 
 
1525
    tmp0 = ((INT32) dataptr[0] + (INT32) dataptr[4]) << CONST_BITS;
 
1526
    tmp1 = ((INT32) dataptr[0] - (INT32) dataptr[4]) << CONST_BITS;
 
1527
 
 
1528
    tmp10 = tmp0 + tmp3;
 
1529
    tmp13 = tmp0 - tmp3;
 
1530
    tmp11 = tmp1 + tmp2;
 
1531
    tmp12 = tmp1 - tmp2;
 
1532
    
 
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.
 
1535
     */
 
1536
 
 
1537
    tmp0 = (INT32) dataptr[7];
 
1538
    tmp1 = (INT32) dataptr[5];
 
1539
    tmp2 = (INT32) dataptr[3];
 
1540
    tmp3 = (INT32) dataptr[1];
 
1541
 
 
1542
    z1 = tmp0 + tmp3;
 
1543
    z2 = tmp1 + tmp2;
 
1544
    z3 = tmp0 + tmp2;
 
1545
    z4 = tmp1 + tmp3;
 
1546
    z5 = MULTIPLY(z3 + z4, FIX(1.175875602)); /* sqrt(2) * c3 */
 
1547
    
 
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) */
 
1556
    
 
1557
    z3 += z5;
 
1558
    z4 += z5;
 
1559
    
 
1560
    tmp0 += z1 + z3;
 
1561
    tmp1 += z2 + z4;
 
1562
    tmp2 += z2 + z3;
 
1563
    tmp3 += z1 + z4;
 
1564
 
 
1565
    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
 
1566
 
 
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);
 
1575
 
 
1576
    dataptr += DCTSIZE;         /* advance pointer to next row */
 
1577
  }
 
1578
 
 
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. */
 
1582
 
 
1583
  dataptr = data;
 
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.
 
1591
     */
 
1592
 
 
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);
 
1599
      
 
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;
 
1608
      
 
1609
      dataptr++;                /* advance pointer to next column */
 
1610
      continue;
 
1611
    }
 
1612
#endif
 
1613
 
 
1614
    /* Even part: reverse the even part of the forward DCT. */
 
1615
    /* The rotator is sqrt(2)*c(-6). */
 
1616
 
 
1617
    z2 = (INT32) dataptr[DCTSIZE*2];
 
1618
    z3 = (INT32) dataptr[DCTSIZE*6];
 
1619
 
 
1620
    z1 = MULTIPLY(z2 + z3, FIX(0.541196100));
 
1621
    tmp2 = z1 + MULTIPLY(z3, - FIX(1.847759065));
 
1622
    tmp3 = z1 + MULTIPLY(z2, FIX(0.765366865));
 
1623
 
 
1624
    tmp0 = ((INT32) dataptr[DCTSIZE*0] + (INT32) dataptr[DCTSIZE*4]) << CONST_BITS;
 
1625
    tmp1 = ((INT32) dataptr[DCTSIZE*0] - (INT32) dataptr[DCTSIZE*4]) << CONST_BITS;
 
1626
 
 
1627
    tmp10 = tmp0 + tmp3;
 
1628
    tmp13 = tmp0 - tmp3;
 
1629
    tmp11 = tmp1 + tmp2;
 
1630
    tmp12 = tmp1 - tmp2;
 
1631
    
 
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.
 
1634
     */
 
1635
 
 
1636
    tmp0 = (INT32) dataptr[DCTSIZE*7];
 
1637
    tmp1 = (INT32) dataptr[DCTSIZE*5];
 
1638
    tmp2 = (INT32) dataptr[DCTSIZE*3];
 
1639
    tmp3 = (INT32) dataptr[DCTSIZE*1];
 
1640
 
 
1641
    z1 = tmp0 + tmp3;
 
1642
    z2 = tmp1 + tmp2;
 
1643
    z3 = tmp0 + tmp2;
 
1644
    z4 = tmp1 + tmp3;
 
1645
    z5 = MULTIPLY(z3 + z4, FIX(1.175875602)); /* sqrt(2) * c3 */
 
1646
    
 
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) */
 
1655
    
 
1656
    z3 += z5;
 
1657
    z4 += z5;
 
1658
    
 
1659
    tmp0 += z1 + z3;
 
1660
    tmp1 += z2 + z4;
 
1661
    tmp2 += z2 + z3;
 
1662
    tmp3 += z1 + z4;
 
1663
 
 
1664
    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
 
1665
 
 
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);
 
1682
    
 
1683
    dataptr++;                  /* advance pointer to next column */
 
1684
  }
 
1685
}
 
1686
 
 
1687
 
 
1688
#endif /* ORIG_DCT */
 
1689
#endif /* FIVE_DCT */
 
1690