1*dfc6aa5cSAndroid Build Coastguard Worker /* 2*dfc6aa5cSAndroid Build Coastguard Worker * jfdctflt.c 3*dfc6aa5cSAndroid Build Coastguard Worker * 4*dfc6aa5cSAndroid Build Coastguard Worker * Copyright (C) 1994-1996, Thomas G. Lane. 5*dfc6aa5cSAndroid Build Coastguard Worker * This file is part of the Independent JPEG Group's software. 6*dfc6aa5cSAndroid Build Coastguard Worker * For conditions of distribution and use, see the accompanying README.ijg 7*dfc6aa5cSAndroid Build Coastguard Worker * file. 8*dfc6aa5cSAndroid Build Coastguard Worker * 9*dfc6aa5cSAndroid Build Coastguard Worker * This file contains a floating-point implementation of the 10*dfc6aa5cSAndroid Build Coastguard Worker * forward DCT (Discrete Cosine Transform). 11*dfc6aa5cSAndroid Build Coastguard Worker * 12*dfc6aa5cSAndroid Build Coastguard Worker * This implementation should be more accurate than either of the integer 13*dfc6aa5cSAndroid Build Coastguard Worker * DCT implementations. However, it may not give the same results on all 14*dfc6aa5cSAndroid Build Coastguard Worker * machines because of differences in roundoff behavior. Speed will depend 15*dfc6aa5cSAndroid Build Coastguard Worker * on the hardware's floating point capacity. 16*dfc6aa5cSAndroid Build Coastguard Worker * 17*dfc6aa5cSAndroid Build Coastguard Worker * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT 18*dfc6aa5cSAndroid Build Coastguard Worker * on each column. Direct algorithms are also available, but they are 19*dfc6aa5cSAndroid Build Coastguard Worker * much more complex and seem not to be any faster when reduced to code. 20*dfc6aa5cSAndroid Build Coastguard Worker * 21*dfc6aa5cSAndroid Build Coastguard Worker * This implementation is based on Arai, Agui, and Nakajima's algorithm for 22*dfc6aa5cSAndroid Build Coastguard Worker * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 23*dfc6aa5cSAndroid Build Coastguard Worker * Japanese, but the algorithm is described in the Pennebaker & Mitchell 24*dfc6aa5cSAndroid Build Coastguard Worker * JPEG textbook (see REFERENCES section in file README.ijg). The following 25*dfc6aa5cSAndroid Build Coastguard Worker * code is based directly on figure 4-8 in P&M. 26*dfc6aa5cSAndroid Build Coastguard Worker * While an 8-point DCT cannot be done in less than 11 multiplies, it is 27*dfc6aa5cSAndroid Build Coastguard Worker * possible to arrange the computation so that many of the multiplies are 28*dfc6aa5cSAndroid Build Coastguard Worker * simple scalings of the final outputs. These multiplies can then be 29*dfc6aa5cSAndroid Build Coastguard Worker * folded into the multiplications or divisions by the JPEG quantization 30*dfc6aa5cSAndroid Build Coastguard Worker * table entries. The AA&N method leaves only 5 multiplies and 29 adds 31*dfc6aa5cSAndroid Build Coastguard Worker * to be done in the DCT itself. 32*dfc6aa5cSAndroid Build Coastguard Worker * The primary disadvantage of this method is that with a fixed-point 33*dfc6aa5cSAndroid Build Coastguard Worker * implementation, accuracy is lost due to imprecise representation of the 34*dfc6aa5cSAndroid Build Coastguard Worker * scaled quantization values. However, that problem does not arise if 35*dfc6aa5cSAndroid Build Coastguard Worker * we use floating point arithmetic. 36*dfc6aa5cSAndroid Build Coastguard Worker */ 37*dfc6aa5cSAndroid Build Coastguard Worker 38*dfc6aa5cSAndroid Build Coastguard Worker #define JPEG_INTERNALS 39*dfc6aa5cSAndroid Build Coastguard Worker #include "jinclude.h" 40*dfc6aa5cSAndroid Build Coastguard Worker #include "jpeglib.h" 41*dfc6aa5cSAndroid Build Coastguard Worker #include "jdct.h" /* Private declarations for DCT subsystem */ 42*dfc6aa5cSAndroid Build Coastguard Worker 43*dfc6aa5cSAndroid Build Coastguard Worker #ifdef DCT_FLOAT_SUPPORTED 44*dfc6aa5cSAndroid Build Coastguard Worker 45*dfc6aa5cSAndroid Build Coastguard Worker 46*dfc6aa5cSAndroid Build Coastguard Worker /* 47*dfc6aa5cSAndroid Build Coastguard Worker * This module is specialized to the case DCTSIZE = 8. 48*dfc6aa5cSAndroid Build Coastguard Worker */ 49*dfc6aa5cSAndroid Build Coastguard Worker 50*dfc6aa5cSAndroid Build Coastguard Worker #if DCTSIZE != 8 51*dfc6aa5cSAndroid Build Coastguard Worker Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 52*dfc6aa5cSAndroid Build Coastguard Worker #endif 53*dfc6aa5cSAndroid Build Coastguard Worker 54*dfc6aa5cSAndroid Build Coastguard Worker 55*dfc6aa5cSAndroid Build Coastguard Worker /* 56*dfc6aa5cSAndroid Build Coastguard Worker * Perform the forward DCT on one block of samples. 57*dfc6aa5cSAndroid Build Coastguard Worker */ 58*dfc6aa5cSAndroid Build Coastguard Worker 59*dfc6aa5cSAndroid Build Coastguard Worker GLOBAL(void) 60*dfc6aa5cSAndroid Build Coastguard Worker jpeg_fdct_float(FAST_FLOAT *data) 61*dfc6aa5cSAndroid Build Coastguard Worker { 62*dfc6aa5cSAndroid Build Coastguard Worker FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 63*dfc6aa5cSAndroid Build Coastguard Worker FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 64*dfc6aa5cSAndroid Build Coastguard Worker FAST_FLOAT z1, z2, z3, z4, z5, z11, z13; 65*dfc6aa5cSAndroid Build Coastguard Worker FAST_FLOAT *dataptr; 66*dfc6aa5cSAndroid Build Coastguard Worker int ctr; 67*dfc6aa5cSAndroid Build Coastguard Worker 68*dfc6aa5cSAndroid Build Coastguard Worker /* Pass 1: process rows. */ 69*dfc6aa5cSAndroid Build Coastguard Worker 70*dfc6aa5cSAndroid Build Coastguard Worker dataptr = data; 71*dfc6aa5cSAndroid Build Coastguard Worker for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) { 72*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = dataptr[0] + dataptr[7]; 73*dfc6aa5cSAndroid Build Coastguard Worker tmp7 = dataptr[0] - dataptr[7]; 74*dfc6aa5cSAndroid Build Coastguard Worker tmp1 = dataptr[1] + dataptr[6]; 75*dfc6aa5cSAndroid Build Coastguard Worker tmp6 = dataptr[1] - dataptr[6]; 76*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = dataptr[2] + dataptr[5]; 77*dfc6aa5cSAndroid Build Coastguard Worker tmp5 = dataptr[2] - dataptr[5]; 78*dfc6aa5cSAndroid Build Coastguard Worker tmp3 = dataptr[3] + dataptr[4]; 79*dfc6aa5cSAndroid Build Coastguard Worker tmp4 = dataptr[3] - dataptr[4]; 80*dfc6aa5cSAndroid Build Coastguard Worker 81*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */ 82*dfc6aa5cSAndroid Build Coastguard Worker 83*dfc6aa5cSAndroid Build Coastguard Worker tmp10 = tmp0 + tmp3; /* phase 2 */ 84*dfc6aa5cSAndroid Build Coastguard Worker tmp13 = tmp0 - tmp3; 85*dfc6aa5cSAndroid Build Coastguard Worker tmp11 = tmp1 + tmp2; 86*dfc6aa5cSAndroid Build Coastguard Worker tmp12 = tmp1 - tmp2; 87*dfc6aa5cSAndroid Build Coastguard Worker 88*dfc6aa5cSAndroid Build Coastguard Worker dataptr[0] = tmp10 + tmp11; /* phase 3 */ 89*dfc6aa5cSAndroid Build Coastguard Worker dataptr[4] = tmp10 - tmp11; 90*dfc6aa5cSAndroid Build Coastguard Worker 91*dfc6aa5cSAndroid Build Coastguard Worker z1 = (tmp12 + tmp13) * ((FAST_FLOAT)0.707106781); /* c4 */ 92*dfc6aa5cSAndroid Build Coastguard Worker dataptr[2] = tmp13 + z1; /* phase 5 */ 93*dfc6aa5cSAndroid Build Coastguard Worker dataptr[6] = tmp13 - z1; 94*dfc6aa5cSAndroid Build Coastguard Worker 95*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */ 96*dfc6aa5cSAndroid Build Coastguard Worker 97*dfc6aa5cSAndroid Build Coastguard Worker tmp10 = tmp4 + tmp5; /* phase 2 */ 98*dfc6aa5cSAndroid Build Coastguard Worker tmp11 = tmp5 + tmp6; 99*dfc6aa5cSAndroid Build Coastguard Worker tmp12 = tmp6 + tmp7; 100*dfc6aa5cSAndroid Build Coastguard Worker 101*dfc6aa5cSAndroid Build Coastguard Worker /* The rotator is modified from fig 4-8 to avoid extra negations. */ 102*dfc6aa5cSAndroid Build Coastguard Worker z5 = (tmp10 - tmp12) * ((FAST_FLOAT)0.382683433); /* c6 */ 103*dfc6aa5cSAndroid Build Coastguard Worker z2 = ((FAST_FLOAT)0.541196100) * tmp10 + z5; /* c2-c6 */ 104*dfc6aa5cSAndroid Build Coastguard Worker z4 = ((FAST_FLOAT)1.306562965) * tmp12 + z5; /* c2+c6 */ 105*dfc6aa5cSAndroid Build Coastguard Worker z3 = tmp11 * ((FAST_FLOAT)0.707106781); /* c4 */ 106*dfc6aa5cSAndroid Build Coastguard Worker 107*dfc6aa5cSAndroid Build Coastguard Worker z11 = tmp7 + z3; /* phase 5 */ 108*dfc6aa5cSAndroid Build Coastguard Worker z13 = tmp7 - z3; 109*dfc6aa5cSAndroid Build Coastguard Worker 110*dfc6aa5cSAndroid Build Coastguard Worker dataptr[5] = z13 + z2; /* phase 6 */ 111*dfc6aa5cSAndroid Build Coastguard Worker dataptr[3] = z13 - z2; 112*dfc6aa5cSAndroid Build Coastguard Worker dataptr[1] = z11 + z4; 113*dfc6aa5cSAndroid Build Coastguard Worker dataptr[7] = z11 - z4; 114*dfc6aa5cSAndroid Build Coastguard Worker 115*dfc6aa5cSAndroid Build Coastguard Worker dataptr += DCTSIZE; /* advance pointer to next row */ 116*dfc6aa5cSAndroid Build Coastguard Worker } 117*dfc6aa5cSAndroid Build Coastguard Worker 118*dfc6aa5cSAndroid Build Coastguard Worker /* Pass 2: process columns. */ 119*dfc6aa5cSAndroid Build Coastguard Worker 120*dfc6aa5cSAndroid Build Coastguard Worker dataptr = data; 121*dfc6aa5cSAndroid Build Coastguard Worker for (ctr = DCTSIZE - 1; ctr >= 0; ctr--) { 122*dfc6aa5cSAndroid Build Coastguard Worker tmp0 = dataptr[DCTSIZE * 0] + dataptr[DCTSIZE * 7]; 123*dfc6aa5cSAndroid Build Coastguard Worker tmp7 = dataptr[DCTSIZE * 0] - dataptr[DCTSIZE * 7]; 124*dfc6aa5cSAndroid Build Coastguard Worker tmp1 = dataptr[DCTSIZE * 1] + dataptr[DCTSIZE * 6]; 125*dfc6aa5cSAndroid Build Coastguard Worker tmp6 = dataptr[DCTSIZE * 1] - dataptr[DCTSIZE * 6]; 126*dfc6aa5cSAndroid Build Coastguard Worker tmp2 = dataptr[DCTSIZE * 2] + dataptr[DCTSIZE * 5]; 127*dfc6aa5cSAndroid Build Coastguard Worker tmp5 = dataptr[DCTSIZE * 2] - dataptr[DCTSIZE * 5]; 128*dfc6aa5cSAndroid Build Coastguard Worker tmp3 = dataptr[DCTSIZE * 3] + dataptr[DCTSIZE * 4]; 129*dfc6aa5cSAndroid Build Coastguard Worker tmp4 = dataptr[DCTSIZE * 3] - dataptr[DCTSIZE * 4]; 130*dfc6aa5cSAndroid Build Coastguard Worker 131*dfc6aa5cSAndroid Build Coastguard Worker /* Even part */ 132*dfc6aa5cSAndroid Build Coastguard Worker 133*dfc6aa5cSAndroid Build Coastguard Worker tmp10 = tmp0 + tmp3; /* phase 2 */ 134*dfc6aa5cSAndroid Build Coastguard Worker tmp13 = tmp0 - tmp3; 135*dfc6aa5cSAndroid Build Coastguard Worker tmp11 = tmp1 + tmp2; 136*dfc6aa5cSAndroid Build Coastguard Worker tmp12 = tmp1 - tmp2; 137*dfc6aa5cSAndroid Build Coastguard Worker 138*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 0] = tmp10 + tmp11; /* phase 3 */ 139*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 4] = tmp10 - tmp11; 140*dfc6aa5cSAndroid Build Coastguard Worker 141*dfc6aa5cSAndroid Build Coastguard Worker z1 = (tmp12 + tmp13) * ((FAST_FLOAT)0.707106781); /* c4 */ 142*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 2] = tmp13 + z1; /* phase 5 */ 143*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 6] = tmp13 - z1; 144*dfc6aa5cSAndroid Build Coastguard Worker 145*dfc6aa5cSAndroid Build Coastguard Worker /* Odd part */ 146*dfc6aa5cSAndroid Build Coastguard Worker 147*dfc6aa5cSAndroid Build Coastguard Worker tmp10 = tmp4 + tmp5; /* phase 2 */ 148*dfc6aa5cSAndroid Build Coastguard Worker tmp11 = tmp5 + tmp6; 149*dfc6aa5cSAndroid Build Coastguard Worker tmp12 = tmp6 + tmp7; 150*dfc6aa5cSAndroid Build Coastguard Worker 151*dfc6aa5cSAndroid Build Coastguard Worker /* The rotator is modified from fig 4-8 to avoid extra negations. */ 152*dfc6aa5cSAndroid Build Coastguard Worker z5 = (tmp10 - tmp12) * ((FAST_FLOAT)0.382683433); /* c6 */ 153*dfc6aa5cSAndroid Build Coastguard Worker z2 = ((FAST_FLOAT)0.541196100) * tmp10 + z5; /* c2-c6 */ 154*dfc6aa5cSAndroid Build Coastguard Worker z4 = ((FAST_FLOAT)1.306562965) * tmp12 + z5; /* c2+c6 */ 155*dfc6aa5cSAndroid Build Coastguard Worker z3 = tmp11 * ((FAST_FLOAT)0.707106781); /* c4 */ 156*dfc6aa5cSAndroid Build Coastguard Worker 157*dfc6aa5cSAndroid Build Coastguard Worker z11 = tmp7 + z3; /* phase 5 */ 158*dfc6aa5cSAndroid Build Coastguard Worker z13 = tmp7 - z3; 159*dfc6aa5cSAndroid Build Coastguard Worker 160*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 5] = z13 + z2; /* phase 6 */ 161*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 3] = z13 - z2; 162*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 1] = z11 + z4; 163*dfc6aa5cSAndroid Build Coastguard Worker dataptr[DCTSIZE * 7] = z11 - z4; 164*dfc6aa5cSAndroid Build Coastguard Worker 165*dfc6aa5cSAndroid Build Coastguard Worker dataptr++; /* advance pointer to next column */ 166*dfc6aa5cSAndroid Build Coastguard Worker } 167*dfc6aa5cSAndroid Build Coastguard Worker } 168*dfc6aa5cSAndroid Build Coastguard Worker 169*dfc6aa5cSAndroid Build Coastguard Worker #endif /* DCT_FLOAT_SUPPORTED */ 170