Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/jcdctmgr.c@0:791a779d6220, 2017-07-31 (annotated)
- Committer:
- shoaib_ahmed
- Date:
- Mon Jul 31 09:16:35 2017 +0000
- Revision:
- 0:791a779d6220
final project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shoaib_ahmed | 0:791a779d6220 | 1 | /* |
shoaib_ahmed | 0:791a779d6220 | 2 | * jcdctmgr.c |
shoaib_ahmed | 0:791a779d6220 | 3 | * |
shoaib_ahmed | 0:791a779d6220 | 4 | * Copyright (C) 1994-1996, Thomas G. Lane. |
shoaib_ahmed | 0:791a779d6220 | 5 | * Modified 2003-2013 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 the forward-DCT management logic. |
shoaib_ahmed | 0:791a779d6220 | 10 | * This code selects a particular DCT implementation to be used, |
shoaib_ahmed | 0:791a779d6220 | 11 | * and it performs related housekeeping chores including coefficient |
shoaib_ahmed | 0:791a779d6220 | 12 | * quantization. |
shoaib_ahmed | 0:791a779d6220 | 13 | */ |
shoaib_ahmed | 0:791a779d6220 | 14 | |
shoaib_ahmed | 0:791a779d6220 | 15 | #define JPEG_INTERNALS |
shoaib_ahmed | 0:791a779d6220 | 16 | #include "jinclude.h" |
shoaib_ahmed | 0:791a779d6220 | 17 | #include "jpeglib.h" |
shoaib_ahmed | 0:791a779d6220 | 18 | #include "jdct.h" /* Private declarations for DCT subsystem */ |
shoaib_ahmed | 0:791a779d6220 | 19 | |
shoaib_ahmed | 0:791a779d6220 | 20 | |
shoaib_ahmed | 0:791a779d6220 | 21 | /* Private subobject for this module */ |
shoaib_ahmed | 0:791a779d6220 | 22 | |
shoaib_ahmed | 0:791a779d6220 | 23 | typedef struct { |
shoaib_ahmed | 0:791a779d6220 | 24 | struct jpeg_forward_dct pub; /* public fields */ |
shoaib_ahmed | 0:791a779d6220 | 25 | |
shoaib_ahmed | 0:791a779d6220 | 26 | /* Pointer to the DCT routine actually in use */ |
shoaib_ahmed | 0:791a779d6220 | 27 | forward_DCT_method_ptr do_dct[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 28 | |
shoaib_ahmed | 0:791a779d6220 | 29 | #ifdef DCT_FLOAT_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 30 | /* Same as above for the floating-point case. */ |
shoaib_ahmed | 0:791a779d6220 | 31 | float_DCT_method_ptr do_float_dct[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 32 | #endif |
shoaib_ahmed | 0:791a779d6220 | 33 | } my_fdct_controller; |
shoaib_ahmed | 0:791a779d6220 | 34 | |
shoaib_ahmed | 0:791a779d6220 | 35 | typedef my_fdct_controller * my_fdct_ptr; |
shoaib_ahmed | 0:791a779d6220 | 36 | |
shoaib_ahmed | 0:791a779d6220 | 37 | |
shoaib_ahmed | 0:791a779d6220 | 38 | /* The allocated post-DCT divisor tables -- big enough for any |
shoaib_ahmed | 0:791a779d6220 | 39 | * supported variant and not identical to the quant table entries, |
shoaib_ahmed | 0:791a779d6220 | 40 | * because of scaling (especially for an unnormalized DCT) -- |
shoaib_ahmed | 0:791a779d6220 | 41 | * are pointed to by dct_table in the per-component comp_info |
shoaib_ahmed | 0:791a779d6220 | 42 | * structures. Each table is given in normal array order. |
shoaib_ahmed | 0:791a779d6220 | 43 | */ |
shoaib_ahmed | 0:791a779d6220 | 44 | |
shoaib_ahmed | 0:791a779d6220 | 45 | typedef union { |
shoaib_ahmed | 0:791a779d6220 | 46 | DCTELEM int_array[DCTSIZE2]; |
shoaib_ahmed | 0:791a779d6220 | 47 | #ifdef DCT_FLOAT_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 48 | FAST_FLOAT float_array[DCTSIZE2]; |
shoaib_ahmed | 0:791a779d6220 | 49 | #endif |
shoaib_ahmed | 0:791a779d6220 | 50 | } divisor_table; |
shoaib_ahmed | 0:791a779d6220 | 51 | |
shoaib_ahmed | 0:791a779d6220 | 52 | |
shoaib_ahmed | 0:791a779d6220 | 53 | /* The current scaled-DCT routines require ISLOW-style divisor tables, |
shoaib_ahmed | 0:791a779d6220 | 54 | * so be sure to compile that code if either ISLOW or SCALING is requested. |
shoaib_ahmed | 0:791a779d6220 | 55 | */ |
shoaib_ahmed | 0:791a779d6220 | 56 | #ifdef DCT_ISLOW_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 57 | #define PROVIDE_ISLOW_TABLES |
shoaib_ahmed | 0:791a779d6220 | 58 | #else |
shoaib_ahmed | 0:791a779d6220 | 59 | #ifdef DCT_SCALING_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 60 | #define PROVIDE_ISLOW_TABLES |
shoaib_ahmed | 0:791a779d6220 | 61 | #endif |
shoaib_ahmed | 0:791a779d6220 | 62 | #endif |
shoaib_ahmed | 0:791a779d6220 | 63 | |
shoaib_ahmed | 0:791a779d6220 | 64 | |
shoaib_ahmed | 0:791a779d6220 | 65 | /* |
shoaib_ahmed | 0:791a779d6220 | 66 | * Perform forward DCT on one or more blocks of a component. |
shoaib_ahmed | 0:791a779d6220 | 67 | * |
shoaib_ahmed | 0:791a779d6220 | 68 | * The input samples are taken from the sample_data[] array starting at |
shoaib_ahmed | 0:791a779d6220 | 69 | * position start_row/start_col, and moving to the right for any additional |
shoaib_ahmed | 0:791a779d6220 | 70 | * blocks. The quantized coefficients are returned in coef_blocks[]. |
shoaib_ahmed | 0:791a779d6220 | 71 | */ |
shoaib_ahmed | 0:791a779d6220 | 72 | |
shoaib_ahmed | 0:791a779d6220 | 73 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 74 | forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 75 | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
shoaib_ahmed | 0:791a779d6220 | 76 | JDIMENSION start_row, JDIMENSION start_col, |
shoaib_ahmed | 0:791a779d6220 | 77 | JDIMENSION num_blocks) |
shoaib_ahmed | 0:791a779d6220 | 78 | /* This version is used for integer DCT implementations. */ |
shoaib_ahmed | 0:791a779d6220 | 79 | { |
shoaib_ahmed | 0:791a779d6220 | 80 | /* This routine is heavily used, so it's worth coding it tightly. */ |
shoaib_ahmed | 0:791a779d6220 | 81 | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
shoaib_ahmed | 0:791a779d6220 | 82 | forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index]; |
shoaib_ahmed | 0:791a779d6220 | 83 | DCTELEM * divisors = (DCTELEM *) compptr->dct_table; |
shoaib_ahmed | 0:791a779d6220 | 84 | DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */ |
shoaib_ahmed | 0:791a779d6220 | 85 | JDIMENSION bi; |
shoaib_ahmed | 0:791a779d6220 | 86 | |
shoaib_ahmed | 0:791a779d6220 | 87 | sample_data += start_row; /* fold in the vertical offset once */ |
shoaib_ahmed | 0:791a779d6220 | 88 | |
shoaib_ahmed | 0:791a779d6220 | 89 | for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) { |
shoaib_ahmed | 0:791a779d6220 | 90 | /* Perform the DCT */ |
shoaib_ahmed | 0:791a779d6220 | 91 | (*do_dct) (workspace, sample_data, start_col); |
shoaib_ahmed | 0:791a779d6220 | 92 | |
shoaib_ahmed | 0:791a779d6220 | 93 | /* Quantize/descale the coefficients, and store into coef_blocks[] */ |
shoaib_ahmed | 0:791a779d6220 | 94 | { register DCTELEM temp, qval; |
shoaib_ahmed | 0:791a779d6220 | 95 | register int i; |
shoaib_ahmed | 0:791a779d6220 | 96 | register JCOEFPTR output_ptr = coef_blocks[bi]; |
shoaib_ahmed | 0:791a779d6220 | 97 | |
shoaib_ahmed | 0:791a779d6220 | 98 | for (i = 0; i < DCTSIZE2; i++) { |
shoaib_ahmed | 0:791a779d6220 | 99 | qval = divisors[i]; |
shoaib_ahmed | 0:791a779d6220 | 100 | temp = workspace[i]; |
shoaib_ahmed | 0:791a779d6220 | 101 | /* Divide the coefficient value by qval, ensuring proper rounding. |
shoaib_ahmed | 0:791a779d6220 | 102 | * Since C does not specify the direction of rounding for negative |
shoaib_ahmed | 0:791a779d6220 | 103 | * quotients, we have to force the dividend positive for portability. |
shoaib_ahmed | 0:791a779d6220 | 104 | * |
shoaib_ahmed | 0:791a779d6220 | 105 | * In most files, at least half of the output values will be zero |
shoaib_ahmed | 0:791a779d6220 | 106 | * (at default quantization settings, more like three-quarters...) |
shoaib_ahmed | 0:791a779d6220 | 107 | * so we should ensure that this case is fast. On many machines, |
shoaib_ahmed | 0:791a779d6220 | 108 | * a comparison is enough cheaper than a divide to make a special test |
shoaib_ahmed | 0:791a779d6220 | 109 | * a win. Since both inputs will be nonnegative, we need only test |
shoaib_ahmed | 0:791a779d6220 | 110 | * for a < b to discover whether a/b is 0. |
shoaib_ahmed | 0:791a779d6220 | 111 | * If your machine's division is fast enough, define FAST_DIVIDE. |
shoaib_ahmed | 0:791a779d6220 | 112 | */ |
shoaib_ahmed | 0:791a779d6220 | 113 | #ifdef FAST_DIVIDE |
shoaib_ahmed | 0:791a779d6220 | 114 | #define DIVIDE_BY(a,b) a /= b |
shoaib_ahmed | 0:791a779d6220 | 115 | #else |
shoaib_ahmed | 0:791a779d6220 | 116 | #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0 |
shoaib_ahmed | 0:791a779d6220 | 117 | #endif |
shoaib_ahmed | 0:791a779d6220 | 118 | if (temp < 0) { |
shoaib_ahmed | 0:791a779d6220 | 119 | temp = -temp; |
shoaib_ahmed | 0:791a779d6220 | 120 | temp += qval>>1; /* for rounding */ |
shoaib_ahmed | 0:791a779d6220 | 121 | DIVIDE_BY(temp, qval); |
shoaib_ahmed | 0:791a779d6220 | 122 | temp = -temp; |
shoaib_ahmed | 0:791a779d6220 | 123 | } else { |
shoaib_ahmed | 0:791a779d6220 | 124 | temp += qval>>1; /* for rounding */ |
shoaib_ahmed | 0:791a779d6220 | 125 | DIVIDE_BY(temp, qval); |
shoaib_ahmed | 0:791a779d6220 | 126 | } |
shoaib_ahmed | 0:791a779d6220 | 127 | output_ptr[i] = (JCOEF) temp; |
shoaib_ahmed | 0:791a779d6220 | 128 | } |
shoaib_ahmed | 0:791a779d6220 | 129 | } |
shoaib_ahmed | 0:791a779d6220 | 130 | } |
shoaib_ahmed | 0:791a779d6220 | 131 | } |
shoaib_ahmed | 0:791a779d6220 | 132 | |
shoaib_ahmed | 0:791a779d6220 | 133 | |
shoaib_ahmed | 0:791a779d6220 | 134 | #ifdef DCT_FLOAT_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 135 | |
shoaib_ahmed | 0:791a779d6220 | 136 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 137 | forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 138 | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
shoaib_ahmed | 0:791a779d6220 | 139 | JDIMENSION start_row, JDIMENSION start_col, |
shoaib_ahmed | 0:791a779d6220 | 140 | JDIMENSION num_blocks) |
shoaib_ahmed | 0:791a779d6220 | 141 | /* This version is used for floating-point DCT implementations. */ |
shoaib_ahmed | 0:791a779d6220 | 142 | { |
shoaib_ahmed | 0:791a779d6220 | 143 | /* This routine is heavily used, so it's worth coding it tightly. */ |
shoaib_ahmed | 0:791a779d6220 | 144 | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
shoaib_ahmed | 0:791a779d6220 | 145 | float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index]; |
shoaib_ahmed | 0:791a779d6220 | 146 | FAST_FLOAT * divisors = (FAST_FLOAT *) compptr->dct_table; |
shoaib_ahmed | 0:791a779d6220 | 147 | FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */ |
shoaib_ahmed | 0:791a779d6220 | 148 | JDIMENSION bi; |
shoaib_ahmed | 0:791a779d6220 | 149 | |
shoaib_ahmed | 0:791a779d6220 | 150 | sample_data += start_row; /* fold in the vertical offset once */ |
shoaib_ahmed | 0:791a779d6220 | 151 | |
shoaib_ahmed | 0:791a779d6220 | 152 | for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) { |
shoaib_ahmed | 0:791a779d6220 | 153 | /* Perform the DCT */ |
shoaib_ahmed | 0:791a779d6220 | 154 | (*do_dct) (workspace, sample_data, start_col); |
shoaib_ahmed | 0:791a779d6220 | 155 | |
shoaib_ahmed | 0:791a779d6220 | 156 | /* Quantize/descale the coefficients, and store into coef_blocks[] */ |
shoaib_ahmed | 0:791a779d6220 | 157 | { register FAST_FLOAT temp; |
shoaib_ahmed | 0:791a779d6220 | 158 | register int i; |
shoaib_ahmed | 0:791a779d6220 | 159 | register JCOEFPTR output_ptr = coef_blocks[bi]; |
shoaib_ahmed | 0:791a779d6220 | 160 | |
shoaib_ahmed | 0:791a779d6220 | 161 | for (i = 0; i < DCTSIZE2; i++) { |
shoaib_ahmed | 0:791a779d6220 | 162 | /* Apply the quantization and scaling factor */ |
shoaib_ahmed | 0:791a779d6220 | 163 | temp = workspace[i] * divisors[i]; |
shoaib_ahmed | 0:791a779d6220 | 164 | /* Round to nearest integer. |
shoaib_ahmed | 0:791a779d6220 | 165 | * Since C does not specify the direction of rounding for negative |
shoaib_ahmed | 0:791a779d6220 | 166 | * quotients, we have to force the dividend positive for portability. |
shoaib_ahmed | 0:791a779d6220 | 167 | * The maximum coefficient size is +-16K (for 12-bit data), so this |
shoaib_ahmed | 0:791a779d6220 | 168 | * code should work for either 16-bit or 32-bit ints. |
shoaib_ahmed | 0:791a779d6220 | 169 | */ |
shoaib_ahmed | 0:791a779d6220 | 170 | output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384); |
shoaib_ahmed | 0:791a779d6220 | 171 | } |
shoaib_ahmed | 0:791a779d6220 | 172 | } |
shoaib_ahmed | 0:791a779d6220 | 173 | } |
shoaib_ahmed | 0:791a779d6220 | 174 | } |
shoaib_ahmed | 0:791a779d6220 | 175 | |
shoaib_ahmed | 0:791a779d6220 | 176 | #endif /* DCT_FLOAT_SUPPORTED */ |
shoaib_ahmed | 0:791a779d6220 | 177 | |
shoaib_ahmed | 0:791a779d6220 | 178 | |
shoaib_ahmed | 0:791a779d6220 | 179 | /* |
shoaib_ahmed | 0:791a779d6220 | 180 | * Initialize for a processing pass. |
shoaib_ahmed | 0:791a779d6220 | 181 | * Verify that all referenced Q-tables are present, and set up |
shoaib_ahmed | 0:791a779d6220 | 182 | * the divisor table for each one. |
shoaib_ahmed | 0:791a779d6220 | 183 | * In the current implementation, DCT of all components is done during |
shoaib_ahmed | 0:791a779d6220 | 184 | * the first pass, even if only some components will be output in the |
shoaib_ahmed | 0:791a779d6220 | 185 | * first scan. Hence all components should be examined here. |
shoaib_ahmed | 0:791a779d6220 | 186 | */ |
shoaib_ahmed | 0:791a779d6220 | 187 | |
shoaib_ahmed | 0:791a779d6220 | 188 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 189 | start_pass_fdctmgr (j_compress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 190 | { |
shoaib_ahmed | 0:791a779d6220 | 191 | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
shoaib_ahmed | 0:791a779d6220 | 192 | int ci, qtblno, i; |
shoaib_ahmed | 0:791a779d6220 | 193 | jpeg_component_info *compptr; |
shoaib_ahmed | 0:791a779d6220 | 194 | int method = 0; |
shoaib_ahmed | 0:791a779d6220 | 195 | JQUANT_TBL * qtbl; |
shoaib_ahmed | 0:791a779d6220 | 196 | DCTELEM * dtbl; |
shoaib_ahmed | 0:791a779d6220 | 197 | |
shoaib_ahmed | 0:791a779d6220 | 198 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
shoaib_ahmed | 0:791a779d6220 | 199 | ci++, compptr++) { |
shoaib_ahmed | 0:791a779d6220 | 200 | /* Select the proper DCT routine for this component's scaling */ |
shoaib_ahmed | 0:791a779d6220 | 201 | switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) { |
shoaib_ahmed | 0:791a779d6220 | 202 | #ifdef DCT_SCALING_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 203 | case ((1 << 8) + 1): |
shoaib_ahmed | 0:791a779d6220 | 204 | fdct->do_dct[ci] = jpeg_fdct_1x1; |
shoaib_ahmed | 0:791a779d6220 | 205 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 206 | break; |
shoaib_ahmed | 0:791a779d6220 | 207 | case ((2 << 8) + 2): |
shoaib_ahmed | 0:791a779d6220 | 208 | fdct->do_dct[ci] = jpeg_fdct_2x2; |
shoaib_ahmed | 0:791a779d6220 | 209 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 210 | break; |
shoaib_ahmed | 0:791a779d6220 | 211 | case ((3 << 8) + 3): |
shoaib_ahmed | 0:791a779d6220 | 212 | fdct->do_dct[ci] = jpeg_fdct_3x3; |
shoaib_ahmed | 0:791a779d6220 | 213 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 214 | break; |
shoaib_ahmed | 0:791a779d6220 | 215 | case ((4 << 8) + 4): |
shoaib_ahmed | 0:791a779d6220 | 216 | fdct->do_dct[ci] = jpeg_fdct_4x4; |
shoaib_ahmed | 0:791a779d6220 | 217 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 218 | break; |
shoaib_ahmed | 0:791a779d6220 | 219 | case ((5 << 8) + 5): |
shoaib_ahmed | 0:791a779d6220 | 220 | fdct->do_dct[ci] = jpeg_fdct_5x5; |
shoaib_ahmed | 0:791a779d6220 | 221 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 222 | break; |
shoaib_ahmed | 0:791a779d6220 | 223 | case ((6 << 8) + 6): |
shoaib_ahmed | 0:791a779d6220 | 224 | fdct->do_dct[ci] = jpeg_fdct_6x6; |
shoaib_ahmed | 0:791a779d6220 | 225 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 226 | break; |
shoaib_ahmed | 0:791a779d6220 | 227 | case ((7 << 8) + 7): |
shoaib_ahmed | 0:791a779d6220 | 228 | fdct->do_dct[ci] = jpeg_fdct_7x7; |
shoaib_ahmed | 0:791a779d6220 | 229 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 230 | break; |
shoaib_ahmed | 0:791a779d6220 | 231 | case ((9 << 8) + 9): |
shoaib_ahmed | 0:791a779d6220 | 232 | fdct->do_dct[ci] = jpeg_fdct_9x9; |
shoaib_ahmed | 0:791a779d6220 | 233 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 234 | break; |
shoaib_ahmed | 0:791a779d6220 | 235 | case ((10 << 8) + 10): |
shoaib_ahmed | 0:791a779d6220 | 236 | fdct->do_dct[ci] = jpeg_fdct_10x10; |
shoaib_ahmed | 0:791a779d6220 | 237 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 238 | break; |
shoaib_ahmed | 0:791a779d6220 | 239 | case ((11 << 8) + 11): |
shoaib_ahmed | 0:791a779d6220 | 240 | fdct->do_dct[ci] = jpeg_fdct_11x11; |
shoaib_ahmed | 0:791a779d6220 | 241 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 242 | break; |
shoaib_ahmed | 0:791a779d6220 | 243 | case ((12 << 8) + 12): |
shoaib_ahmed | 0:791a779d6220 | 244 | fdct->do_dct[ci] = jpeg_fdct_12x12; |
shoaib_ahmed | 0:791a779d6220 | 245 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 246 | break; |
shoaib_ahmed | 0:791a779d6220 | 247 | case ((13 << 8) + 13): |
shoaib_ahmed | 0:791a779d6220 | 248 | fdct->do_dct[ci] = jpeg_fdct_13x13; |
shoaib_ahmed | 0:791a779d6220 | 249 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 250 | break; |
shoaib_ahmed | 0:791a779d6220 | 251 | case ((14 << 8) + 14): |
shoaib_ahmed | 0:791a779d6220 | 252 | fdct->do_dct[ci] = jpeg_fdct_14x14; |
shoaib_ahmed | 0:791a779d6220 | 253 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 254 | break; |
shoaib_ahmed | 0:791a779d6220 | 255 | case ((15 << 8) + 15): |
shoaib_ahmed | 0:791a779d6220 | 256 | fdct->do_dct[ci] = jpeg_fdct_15x15; |
shoaib_ahmed | 0:791a779d6220 | 257 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 258 | break; |
shoaib_ahmed | 0:791a779d6220 | 259 | case ((16 << 8) + 16): |
shoaib_ahmed | 0:791a779d6220 | 260 | fdct->do_dct[ci] = jpeg_fdct_16x16; |
shoaib_ahmed | 0:791a779d6220 | 261 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 262 | break; |
shoaib_ahmed | 0:791a779d6220 | 263 | case ((16 << 8) + 8): |
shoaib_ahmed | 0:791a779d6220 | 264 | fdct->do_dct[ci] = jpeg_fdct_16x8; |
shoaib_ahmed | 0:791a779d6220 | 265 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 266 | break; |
shoaib_ahmed | 0:791a779d6220 | 267 | case ((14 << 8) + 7): |
shoaib_ahmed | 0:791a779d6220 | 268 | fdct->do_dct[ci] = jpeg_fdct_14x7; |
shoaib_ahmed | 0:791a779d6220 | 269 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 270 | break; |
shoaib_ahmed | 0:791a779d6220 | 271 | case ((12 << 8) + 6): |
shoaib_ahmed | 0:791a779d6220 | 272 | fdct->do_dct[ci] = jpeg_fdct_12x6; |
shoaib_ahmed | 0:791a779d6220 | 273 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 274 | break; |
shoaib_ahmed | 0:791a779d6220 | 275 | case ((10 << 8) + 5): |
shoaib_ahmed | 0:791a779d6220 | 276 | fdct->do_dct[ci] = jpeg_fdct_10x5; |
shoaib_ahmed | 0:791a779d6220 | 277 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 278 | break; |
shoaib_ahmed | 0:791a779d6220 | 279 | case ((8 << 8) + 4): |
shoaib_ahmed | 0:791a779d6220 | 280 | fdct->do_dct[ci] = jpeg_fdct_8x4; |
shoaib_ahmed | 0:791a779d6220 | 281 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 282 | break; |
shoaib_ahmed | 0:791a779d6220 | 283 | case ((6 << 8) + 3): |
shoaib_ahmed | 0:791a779d6220 | 284 | fdct->do_dct[ci] = jpeg_fdct_6x3; |
shoaib_ahmed | 0:791a779d6220 | 285 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 286 | break; |
shoaib_ahmed | 0:791a779d6220 | 287 | case ((4 << 8) + 2): |
shoaib_ahmed | 0:791a779d6220 | 288 | fdct->do_dct[ci] = jpeg_fdct_4x2; |
shoaib_ahmed | 0:791a779d6220 | 289 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 290 | break; |
shoaib_ahmed | 0:791a779d6220 | 291 | case ((2 << 8) + 1): |
shoaib_ahmed | 0:791a779d6220 | 292 | fdct->do_dct[ci] = jpeg_fdct_2x1; |
shoaib_ahmed | 0:791a779d6220 | 293 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 294 | break; |
shoaib_ahmed | 0:791a779d6220 | 295 | case ((8 << 8) + 16): |
shoaib_ahmed | 0:791a779d6220 | 296 | fdct->do_dct[ci] = jpeg_fdct_8x16; |
shoaib_ahmed | 0:791a779d6220 | 297 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 298 | break; |
shoaib_ahmed | 0:791a779d6220 | 299 | case ((7 << 8) + 14): |
shoaib_ahmed | 0:791a779d6220 | 300 | fdct->do_dct[ci] = jpeg_fdct_7x14; |
shoaib_ahmed | 0:791a779d6220 | 301 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 302 | break; |
shoaib_ahmed | 0:791a779d6220 | 303 | case ((6 << 8) + 12): |
shoaib_ahmed | 0:791a779d6220 | 304 | fdct->do_dct[ci] = jpeg_fdct_6x12; |
shoaib_ahmed | 0:791a779d6220 | 305 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 306 | break; |
shoaib_ahmed | 0:791a779d6220 | 307 | case ((5 << 8) + 10): |
shoaib_ahmed | 0:791a779d6220 | 308 | fdct->do_dct[ci] = jpeg_fdct_5x10; |
shoaib_ahmed | 0:791a779d6220 | 309 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 310 | break; |
shoaib_ahmed | 0:791a779d6220 | 311 | case ((4 << 8) + 8): |
shoaib_ahmed | 0:791a779d6220 | 312 | fdct->do_dct[ci] = jpeg_fdct_4x8; |
shoaib_ahmed | 0:791a779d6220 | 313 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 314 | break; |
shoaib_ahmed | 0:791a779d6220 | 315 | case ((3 << 8) + 6): |
shoaib_ahmed | 0:791a779d6220 | 316 | fdct->do_dct[ci] = jpeg_fdct_3x6; |
shoaib_ahmed | 0:791a779d6220 | 317 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 318 | break; |
shoaib_ahmed | 0:791a779d6220 | 319 | case ((2 << 8) + 4): |
shoaib_ahmed | 0:791a779d6220 | 320 | fdct->do_dct[ci] = jpeg_fdct_2x4; |
shoaib_ahmed | 0:791a779d6220 | 321 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 322 | break; |
shoaib_ahmed | 0:791a779d6220 | 323 | case ((1 << 8) + 2): |
shoaib_ahmed | 0:791a779d6220 | 324 | fdct->do_dct[ci] = jpeg_fdct_1x2; |
shoaib_ahmed | 0:791a779d6220 | 325 | method = JDCT_ISLOW; /* jfdctint uses islow-style table */ |
shoaib_ahmed | 0:791a779d6220 | 326 | break; |
shoaib_ahmed | 0:791a779d6220 | 327 | #endif |
shoaib_ahmed | 0:791a779d6220 | 328 | case ((DCTSIZE << 8) + DCTSIZE): |
shoaib_ahmed | 0:791a779d6220 | 329 | switch (cinfo->dct_method) { |
shoaib_ahmed | 0:791a779d6220 | 330 | #ifdef DCT_ISLOW_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 331 | case JDCT_ISLOW: |
shoaib_ahmed | 0:791a779d6220 | 332 | fdct->do_dct[ci] = jpeg_fdct_islow; |
shoaib_ahmed | 0:791a779d6220 | 333 | method = JDCT_ISLOW; |
shoaib_ahmed | 0:791a779d6220 | 334 | break; |
shoaib_ahmed | 0:791a779d6220 | 335 | #endif |
shoaib_ahmed | 0:791a779d6220 | 336 | #ifdef DCT_IFAST_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 337 | case JDCT_IFAST: |
shoaib_ahmed | 0:791a779d6220 | 338 | fdct->do_dct[ci] = jpeg_fdct_ifast; |
shoaib_ahmed | 0:791a779d6220 | 339 | method = JDCT_IFAST; |
shoaib_ahmed | 0:791a779d6220 | 340 | break; |
shoaib_ahmed | 0:791a779d6220 | 341 | #endif |
shoaib_ahmed | 0:791a779d6220 | 342 | #ifdef DCT_FLOAT_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 343 | case JDCT_FLOAT: |
shoaib_ahmed | 0:791a779d6220 | 344 | fdct->do_float_dct[ci] = jpeg_fdct_float; |
shoaib_ahmed | 0:791a779d6220 | 345 | method = JDCT_FLOAT; |
shoaib_ahmed | 0:791a779d6220 | 346 | break; |
shoaib_ahmed | 0:791a779d6220 | 347 | #endif |
shoaib_ahmed | 0:791a779d6220 | 348 | default: |
shoaib_ahmed | 0:791a779d6220 | 349 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
shoaib_ahmed | 0:791a779d6220 | 350 | break; |
shoaib_ahmed | 0:791a779d6220 | 351 | } |
shoaib_ahmed | 0:791a779d6220 | 352 | break; |
shoaib_ahmed | 0:791a779d6220 | 353 | default: |
shoaib_ahmed | 0:791a779d6220 | 354 | ERREXIT2(cinfo, JERR_BAD_DCTSIZE, |
shoaib_ahmed | 0:791a779d6220 | 355 | compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size); |
shoaib_ahmed | 0:791a779d6220 | 356 | break; |
shoaib_ahmed | 0:791a779d6220 | 357 | } |
shoaib_ahmed | 0:791a779d6220 | 358 | qtblno = compptr->quant_tbl_no; |
shoaib_ahmed | 0:791a779d6220 | 359 | /* Make sure specified quantization table is present */ |
shoaib_ahmed | 0:791a779d6220 | 360 | if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || |
shoaib_ahmed | 0:791a779d6220 | 361 | cinfo->quant_tbl_ptrs[qtblno] == NULL) |
shoaib_ahmed | 0:791a779d6220 | 362 | ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); |
shoaib_ahmed | 0:791a779d6220 | 363 | qtbl = cinfo->quant_tbl_ptrs[qtblno]; |
shoaib_ahmed | 0:791a779d6220 | 364 | /* Create divisor table from quant table */ |
shoaib_ahmed | 0:791a779d6220 | 365 | switch (method) { |
shoaib_ahmed | 0:791a779d6220 | 366 | #ifdef PROVIDE_ISLOW_TABLES |
shoaib_ahmed | 0:791a779d6220 | 367 | case JDCT_ISLOW: |
shoaib_ahmed | 0:791a779d6220 | 368 | /* For LL&M IDCT method, divisors are equal to raw quantization |
shoaib_ahmed | 0:791a779d6220 | 369 | * coefficients multiplied by 8 (to counteract scaling). |
shoaib_ahmed | 0:791a779d6220 | 370 | */ |
shoaib_ahmed | 0:791a779d6220 | 371 | dtbl = (DCTELEM *) compptr->dct_table; |
shoaib_ahmed | 0:791a779d6220 | 372 | for (i = 0; i < DCTSIZE2; i++) { |
shoaib_ahmed | 0:791a779d6220 | 373 | dtbl[i] = |
shoaib_ahmed | 0:791a779d6220 | 374 | ((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3); |
shoaib_ahmed | 0:791a779d6220 | 375 | } |
shoaib_ahmed | 0:791a779d6220 | 376 | fdct->pub.forward_DCT[ci] = forward_DCT; |
shoaib_ahmed | 0:791a779d6220 | 377 | break; |
shoaib_ahmed | 0:791a779d6220 | 378 | #endif |
shoaib_ahmed | 0:791a779d6220 | 379 | #ifdef DCT_IFAST_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 380 | case JDCT_IFAST: |
shoaib_ahmed | 0:791a779d6220 | 381 | { |
shoaib_ahmed | 0:791a779d6220 | 382 | /* For AA&N IDCT method, divisors are equal to quantization |
shoaib_ahmed | 0:791a779d6220 | 383 | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
shoaib_ahmed | 0:791a779d6220 | 384 | * scalefactor[0] = 1 |
shoaib_ahmed | 0:791a779d6220 | 385 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
shoaib_ahmed | 0:791a779d6220 | 386 | * We apply a further scale factor of 8. |
shoaib_ahmed | 0:791a779d6220 | 387 | */ |
shoaib_ahmed | 0:791a779d6220 | 388 | #define CONST_BITS 14 |
shoaib_ahmed | 0:791a779d6220 | 389 | static const INT16 aanscales[DCTSIZE2] = { |
shoaib_ahmed | 0:791a779d6220 | 390 | /* precomputed values scaled up by 14 bits */ |
shoaib_ahmed | 0:791a779d6220 | 391 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
shoaib_ahmed | 0:791a779d6220 | 392 | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
shoaib_ahmed | 0:791a779d6220 | 393 | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
shoaib_ahmed | 0:791a779d6220 | 394 | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
shoaib_ahmed | 0:791a779d6220 | 395 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
shoaib_ahmed | 0:791a779d6220 | 396 | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
shoaib_ahmed | 0:791a779d6220 | 397 | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
shoaib_ahmed | 0:791a779d6220 | 398 | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
shoaib_ahmed | 0:791a779d6220 | 399 | }; |
shoaib_ahmed | 0:791a779d6220 | 400 | SHIFT_TEMPS |
shoaib_ahmed | 0:791a779d6220 | 401 | |
shoaib_ahmed | 0:791a779d6220 | 402 | dtbl = (DCTELEM *) compptr->dct_table; |
shoaib_ahmed | 0:791a779d6220 | 403 | for (i = 0; i < DCTSIZE2; i++) { |
shoaib_ahmed | 0:791a779d6220 | 404 | dtbl[i] = (DCTELEM) |
shoaib_ahmed | 0:791a779d6220 | 405 | DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], |
shoaib_ahmed | 0:791a779d6220 | 406 | (INT32) aanscales[i]), |
shoaib_ahmed | 0:791a779d6220 | 407 | compptr->component_needed ? CONST_BITS-4 : CONST_BITS-3); |
shoaib_ahmed | 0:791a779d6220 | 408 | } |
shoaib_ahmed | 0:791a779d6220 | 409 | } |
shoaib_ahmed | 0:791a779d6220 | 410 | fdct->pub.forward_DCT[ci] = forward_DCT; |
shoaib_ahmed | 0:791a779d6220 | 411 | break; |
shoaib_ahmed | 0:791a779d6220 | 412 | #endif |
shoaib_ahmed | 0:791a779d6220 | 413 | #ifdef DCT_FLOAT_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 414 | case JDCT_FLOAT: |
shoaib_ahmed | 0:791a779d6220 | 415 | { |
shoaib_ahmed | 0:791a779d6220 | 416 | /* For float AA&N IDCT method, divisors are equal to quantization |
shoaib_ahmed | 0:791a779d6220 | 417 | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
shoaib_ahmed | 0:791a779d6220 | 418 | * scalefactor[0] = 1 |
shoaib_ahmed | 0:791a779d6220 | 419 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
shoaib_ahmed | 0:791a779d6220 | 420 | * We apply a further scale factor of 8. |
shoaib_ahmed | 0:791a779d6220 | 421 | * What's actually stored is 1/divisor so that the inner loop can |
shoaib_ahmed | 0:791a779d6220 | 422 | * use a multiplication rather than a division. |
shoaib_ahmed | 0:791a779d6220 | 423 | */ |
shoaib_ahmed | 0:791a779d6220 | 424 | FAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table; |
shoaib_ahmed | 0:791a779d6220 | 425 | int row, col; |
shoaib_ahmed | 0:791a779d6220 | 426 | static const double aanscalefactor[DCTSIZE] = { |
shoaib_ahmed | 0:791a779d6220 | 427 | 1.0, 1.387039845, 1.306562965, 1.175875602, |
shoaib_ahmed | 0:791a779d6220 | 428 | 1.0, 0.785694958, 0.541196100, 0.275899379 |
shoaib_ahmed | 0:791a779d6220 | 429 | }; |
shoaib_ahmed | 0:791a779d6220 | 430 | |
shoaib_ahmed | 0:791a779d6220 | 431 | i = 0; |
shoaib_ahmed | 0:791a779d6220 | 432 | for (row = 0; row < DCTSIZE; row++) { |
shoaib_ahmed | 0:791a779d6220 | 433 | for (col = 0; col < DCTSIZE; col++) { |
shoaib_ahmed | 0:791a779d6220 | 434 | fdtbl[i] = (FAST_FLOAT) |
shoaib_ahmed | 0:791a779d6220 | 435 | (1.0 / ((double) qtbl->quantval[i] * |
shoaib_ahmed | 0:791a779d6220 | 436 | aanscalefactor[row] * aanscalefactor[col] * |
shoaib_ahmed | 0:791a779d6220 | 437 | (compptr->component_needed ? 16.0 : 8.0))); |
shoaib_ahmed | 0:791a779d6220 | 438 | i++; |
shoaib_ahmed | 0:791a779d6220 | 439 | } |
shoaib_ahmed | 0:791a779d6220 | 440 | } |
shoaib_ahmed | 0:791a779d6220 | 441 | } |
shoaib_ahmed | 0:791a779d6220 | 442 | fdct->pub.forward_DCT[ci] = forward_DCT_float; |
shoaib_ahmed | 0:791a779d6220 | 443 | break; |
shoaib_ahmed | 0:791a779d6220 | 444 | #endif |
shoaib_ahmed | 0:791a779d6220 | 445 | default: |
shoaib_ahmed | 0:791a779d6220 | 446 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
shoaib_ahmed | 0:791a779d6220 | 447 | break; |
shoaib_ahmed | 0:791a779d6220 | 448 | } |
shoaib_ahmed | 0:791a779d6220 | 449 | } |
shoaib_ahmed | 0:791a779d6220 | 450 | } |
shoaib_ahmed | 0:791a779d6220 | 451 | |
shoaib_ahmed | 0:791a779d6220 | 452 | |
shoaib_ahmed | 0:791a779d6220 | 453 | /* |
shoaib_ahmed | 0:791a779d6220 | 454 | * Initialize FDCT manager. |
shoaib_ahmed | 0:791a779d6220 | 455 | */ |
shoaib_ahmed | 0:791a779d6220 | 456 | |
shoaib_ahmed | 0:791a779d6220 | 457 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 458 | jinit_forward_dct (j_compress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 459 | { |
shoaib_ahmed | 0:791a779d6220 | 460 | my_fdct_ptr fdct; |
shoaib_ahmed | 0:791a779d6220 | 461 | int ci; |
shoaib_ahmed | 0:791a779d6220 | 462 | jpeg_component_info *compptr; |
shoaib_ahmed | 0:791a779d6220 | 463 | |
shoaib_ahmed | 0:791a779d6220 | 464 | fdct = (my_fdct_ptr) |
shoaib_ahmed | 0:791a779d6220 | 465 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 466 | SIZEOF(my_fdct_controller)); |
shoaib_ahmed | 0:791a779d6220 | 467 | cinfo->fdct = &fdct->pub; |
shoaib_ahmed | 0:791a779d6220 | 468 | fdct->pub.start_pass = start_pass_fdctmgr; |
shoaib_ahmed | 0:791a779d6220 | 469 | |
shoaib_ahmed | 0:791a779d6220 | 470 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
shoaib_ahmed | 0:791a779d6220 | 471 | ci++, compptr++) { |
shoaib_ahmed | 0:791a779d6220 | 472 | /* Allocate a divisor table for each component */ |
shoaib_ahmed | 0:791a779d6220 | 473 | compptr->dct_table = |
shoaib_ahmed | 0:791a779d6220 | 474 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 475 | SIZEOF(divisor_table)); |
shoaib_ahmed | 0:791a779d6220 | 476 | } |
shoaib_ahmed | 0:791a779d6220 | 477 | } |