Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shoaib_ahmed 0:791a779d6220 1 /*
shoaib_ahmed 0:791a779d6220 2 * jidctflt.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1994-1998, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * Modified 2010-2015 by Guido Vollbeding.
shoaib_ahmed 0:791a779d6220 6 * This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 7 * For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 8 *
shoaib_ahmed 0:791a779d6220 9 * This file contains a floating-point implementation of the
shoaib_ahmed 0:791a779d6220 10 * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
shoaib_ahmed 0:791a779d6220 11 * must also perform dequantization of the input coefficients.
shoaib_ahmed 0:791a779d6220 12 *
shoaib_ahmed 0:791a779d6220 13 * This implementation should be more accurate than either of the integer
shoaib_ahmed 0:791a779d6220 14 * IDCT implementations. However, it may not give the same results on all
shoaib_ahmed 0:791a779d6220 15 * machines because of differences in roundoff behavior. Speed will depend
shoaib_ahmed 0:791a779d6220 16 * on the hardware's floating point capacity.
shoaib_ahmed 0:791a779d6220 17 *
shoaib_ahmed 0:791a779d6220 18 * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
shoaib_ahmed 0:791a779d6220 19 * on each row (or vice versa, but it's more convenient to emit a row at
shoaib_ahmed 0:791a779d6220 20 * a time). Direct algorithms are also available, but they are much more
shoaib_ahmed 0:791a779d6220 21 * complex and seem not to be any faster when reduced to code.
shoaib_ahmed 0:791a779d6220 22 *
shoaib_ahmed 0:791a779d6220 23 * This implementation is based on Arai, Agui, and Nakajima's algorithm for
shoaib_ahmed 0:791a779d6220 24 * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
shoaib_ahmed 0:791a779d6220 25 * Japanese, but the algorithm is described in the Pennebaker & Mitchell
shoaib_ahmed 0:791a779d6220 26 * JPEG textbook (see REFERENCES section in file README). The following code
shoaib_ahmed 0:791a779d6220 27 * is based directly on figure 4-8 in P&M.
shoaib_ahmed 0:791a779d6220 28 * While an 8-point DCT cannot be done in less than 11 multiplies, it is
shoaib_ahmed 0:791a779d6220 29 * possible to arrange the computation so that many of the multiplies are
shoaib_ahmed 0:791a779d6220 30 * simple scalings of the final outputs. These multiplies can then be
shoaib_ahmed 0:791a779d6220 31 * folded into the multiplications or divisions by the JPEG quantization
shoaib_ahmed 0:791a779d6220 32 * table entries. The AA&N method leaves only 5 multiplies and 29 adds
shoaib_ahmed 0:791a779d6220 33 * to be done in the DCT itself.
shoaib_ahmed 0:791a779d6220 34 * The primary disadvantage of this method is that with a fixed-point
shoaib_ahmed 0:791a779d6220 35 * implementation, accuracy is lost due to imprecise representation of the
shoaib_ahmed 0:791a779d6220 36 * scaled quantization values. However, that problem does not arise if
shoaib_ahmed 0:791a779d6220 37 * we use floating point arithmetic.
shoaib_ahmed 0:791a779d6220 38 */
shoaib_ahmed 0:791a779d6220 39
shoaib_ahmed 0:791a779d6220 40 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 41 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 42 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 43 #include "jdct.h" /* Private declarations for DCT subsystem */
shoaib_ahmed 0:791a779d6220 44
shoaib_ahmed 0:791a779d6220 45 #ifdef DCT_FLOAT_SUPPORTED
shoaib_ahmed 0:791a779d6220 46
shoaib_ahmed 0:791a779d6220 47
shoaib_ahmed 0:791a779d6220 48 /*
shoaib_ahmed 0:791a779d6220 49 * This module is specialized to the case DCTSIZE = 8.
shoaib_ahmed 0:791a779d6220 50 */
shoaib_ahmed 0:791a779d6220 51
shoaib_ahmed 0:791a779d6220 52 #if DCTSIZE != 8
shoaib_ahmed 0:791a779d6220 53 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
shoaib_ahmed 0:791a779d6220 54 #endif
shoaib_ahmed 0:791a779d6220 55
shoaib_ahmed 0:791a779d6220 56
shoaib_ahmed 0:791a779d6220 57 /* Dequantize a coefficient by multiplying it by the multiplier-table
shoaib_ahmed 0:791a779d6220 58 * entry; produce a float result.
shoaib_ahmed 0:791a779d6220 59 */
shoaib_ahmed 0:791a779d6220 60
shoaib_ahmed 0:791a779d6220 61 #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
shoaib_ahmed 0:791a779d6220 62
shoaib_ahmed 0:791a779d6220 63
shoaib_ahmed 0:791a779d6220 64 /*
shoaib_ahmed 0:791a779d6220 65 * Perform dequantization and inverse DCT on one block of coefficients.
shoaib_ahmed 0:791a779d6220 66 *
shoaib_ahmed 0:791a779d6220 67 * cK represents cos(K*pi/16).
shoaib_ahmed 0:791a779d6220 68 */
shoaib_ahmed 0:791a779d6220 69
shoaib_ahmed 0:791a779d6220 70 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 71 jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
shoaib_ahmed 0:791a779d6220 72 JCOEFPTR coef_block,
shoaib_ahmed 0:791a779d6220 73 JSAMPARRAY output_buf, JDIMENSION output_col)
shoaib_ahmed 0:791a779d6220 74 {
shoaib_ahmed 0:791a779d6220 75 FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
shoaib_ahmed 0:791a779d6220 76 FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
shoaib_ahmed 0:791a779d6220 77 FAST_FLOAT z5, z10, z11, z12, z13;
shoaib_ahmed 0:791a779d6220 78 JCOEFPTR inptr;
shoaib_ahmed 0:791a779d6220 79 FLOAT_MULT_TYPE * quantptr;
shoaib_ahmed 0:791a779d6220 80 FAST_FLOAT * wsptr;
shoaib_ahmed 0:791a779d6220 81 JSAMPROW outptr;
shoaib_ahmed 0:791a779d6220 82 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
shoaib_ahmed 0:791a779d6220 83 int ctr;
shoaib_ahmed 0:791a779d6220 84 FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
shoaib_ahmed 0:791a779d6220 85
shoaib_ahmed 0:791a779d6220 86 /* Pass 1: process columns from input, store into work array. */
shoaib_ahmed 0:791a779d6220 87
shoaib_ahmed 0:791a779d6220 88 inptr = coef_block;
shoaib_ahmed 0:791a779d6220 89 quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
shoaib_ahmed 0:791a779d6220 90 wsptr = workspace;
shoaib_ahmed 0:791a779d6220 91 for (ctr = DCTSIZE; ctr > 0; ctr--) {
shoaib_ahmed 0:791a779d6220 92 /* Due to quantization, we will usually find that many of the input
shoaib_ahmed 0:791a779d6220 93 * coefficients are zero, especially the AC terms. We can exploit this
shoaib_ahmed 0:791a779d6220 94 * by short-circuiting the IDCT calculation for any column in which all
shoaib_ahmed 0:791a779d6220 95 * the AC terms are zero. In that case each output is equal to the
shoaib_ahmed 0:791a779d6220 96 * DC coefficient (with scale factor as needed).
shoaib_ahmed 0:791a779d6220 97 * With typical images and quantization tables, half or more of the
shoaib_ahmed 0:791a779d6220 98 * column DCT calculations can be simplified this way.
shoaib_ahmed 0:791a779d6220 99 */
shoaib_ahmed 0:791a779d6220 100
shoaib_ahmed 0:791a779d6220 101 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
shoaib_ahmed 0:791a779d6220 102 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
shoaib_ahmed 0:791a779d6220 103 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
shoaib_ahmed 0:791a779d6220 104 inptr[DCTSIZE*7] == 0) {
shoaib_ahmed 0:791a779d6220 105 /* AC terms all zero */
shoaib_ahmed 0:791a779d6220 106 FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
shoaib_ahmed 0:791a779d6220 107
shoaib_ahmed 0:791a779d6220 108 wsptr[DCTSIZE*0] = dcval;
shoaib_ahmed 0:791a779d6220 109 wsptr[DCTSIZE*1] = dcval;
shoaib_ahmed 0:791a779d6220 110 wsptr[DCTSIZE*2] = dcval;
shoaib_ahmed 0:791a779d6220 111 wsptr[DCTSIZE*3] = dcval;
shoaib_ahmed 0:791a779d6220 112 wsptr[DCTSIZE*4] = dcval;
shoaib_ahmed 0:791a779d6220 113 wsptr[DCTSIZE*5] = dcval;
shoaib_ahmed 0:791a779d6220 114 wsptr[DCTSIZE*6] = dcval;
shoaib_ahmed 0:791a779d6220 115 wsptr[DCTSIZE*7] = dcval;
shoaib_ahmed 0:791a779d6220 116
shoaib_ahmed 0:791a779d6220 117 inptr++; /* advance pointers to next column */
shoaib_ahmed 0:791a779d6220 118 quantptr++;
shoaib_ahmed 0:791a779d6220 119 wsptr++;
shoaib_ahmed 0:791a779d6220 120 continue;
shoaib_ahmed 0:791a779d6220 121 }
shoaib_ahmed 0:791a779d6220 122
shoaib_ahmed 0:791a779d6220 123 /* Even part */
shoaib_ahmed 0:791a779d6220 124
shoaib_ahmed 0:791a779d6220 125 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
shoaib_ahmed 0:791a779d6220 126 tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
shoaib_ahmed 0:791a779d6220 127 tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
shoaib_ahmed 0:791a779d6220 128 tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
shoaib_ahmed 0:791a779d6220 129
shoaib_ahmed 0:791a779d6220 130 tmp10 = tmp0 + tmp2; /* phase 3 */
shoaib_ahmed 0:791a779d6220 131 tmp11 = tmp0 - tmp2;
shoaib_ahmed 0:791a779d6220 132
shoaib_ahmed 0:791a779d6220 133 tmp13 = tmp1 + tmp3; /* phases 5-3 */
shoaib_ahmed 0:791a779d6220 134 tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
shoaib_ahmed 0:791a779d6220 135
shoaib_ahmed 0:791a779d6220 136 tmp0 = tmp10 + tmp13; /* phase 2 */
shoaib_ahmed 0:791a779d6220 137 tmp3 = tmp10 - tmp13;
shoaib_ahmed 0:791a779d6220 138 tmp1 = tmp11 + tmp12;
shoaib_ahmed 0:791a779d6220 139 tmp2 = tmp11 - tmp12;
shoaib_ahmed 0:791a779d6220 140
shoaib_ahmed 0:791a779d6220 141 /* Odd part */
shoaib_ahmed 0:791a779d6220 142
shoaib_ahmed 0:791a779d6220 143 tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
shoaib_ahmed 0:791a779d6220 144 tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
shoaib_ahmed 0:791a779d6220 145 tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
shoaib_ahmed 0:791a779d6220 146 tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
shoaib_ahmed 0:791a779d6220 147
shoaib_ahmed 0:791a779d6220 148 z13 = tmp6 + tmp5; /* phase 6 */
shoaib_ahmed 0:791a779d6220 149 z10 = tmp6 - tmp5;
shoaib_ahmed 0:791a779d6220 150 z11 = tmp4 + tmp7;
shoaib_ahmed 0:791a779d6220 151 z12 = tmp4 - tmp7;
shoaib_ahmed 0:791a779d6220 152
shoaib_ahmed 0:791a779d6220 153 tmp7 = z11 + z13; /* phase 5 */
shoaib_ahmed 0:791a779d6220 154 tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
shoaib_ahmed 0:791a779d6220 155
shoaib_ahmed 0:791a779d6220 156 z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
shoaib_ahmed 0:791a779d6220 157 tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
shoaib_ahmed 0:791a779d6220 158 tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
shoaib_ahmed 0:791a779d6220 159
shoaib_ahmed 0:791a779d6220 160 tmp6 = tmp12 - tmp7; /* phase 2 */
shoaib_ahmed 0:791a779d6220 161 tmp5 = tmp11 - tmp6;
shoaib_ahmed 0:791a779d6220 162 tmp4 = tmp10 - tmp5;
shoaib_ahmed 0:791a779d6220 163
shoaib_ahmed 0:791a779d6220 164 wsptr[DCTSIZE*0] = tmp0 + tmp7;
shoaib_ahmed 0:791a779d6220 165 wsptr[DCTSIZE*7] = tmp0 - tmp7;
shoaib_ahmed 0:791a779d6220 166 wsptr[DCTSIZE*1] = tmp1 + tmp6;
shoaib_ahmed 0:791a779d6220 167 wsptr[DCTSIZE*6] = tmp1 - tmp6;
shoaib_ahmed 0:791a779d6220 168 wsptr[DCTSIZE*2] = tmp2 + tmp5;
shoaib_ahmed 0:791a779d6220 169 wsptr[DCTSIZE*5] = tmp2 - tmp5;
shoaib_ahmed 0:791a779d6220 170 wsptr[DCTSIZE*3] = tmp3 + tmp4;
shoaib_ahmed 0:791a779d6220 171 wsptr[DCTSIZE*4] = tmp3 - tmp4;
shoaib_ahmed 0:791a779d6220 172
shoaib_ahmed 0:791a779d6220 173 inptr++; /* advance pointers to next column */
shoaib_ahmed 0:791a779d6220 174 quantptr++;
shoaib_ahmed 0:791a779d6220 175 wsptr++;
shoaib_ahmed 0:791a779d6220 176 }
shoaib_ahmed 0:791a779d6220 177
shoaib_ahmed 0:791a779d6220 178 /* Pass 2: process rows from work array, store into output array. */
shoaib_ahmed 0:791a779d6220 179
shoaib_ahmed 0:791a779d6220 180 wsptr = workspace;
shoaib_ahmed 0:791a779d6220 181 for (ctr = 0; ctr < DCTSIZE; ctr++) {
shoaib_ahmed 0:791a779d6220 182 outptr = output_buf[ctr] + output_col;
shoaib_ahmed 0:791a779d6220 183 /* Rows of zeroes can be exploited in the same way as we did with columns.
shoaib_ahmed 0:791a779d6220 184 * However, the column calculation has created many nonzero AC terms, so
shoaib_ahmed 0:791a779d6220 185 * the simplification applies less often (typically 5% to 10% of the time).
shoaib_ahmed 0:791a779d6220 186 * And testing floats for zero is relatively expensive, so we don't bother.
shoaib_ahmed 0:791a779d6220 187 */
shoaib_ahmed 0:791a779d6220 188
shoaib_ahmed 0:791a779d6220 189 /* Even part */
shoaib_ahmed 0:791a779d6220 190
shoaib_ahmed 0:791a779d6220 191 /* Prepare range-limit and float->int conversion */
shoaib_ahmed 0:791a779d6220 192 z5 = wsptr[0] + (((FAST_FLOAT) RANGE_CENTER) + ((FAST_FLOAT) 0.5));
shoaib_ahmed 0:791a779d6220 193 tmp10 = z5 + wsptr[4];
shoaib_ahmed 0:791a779d6220 194 tmp11 = z5 - wsptr[4];
shoaib_ahmed 0:791a779d6220 195
shoaib_ahmed 0:791a779d6220 196 tmp13 = wsptr[2] + wsptr[6];
shoaib_ahmed 0:791a779d6220 197 tmp12 = (wsptr[2] - wsptr[6]) *
shoaib_ahmed 0:791a779d6220 198 ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
shoaib_ahmed 0:791a779d6220 199
shoaib_ahmed 0:791a779d6220 200 tmp0 = tmp10 + tmp13;
shoaib_ahmed 0:791a779d6220 201 tmp3 = tmp10 - tmp13;
shoaib_ahmed 0:791a779d6220 202 tmp1 = tmp11 + tmp12;
shoaib_ahmed 0:791a779d6220 203 tmp2 = tmp11 - tmp12;
shoaib_ahmed 0:791a779d6220 204
shoaib_ahmed 0:791a779d6220 205 /* Odd part */
shoaib_ahmed 0:791a779d6220 206
shoaib_ahmed 0:791a779d6220 207 z13 = wsptr[5] + wsptr[3];
shoaib_ahmed 0:791a779d6220 208 z10 = wsptr[5] - wsptr[3];
shoaib_ahmed 0:791a779d6220 209 z11 = wsptr[1] + wsptr[7];
shoaib_ahmed 0:791a779d6220 210 z12 = wsptr[1] - wsptr[7];
shoaib_ahmed 0:791a779d6220 211
shoaib_ahmed 0:791a779d6220 212 tmp7 = z11 + z13; /* phase 5 */
shoaib_ahmed 0:791a779d6220 213 tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
shoaib_ahmed 0:791a779d6220 214
shoaib_ahmed 0:791a779d6220 215 z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
shoaib_ahmed 0:791a779d6220 216 tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
shoaib_ahmed 0:791a779d6220 217 tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
shoaib_ahmed 0:791a779d6220 218
shoaib_ahmed 0:791a779d6220 219 tmp6 = tmp12 - tmp7; /* phase 2 */
shoaib_ahmed 0:791a779d6220 220 tmp5 = tmp11 - tmp6;
shoaib_ahmed 0:791a779d6220 221 tmp4 = tmp10 - tmp5;
shoaib_ahmed 0:791a779d6220 222
shoaib_ahmed 0:791a779d6220 223 /* Final output stage: float->int conversion and range-limit */
shoaib_ahmed 0:791a779d6220 224
shoaib_ahmed 0:791a779d6220 225 outptr[0] = range_limit[(int) (tmp0 + tmp7) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 226 outptr[7] = range_limit[(int) (tmp0 - tmp7) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 227 outptr[1] = range_limit[(int) (tmp1 + tmp6) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 228 outptr[6] = range_limit[(int) (tmp1 - tmp6) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 229 outptr[2] = range_limit[(int) (tmp2 + tmp5) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 230 outptr[5] = range_limit[(int) (tmp2 - tmp5) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 231 outptr[3] = range_limit[(int) (tmp3 + tmp4) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 232 outptr[4] = range_limit[(int) (tmp3 - tmp4) & RANGE_MASK];
shoaib_ahmed 0:791a779d6220 233
shoaib_ahmed 0:791a779d6220 234 wsptr += DCTSIZE; /* advance pointer to next row */
shoaib_ahmed 0:791a779d6220 235 }
shoaib_ahmed 0:791a779d6220 236 }
shoaib_ahmed 0:791a779d6220 237
shoaib_ahmed 0:791a779d6220 238 #endif /* DCT_FLOAT_SUPPORTED */