Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jcdctmgr.c |
| 3 | * |
DRC | a73e870 | 2012-12-31 02:52:30 +0000 | [diff] [blame] | 4 | * This file was part of the Independent JPEG Group's software: |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 5 | * Copyright (C) 1994-1996, Thomas G. Lane. |
DRC | a6ef282 | 2013-09-28 03:23:49 +0000 | [diff] [blame] | 6 | * libjpeg-turbo Modifications: |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2006, MIYASAKA Masaru. |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 8 | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | d65e768 | 2015-10-14 22:26:25 -0500 | [diff] [blame] | 9 | * Copyright (C) 2011, 2014-2015, D. R. Commander. |
DRC | 7e3acc0 | 2015-10-10 10:25:46 -0500 | [diff] [blame] | 10 | * For conditions of distribution and use, see the accompanying README.ijg |
| 11 | * file. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 12 | * |
| 13 | * This file contains the forward-DCT management logic. |
| 14 | * This code selects a particular DCT implementation to be used, |
| 15 | * and it performs related housekeeping chores including coefficient |
| 16 | * quantization. |
| 17 | */ |
| 18 | |
| 19 | #define JPEG_INTERNALS |
| 20 | #include "jinclude.h" |
| 21 | #include "jpeglib.h" |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 22 | #include "jdct.h" /* Private declarations for DCT subsystem */ |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 23 | #include "jsimddct.h" |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 24 | |
| 25 | |
| 26 | /* Private subobject for this module */ |
| 27 | |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 28 | typedef void (*forward_DCT_method_ptr) (DCTELEM * data); |
| 29 | typedef void (*float_DCT_method_ptr) (FAST_FLOAT * data); |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 30 | |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 31 | typedef void (*convsamp_method_ptr) (JSAMPARRAY sample_data, |
| 32 | JDIMENSION start_col, |
| 33 | DCTELEM * workspace); |
| 34 | typedef void (*float_convsamp_method_ptr) (JSAMPARRAY sample_data, |
| 35 | JDIMENSION start_col, |
| 36 | FAST_FLOAT *workspace); |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 37 | |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 38 | typedef void (*quantize_method_ptr) (JCOEFPTR coef_block, DCTELEM * divisors, |
| 39 | DCTELEM * workspace); |
| 40 | typedef void (*float_quantize_method_ptr) (JCOEFPTR coef_block, |
| 41 | FAST_FLOAT * divisors, |
| 42 | FAST_FLOAT * workspace); |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 43 | |
DRC | a49c4e5 | 2011-02-18 20:50:08 +0000 | [diff] [blame] | 44 | METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *); |
| 45 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 46 | typedef struct { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 47 | struct jpeg_forward_dct pub; /* public fields */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 48 | |
| 49 | /* Pointer to the DCT routine actually in use */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 50 | forward_DCT_method_ptr dct; |
| 51 | convsamp_method_ptr convsamp; |
| 52 | quantize_method_ptr quantize; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 53 | |
| 54 | /* The actual post-DCT divisors --- not identical to the quant table |
| 55 | * entries, because of scaling (especially for an unnormalized DCT). |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 56 | * Each table is given in normal array order. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 57 | */ |
| 58 | DCTELEM * divisors[NUM_QUANT_TBLS]; |
| 59 | |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 60 | /* work area for FDCT subroutine */ |
| 61 | DCTELEM * workspace; |
| 62 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 63 | #ifdef DCT_FLOAT_SUPPORTED |
| 64 | /* Same as above for the floating-point case. */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 65 | float_DCT_method_ptr float_dct; |
| 66 | float_convsamp_method_ptr float_convsamp; |
| 67 | float_quantize_method_ptr float_quantize; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 68 | FAST_FLOAT * float_divisors[NUM_QUANT_TBLS]; |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 69 | FAST_FLOAT * float_workspace; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 70 | #endif |
| 71 | } my_fdct_controller; |
| 72 | |
| 73 | typedef my_fdct_controller * my_fdct_ptr; |
| 74 | |
| 75 | |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 76 | #if BITS_IN_JSAMPLE == 8 |
| 77 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 78 | /* |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 79 | * Find the highest bit in an integer through binary search. |
| 80 | */ |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 81 | |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 82 | LOCAL(int) |
DRC | fc5dc4f | 2009-10-01 22:26:14 +0000 | [diff] [blame] | 83 | flss (UINT16 val) |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 84 | { |
| 85 | int bit; |
| 86 | |
| 87 | bit = 16; |
| 88 | |
| 89 | if (!val) |
| 90 | return 0; |
| 91 | |
| 92 | if (!(val & 0xff00)) { |
| 93 | bit -= 8; |
| 94 | val <<= 8; |
| 95 | } |
| 96 | if (!(val & 0xf000)) { |
| 97 | bit -= 4; |
| 98 | val <<= 4; |
| 99 | } |
| 100 | if (!(val & 0xc000)) { |
| 101 | bit -= 2; |
| 102 | val <<= 2; |
| 103 | } |
| 104 | if (!(val & 0x8000)) { |
| 105 | bit -= 1; |
| 106 | val <<= 1; |
| 107 | } |
| 108 | |
| 109 | return bit; |
| 110 | } |
| 111 | |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 112 | |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 113 | /* |
| 114 | * Compute values to do a division using reciprocal. |
| 115 | * |
| 116 | * This implementation is based on an algorithm described in |
| 117 | * "How to optimize for the Pentium family of microprocessors" |
| 118 | * (http://www.agner.org/assem/). |
| 119 | * More information about the basic algorithm can be found in |
| 120 | * the paper "Integer Division Using Reciprocals" by Robert Alverson. |
| 121 | * |
| 122 | * The basic idea is to replace x/d by x * d^-1. In order to store |
| 123 | * d^-1 with enough precision we shift it left a few places. It turns |
| 124 | * out that this algoright gives just enough precision, and also fits |
| 125 | * into DCTELEM: |
| 126 | * |
| 127 | * b = (the number of significant bits in divisor) - 1 |
| 128 | * r = (word size) + b |
| 129 | * f = 2^r / divisor |
| 130 | * |
| 131 | * f will not be an integer for most cases, so we need to compensate |
| 132 | * for the rounding error introduced: |
| 133 | * |
| 134 | * no fractional part: |
| 135 | * |
| 136 | * result = input >> r |
| 137 | * |
| 138 | * fractional part of f < 0.5: |
| 139 | * |
| 140 | * round f down to nearest integer |
| 141 | * result = ((input + 1) * f) >> r |
| 142 | * |
| 143 | * fractional part of f > 0.5: |
| 144 | * |
| 145 | * round f up to nearest integer |
| 146 | * result = (input * f) >> r |
| 147 | * |
| 148 | * This is the original algorithm that gives truncated results. But we |
| 149 | * want properly rounded results, so we replace "input" with |
| 150 | * "input + divisor/2". |
| 151 | * |
| 152 | * In order to allow SIMD implementations we also tweak the values to |
| 153 | * allow the same calculation to be made at all times: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 154 | * |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 155 | * dctbl[0] = f rounded to nearest integer |
| 156 | * dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5) |
| 157 | * dctbl[2] = 1 << ((word size) * 2 - r) |
| 158 | * dctbl[3] = r - (word size) |
| 159 | * |
| 160 | * dctbl[2] is for stupid instruction sets where the shift operation |
| 161 | * isn't member wise (e.g. MMX). |
| 162 | * |
| 163 | * The reason dctbl[2] and dctbl[3] reduce the shift with (word size) |
| 164 | * is that most SIMD implementations have a "multiply and store top |
| 165 | * half" operation. |
| 166 | * |
| 167 | * Lastly, we store each of the values in their own table instead |
| 168 | * of in a consecutive manner, yet again in order to allow SIMD |
| 169 | * routines. |
| 170 | */ |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 171 | |
DRC | a49c4e5 | 2011-02-18 20:50:08 +0000 | [diff] [blame] | 172 | LOCAL(int) |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 173 | compute_reciprocal (UINT16 divisor, DCTELEM * dtbl) |
| 174 | { |
| 175 | UDCTELEM2 fq, fr; |
| 176 | UDCTELEM c; |
| 177 | int b, r; |
| 178 | |
DRC | b5a55e6 | 2015-08-29 18:05:43 -0500 | [diff] [blame] | 179 | if (divisor == 1) { |
| 180 | /* divisor == 1 means unquantized, so these reciprocal/correction/shift |
| 181 | * values will cause the C quantization algorithm to act like the |
| 182 | * identity function. Since only the C quantization algorithm is used in |
| 183 | * these cases, the scale value is irrelevant. |
| 184 | */ |
| 185 | dtbl[DCTSIZE2 * 0] = (DCTELEM) 1; /* reciprocal */ |
| 186 | dtbl[DCTSIZE2 * 1] = (DCTELEM) 0; /* correction */ |
| 187 | dtbl[DCTSIZE2 * 2] = (DCTELEM) 1; /* scale */ |
DRC | aa769fe | 2015-10-15 02:25:00 -0500 | [diff] [blame^] | 188 | dtbl[DCTSIZE2 * 3] = -(DCTELEM) (sizeof(DCTELEM) * 8); /* shift */ |
DRC | b5a55e6 | 2015-08-29 18:05:43 -0500 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
DRC | fc5dc4f | 2009-10-01 22:26:14 +0000 | [diff] [blame] | 192 | b = flss(divisor) - 1; |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 193 | r = sizeof(DCTELEM) * 8 + b; |
| 194 | |
| 195 | fq = ((UDCTELEM2)1 << r) / divisor; |
| 196 | fr = ((UDCTELEM2)1 << r) % divisor; |
| 197 | |
| 198 | c = divisor / 2; /* for rounding */ |
| 199 | |
| 200 | if (fr == 0) { /* divisor is power of two */ |
| 201 | /* fq will be one bit too large to fit in DCTELEM, so adjust */ |
| 202 | fq >>= 1; |
| 203 | r--; |
DRC | d65d99a | 2012-01-31 03:39:23 +0000 | [diff] [blame] | 204 | } else if (fr <= (divisor / 2U)) { /* fractional part is < 0.5 */ |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 205 | c++; |
| 206 | } else { /* fractional part is > 0.5 */ |
| 207 | fq++; |
| 208 | } |
| 209 | |
| 210 | dtbl[DCTSIZE2 * 0] = (DCTELEM) fq; /* reciprocal */ |
| 211 | dtbl[DCTSIZE2 * 1] = (DCTELEM) c; /* correction + roundfactor */ |
DRC | d65e768 | 2015-10-14 22:26:25 -0500 | [diff] [blame] | 212 | #ifdef WITH_SIMD |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 213 | dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r)); /* scale */ |
DRC | d65e768 | 2015-10-14 22:26:25 -0500 | [diff] [blame] | 214 | #else |
| 215 | dtbl[DCTSIZE2 * 2] = 1; |
| 216 | #endif |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 217 | dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ |
DRC | a49c4e5 | 2011-02-18 20:50:08 +0000 | [diff] [blame] | 218 | |
| 219 | if(r <= 16) return 0; |
| 220 | else return 1; |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 221 | } |
| 222 | |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 223 | #endif |
| 224 | |
| 225 | |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 226 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 227 | * Initialize for a processing pass. |
| 228 | * Verify that all referenced Q-tables are present, and set up |
| 229 | * the divisor table for each one. |
| 230 | * In the current implementation, DCT of all components is done during |
| 231 | * the first pass, even if only some components will be output in the |
| 232 | * first scan. Hence all components should be examined here. |
| 233 | */ |
| 234 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 235 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 236 | start_pass_fdctmgr (j_compress_ptr cinfo) |
| 237 | { |
| 238 | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
| 239 | int ci, qtblno, i; |
| 240 | jpeg_component_info *compptr; |
| 241 | JQUANT_TBL * qtbl; |
| 242 | DCTELEM * dtbl; |
| 243 | |
| 244 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 245 | ci++, compptr++) { |
| 246 | qtblno = compptr->quant_tbl_no; |
| 247 | /* Make sure specified quantization table is present */ |
| 248 | if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 249 | cinfo->quant_tbl_ptrs[qtblno] == NULL) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 250 | ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); |
| 251 | qtbl = cinfo->quant_tbl_ptrs[qtblno]; |
| 252 | /* Compute divisors for this quant table */ |
| 253 | /* We may do this more than once for same table, but it's not a big deal */ |
| 254 | switch (cinfo->dct_method) { |
| 255 | #ifdef DCT_ISLOW_SUPPORTED |
| 256 | case JDCT_ISLOW: |
| 257 | /* For LL&M IDCT method, divisors are equal to raw quantization |
| 258 | * coefficients multiplied by 8 (to counteract scaling). |
| 259 | */ |
| 260 | if (fdct->divisors[qtblno] == NULL) { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 261 | fdct->divisors[qtblno] = (DCTELEM *) |
| 262 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 263 | (DCTSIZE2 * 4) * sizeof(DCTELEM)); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 264 | } |
| 265 | dtbl = fdct->divisors[qtblno]; |
| 266 | for (i = 0; i < DCTSIZE2; i++) { |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 267 | #if BITS_IN_JSAMPLE == 8 |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 268 | if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) |
| 269 | && fdct->quantize == jsimd_quantize) |
| 270 | fdct->quantize = quantize; |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 271 | #else |
| 272 | dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3; |
| 273 | #endif |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 274 | } |
| 275 | break; |
| 276 | #endif |
| 277 | #ifdef DCT_IFAST_SUPPORTED |
| 278 | case JDCT_IFAST: |
| 279 | { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 280 | /* For AA&N IDCT method, divisors are equal to quantization |
| 281 | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
| 282 | * scalefactor[0] = 1 |
| 283 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
| 284 | * We apply a further scale factor of 8. |
| 285 | */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 286 | #define CONST_BITS 14 |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 287 | static const INT16 aanscales[DCTSIZE2] = { |
| 288 | /* precomputed values scaled up by 14 bits */ |
| 289 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
| 290 | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, |
| 291 | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, |
| 292 | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, |
| 293 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, |
| 294 | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
| 295 | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
| 296 | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
| 297 | }; |
| 298 | SHIFT_TEMPS |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 299 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 300 | if (fdct->divisors[qtblno] == NULL) { |
| 301 | fdct->divisors[qtblno] = (DCTELEM *) |
| 302 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 303 | (DCTSIZE2 * 4) * sizeof(DCTELEM)); |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 304 | } |
| 305 | dtbl = fdct->divisors[qtblno]; |
| 306 | for (i = 0; i < DCTSIZE2; i++) { |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 307 | #if BITS_IN_JSAMPLE == 8 |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 308 | if(!compute_reciprocal( |
DRC | 1e32fe3 | 2015-10-14 17:32:39 -0500 | [diff] [blame] | 309 | DESCALE(MULTIPLY16V16((JLONG) qtbl->quantval[i], |
| 310 | (JLONG) aanscales[i]), |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 311 | CONST_BITS-3), &dtbl[i]) |
| 312 | && fdct->quantize == jsimd_quantize) |
| 313 | fdct->quantize = quantize; |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 314 | #else |
| 315 | dtbl[i] = (DCTELEM) |
DRC | 1e32fe3 | 2015-10-14 17:32:39 -0500 | [diff] [blame] | 316 | DESCALE(MULTIPLY16V16((JLONG) qtbl->quantval[i], |
| 317 | (JLONG) aanscales[i]), |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 318 | CONST_BITS-3); |
| 319 | #endif |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 320 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 321 | } |
| 322 | break; |
| 323 | #endif |
| 324 | #ifdef DCT_FLOAT_SUPPORTED |
| 325 | case JDCT_FLOAT: |
| 326 | { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 327 | /* For float AA&N IDCT method, divisors are equal to quantization |
| 328 | * coefficients scaled by scalefactor[row]*scalefactor[col], where |
| 329 | * scalefactor[0] = 1 |
| 330 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 |
| 331 | * We apply a further scale factor of 8. |
| 332 | * What's actually stored is 1/divisor so that the inner loop can |
| 333 | * use a multiplication rather than a division. |
| 334 | */ |
| 335 | FAST_FLOAT * fdtbl; |
| 336 | int row, col; |
| 337 | static const double aanscalefactor[DCTSIZE] = { |
| 338 | 1.0, 1.387039845, 1.306562965, 1.175875602, |
| 339 | 1.0, 0.785694958, 0.541196100, 0.275899379 |
| 340 | }; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 341 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 342 | if (fdct->float_divisors[qtblno] == NULL) { |
| 343 | fdct->float_divisors[qtblno] = (FAST_FLOAT *) |
| 344 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 345 | DCTSIZE2 * sizeof(FAST_FLOAT)); |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 346 | } |
| 347 | fdtbl = fdct->float_divisors[qtblno]; |
| 348 | i = 0; |
| 349 | for (row = 0; row < DCTSIZE; row++) { |
| 350 | for (col = 0; col < DCTSIZE; col++) { |
| 351 | fdtbl[i] = (FAST_FLOAT) |
| 352 | (1.0 / (((double) qtbl->quantval[i] * |
| 353 | aanscalefactor[row] * aanscalefactor[col] * 8.0))); |
| 354 | i++; |
| 355 | } |
| 356 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 357 | } |
| 358 | break; |
| 359 | #endif |
| 360 | default: |
| 361 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | |
| 368 | /* |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 369 | * Load data into workspace, applying unsigned->signed conversion. |
| 370 | */ |
| 371 | |
| 372 | METHODDEF(void) |
| 373 | convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM * workspace) |
| 374 | { |
| 375 | register DCTELEM *workspaceptr; |
| 376 | register JSAMPROW elemptr; |
| 377 | register int elemr; |
| 378 | |
| 379 | workspaceptr = workspace; |
| 380 | for (elemr = 0; elemr < DCTSIZE; elemr++) { |
| 381 | elemptr = sample_data[elemr] + start_col; |
| 382 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 383 | #if DCTSIZE == 8 /* unroll the inner loop */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 384 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 385 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 386 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 387 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 388 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 389 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 390 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 391 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 392 | #else |
| 393 | { |
| 394 | register int elemc; |
| 395 | for (elemc = DCTSIZE; elemc > 0; elemc--) |
| 396 | *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; |
| 397 | } |
| 398 | #endif |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
| 403 | /* |
| 404 | * Quantize/descale the coefficients, and store into coef_blocks[]. |
| 405 | */ |
| 406 | |
| 407 | METHODDEF(void) |
| 408 | quantize (JCOEFPTR coef_block, DCTELEM * divisors, DCTELEM * workspace) |
| 409 | { |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 410 | int i; |
| 411 | DCTELEM temp; |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 412 | JCOEFPTR output_ptr = coef_block; |
| 413 | |
| 414 | #if BITS_IN_JSAMPLE == 8 |
| 415 | |
DRC | b5a55e6 | 2015-08-29 18:05:43 -0500 | [diff] [blame] | 416 | UDCTELEM recip, corr; |
| 417 | int shift; |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 418 | UDCTELEM2 product; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 419 | |
| 420 | for (i = 0; i < DCTSIZE2; i++) { |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 421 | temp = workspace[i]; |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 422 | recip = divisors[i + DCTSIZE2 * 0]; |
| 423 | corr = divisors[i + DCTSIZE2 * 1]; |
| 424 | shift = divisors[i + DCTSIZE2 * 3]; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 425 | |
| 426 | if (temp < 0) { |
| 427 | temp = -temp; |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 428 | product = (UDCTELEM2)(temp + corr) * recip; |
| 429 | product >>= shift + sizeof(DCTELEM)*8; |
DRC | aa769fe | 2015-10-15 02:25:00 -0500 | [diff] [blame^] | 430 | temp = (DCTELEM)product; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 431 | temp = -temp; |
| 432 | } else { |
Pierre Ossman | dedc42e | 2009-03-09 13:23:04 +0000 | [diff] [blame] | 433 | product = (UDCTELEM2)(temp + corr) * recip; |
| 434 | product >>= shift + sizeof(DCTELEM)*8; |
DRC | aa769fe | 2015-10-15 02:25:00 -0500 | [diff] [blame^] | 435 | temp = (DCTELEM)product; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 436 | } |
| 437 | output_ptr[i] = (JCOEF) temp; |
| 438 | } |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 439 | |
| 440 | #else |
| 441 | |
| 442 | register DCTELEM qval; |
| 443 | |
| 444 | for (i = 0; i < DCTSIZE2; i++) { |
| 445 | qval = divisors[i]; |
| 446 | temp = workspace[i]; |
| 447 | /* Divide the coefficient value by qval, ensuring proper rounding. |
| 448 | * Since C does not specify the direction of rounding for negative |
| 449 | * quotients, we have to force the dividend positive for portability. |
| 450 | * |
| 451 | * In most files, at least half of the output values will be zero |
| 452 | * (at default quantization settings, more like three-quarters...) |
| 453 | * so we should ensure that this case is fast. On many machines, |
| 454 | * a comparison is enough cheaper than a divide to make a special test |
| 455 | * a win. Since both inputs will be nonnegative, we need only test |
| 456 | * for a < b to discover whether a/b is 0. |
| 457 | * If your machine's division is fast enough, define FAST_DIVIDE. |
| 458 | */ |
| 459 | #ifdef FAST_DIVIDE |
| 460 | #define DIVIDE_BY(a,b) a /= b |
| 461 | #else |
| 462 | #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0 |
| 463 | #endif |
| 464 | if (temp < 0) { |
| 465 | temp = -temp; |
| 466 | temp += qval>>1; /* for rounding */ |
| 467 | DIVIDE_BY(temp, qval); |
DRC | eca0637 | 2014-11-06 09:32:38 +0000 | [diff] [blame] | 468 | temp = -temp; |
DRC | aee4f72 | 2014-08-09 23:06:07 +0000 | [diff] [blame] | 469 | } else { |
| 470 | temp += qval>>1; /* for rounding */ |
| 471 | DIVIDE_BY(temp, qval); |
| 472 | } |
| 473 | output_ptr[i] = (JCOEF) temp; |
| 474 | } |
| 475 | |
| 476 | #endif |
| 477 | |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | |
| 481 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 482 | * Perform forward DCT on one or more blocks of a component. |
| 483 | * |
| 484 | * The input samples are taken from the sample_data[] array starting at |
| 485 | * position start_row/start_col, and moving to the right for any additional |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 486 | * blocks. The quantized coefficients are returned in coef_blocks[]. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 487 | */ |
| 488 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 489 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 490 | forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 491 | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
| 492 | JDIMENSION start_row, JDIMENSION start_col, |
| 493 | JDIMENSION num_blocks) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 494 | /* This version is used for integer DCT implementations. */ |
| 495 | { |
| 496 | /* This routine is heavily used, so it's worth coding it tightly. */ |
| 497 | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 498 | DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no]; |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 499 | DCTELEM * workspace; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 500 | JDIMENSION bi; |
| 501 | |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 502 | /* Make sure the compiler doesn't look up these every pass */ |
| 503 | forward_DCT_method_ptr do_dct = fdct->dct; |
| 504 | convsamp_method_ptr do_convsamp = fdct->convsamp; |
| 505 | quantize_method_ptr do_quantize = fdct->quantize; |
Pierre Ossman | dc5db14 | 2009-03-13 12:17:26 +0000 | [diff] [blame] | 506 | workspace = fdct->workspace; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 507 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 508 | sample_data += start_row; /* fold in the vertical offset once */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 509 | |
| 510 | for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { |
| 511 | /* Load data into workspace, applying unsigned->signed conversion */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 512 | (*do_convsamp) (sample_data, start_col, workspace); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 513 | |
| 514 | /* Perform the DCT */ |
| 515 | (*do_dct) (workspace); |
| 516 | |
| 517 | /* Quantize/descale the coefficients, and store into coef_blocks[] */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 518 | (*do_quantize) (coef_blocks[bi], divisors, workspace); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | |
| 523 | #ifdef DCT_FLOAT_SUPPORTED |
| 524 | |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 525 | |
| 526 | METHODDEF(void) |
| 527 | convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT * workspace) |
| 528 | { |
| 529 | register FAST_FLOAT *workspaceptr; |
| 530 | register JSAMPROW elemptr; |
| 531 | register int elemr; |
| 532 | |
| 533 | workspaceptr = workspace; |
| 534 | for (elemr = 0; elemr < DCTSIZE; elemr++) { |
| 535 | elemptr = sample_data[elemr] + start_col; |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 536 | #if DCTSIZE == 8 /* unroll the inner loop */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 537 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 538 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 539 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 540 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 541 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 542 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 543 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 544 | *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 545 | #else |
| 546 | { |
| 547 | register int elemc; |
| 548 | for (elemc = DCTSIZE; elemc > 0; elemc--) |
| 549 | *workspaceptr++ = (FAST_FLOAT) |
| 550 | (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); |
| 551 | } |
| 552 | #endif |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | |
| 557 | METHODDEF(void) |
| 558 | quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, FAST_FLOAT * workspace) |
| 559 | { |
| 560 | register FAST_FLOAT temp; |
| 561 | register int i; |
| 562 | register JCOEFPTR output_ptr = coef_block; |
| 563 | |
| 564 | for (i = 0; i < DCTSIZE2; i++) { |
| 565 | /* Apply the quantization and scaling factor */ |
| 566 | temp = workspace[i] * divisors[i]; |
| 567 | |
| 568 | /* Round to nearest integer. |
| 569 | * Since C does not specify the direction of rounding for negative |
| 570 | * quotients, we have to force the dividend positive for portability. |
| 571 | * The maximum coefficient size is +-16K (for 12-bit data), so this |
| 572 | * code should work for either 16-bit or 32-bit ints. |
| 573 | */ |
| 574 | output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 579 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 580 | forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 581 | JSAMPARRAY sample_data, JBLOCKROW coef_blocks, |
| 582 | JDIMENSION start_row, JDIMENSION start_col, |
| 583 | JDIMENSION num_blocks) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 584 | /* This version is used for floating-point DCT implementations. */ |
| 585 | { |
| 586 | /* This routine is heavily used, so it's worth coding it tightly. */ |
| 587 | my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 588 | FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no]; |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 589 | FAST_FLOAT * workspace; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 590 | JDIMENSION bi; |
| 591 | |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 592 | |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 593 | /* Make sure the compiler doesn't look up these every pass */ |
| 594 | float_DCT_method_ptr do_dct = fdct->float_dct; |
| 595 | float_convsamp_method_ptr do_convsamp = fdct->float_convsamp; |
| 596 | float_quantize_method_ptr do_quantize = fdct->float_quantize; |
Pierre Ossman | dc5db14 | 2009-03-13 12:17:26 +0000 | [diff] [blame] | 597 | workspace = fdct->float_workspace; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 598 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 599 | sample_data += start_row; /* fold in the vertical offset once */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 600 | |
| 601 | for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { |
| 602 | /* Load data into workspace, applying unsigned->signed conversion */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 603 | (*do_convsamp) (sample_data, start_col, workspace); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 604 | |
| 605 | /* Perform the DCT */ |
| 606 | (*do_dct) (workspace); |
| 607 | |
| 608 | /* Quantize/descale the coefficients, and store into coef_blocks[] */ |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 609 | (*do_quantize) (coef_blocks[bi], divisors, workspace); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
| 613 | #endif /* DCT_FLOAT_SUPPORTED */ |
| 614 | |
| 615 | |
| 616 | /* |
| 617 | * Initialize FDCT manager. |
| 618 | */ |
| 619 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 620 | GLOBAL(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 621 | jinit_forward_dct (j_compress_ptr cinfo) |
| 622 | { |
| 623 | my_fdct_ptr fdct; |
| 624 | int i; |
| 625 | |
| 626 | fdct = (my_fdct_ptr) |
| 627 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 628 | sizeof(my_fdct_controller)); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 629 | cinfo->fdct = (struct jpeg_forward_dct *) fdct; |
| 630 | fdct->pub.start_pass = start_pass_fdctmgr; |
| 631 | |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 632 | /* First determine the DCT... */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 633 | switch (cinfo->dct_method) { |
| 634 | #ifdef DCT_ISLOW_SUPPORTED |
| 635 | case JDCT_ISLOW: |
| 636 | fdct->pub.forward_DCT = forward_DCT; |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 637 | if (jsimd_can_fdct_islow()) |
| 638 | fdct->dct = jsimd_fdct_islow; |
| 639 | else |
| 640 | fdct->dct = jpeg_fdct_islow; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 641 | break; |
| 642 | #endif |
| 643 | #ifdef DCT_IFAST_SUPPORTED |
| 644 | case JDCT_IFAST: |
| 645 | fdct->pub.forward_DCT = forward_DCT; |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 646 | if (jsimd_can_fdct_ifast()) |
| 647 | fdct->dct = jsimd_fdct_ifast; |
| 648 | else |
| 649 | fdct->dct = jpeg_fdct_ifast; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 650 | break; |
| 651 | #endif |
| 652 | #ifdef DCT_FLOAT_SUPPORTED |
| 653 | case JDCT_FLOAT: |
| 654 | fdct->pub.forward_DCT = forward_DCT_float; |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 655 | if (jsimd_can_fdct_float()) |
| 656 | fdct->float_dct = jsimd_fdct_float; |
| 657 | else |
| 658 | fdct->float_dct = jpeg_fdct_float; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 659 | break; |
| 660 | #endif |
| 661 | default: |
| 662 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | /* ...then the supporting stages. */ |
| 667 | switch (cinfo->dct_method) { |
| 668 | #ifdef DCT_ISLOW_SUPPORTED |
| 669 | case JDCT_ISLOW: |
| 670 | #endif |
| 671 | #ifdef DCT_IFAST_SUPPORTED |
| 672 | case JDCT_IFAST: |
| 673 | #endif |
| 674 | #if defined(DCT_ISLOW_SUPPORTED) || defined(DCT_IFAST_SUPPORTED) |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 675 | if (jsimd_can_convsamp()) |
| 676 | fdct->convsamp = jsimd_convsamp; |
| 677 | else |
| 678 | fdct->convsamp = convsamp; |
| 679 | if (jsimd_can_quantize()) |
| 680 | fdct->quantize = jsimd_quantize; |
| 681 | else |
| 682 | fdct->quantize = quantize; |
Pierre Ossman | 49dcbfb | 2009-03-09 10:37:20 +0000 | [diff] [blame] | 683 | break; |
| 684 | #endif |
| 685 | #ifdef DCT_FLOAT_SUPPORTED |
| 686 | case JDCT_FLOAT: |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 687 | if (jsimd_can_convsamp_float()) |
| 688 | fdct->float_convsamp = jsimd_convsamp_float; |
| 689 | else |
| 690 | fdct->float_convsamp = convsamp_float; |
| 691 | if (jsimd_can_quantize_float()) |
| 692 | fdct->float_quantize = jsimd_quantize_float; |
| 693 | else |
| 694 | fdct->float_quantize = quantize_float; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 695 | break; |
| 696 | #endif |
| 697 | default: |
| 698 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 699 | break; |
| 700 | } |
| 701 | |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 702 | /* Allocate workspace memory */ |
| 703 | #ifdef DCT_FLOAT_SUPPORTED |
| 704 | if (cinfo->dct_method == JDCT_FLOAT) |
| 705 | fdct->float_workspace = (FAST_FLOAT *) |
| 706 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 707 | sizeof(FAST_FLOAT) * DCTSIZE2); |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 708 | else |
| 709 | #endif |
| 710 | fdct->workspace = (DCTELEM *) |
| 711 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
DRC | 5de454b | 2014-05-18 19:04:03 +0000 | [diff] [blame] | 712 | sizeof(DCTELEM) * DCTSIZE2); |
Pierre Ossman | 35c4719 | 2009-03-09 13:29:37 +0000 | [diff] [blame] | 713 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 714 | /* Mark divisor tables unallocated */ |
| 715 | for (i = 0; i < NUM_QUANT_TBLS; i++) { |
| 716 | fdct->divisors[i] = NULL; |
| 717 | #ifdef DCT_FLOAT_SUPPORTED |
| 718 | fdct->float_divisors[i] = NULL; |
| 719 | #endif |
| 720 | } |
| 721 | } |