00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00064 #include <stdlib.h>
00065 #include <stdio.h>
00066 #include "libavutil/common.h"
00067 #include "dsputil.h"
00068
00069 #define DCTSIZE 8
00070 #define BITS_IN_JSAMPLE 8
00071 #define GLOBAL(x) x
00072 #define RIGHT_SHIFT(x, n) ((x) >> (n))
00073 #define MULTIPLY16C16(var,const) ((var)*(const))
00074
00075 #if 1 //def USE_ACCURATE_ROUNDING
00076 #define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n)
00077 #else
00078 #define DESCALE(x,n) RIGHT_SHIFT(x, n)
00079 #endif
00080
00081
00082
00083
00084
00085
00086 #if DCTSIZE != 8
00087 Sorry, this code only copes with 8x8 DCTs.
00088 #endif
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 #if BITS_IN_JSAMPLE == 8
00126 #define CONST_BITS 13
00127 #define PASS1_BITS 4
00128 #else
00129 #define CONST_BITS 13
00130 #define PASS1_BITS 1
00131 #endif
00132
00133
00134
00135
00136
00137
00138
00139
00140 #if CONST_BITS == 13
00141 #define FIX_0_298631336 ((int32_t) 2446)
00142 #define FIX_0_390180644 ((int32_t) 3196)
00143 #define FIX_0_541196100 ((int32_t) 4433)
00144 #define FIX_0_765366865 ((int32_t) 6270)
00145 #define FIX_0_899976223 ((int32_t) 7373)
00146 #define FIX_1_175875602 ((int32_t) 9633)
00147 #define FIX_1_501321110 ((int32_t) 12299)
00148 #define FIX_1_847759065 ((int32_t) 15137)
00149 #define FIX_1_961570560 ((int32_t) 16069)
00150 #define FIX_2_053119869 ((int32_t) 16819)
00151 #define FIX_2_562915447 ((int32_t) 20995)
00152 #define FIX_3_072711026 ((int32_t) 25172)
00153 #else
00154 #define FIX_0_298631336 FIX(0.298631336)
00155 #define FIX_0_390180644 FIX(0.390180644)
00156 #define FIX_0_541196100 FIX(0.541196100)
00157 #define FIX_0_765366865 FIX(0.765366865)
00158 #define FIX_0_899976223 FIX(0.899976223)
00159 #define FIX_1_175875602 FIX(1.175875602)
00160 #define FIX_1_501321110 FIX(1.501321110)
00161 #define FIX_1_847759065 FIX(1.847759065)
00162 #define FIX_1_961570560 FIX(1.961570560)
00163 #define FIX_2_053119869 FIX(2.053119869)
00164 #define FIX_2_562915447 FIX(2.562915447)
00165 #define FIX_3_072711026 FIX(3.072711026)
00166 #endif
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 #if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2
00177 #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
00178 #else
00179 #define MULTIPLY(var,const) ((var) * (const))
00180 #endif
00181
00182
00183 static av_always_inline void row_fdct(DCTELEM * data){
00184 int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00185 int tmp10, tmp11, tmp12, tmp13;
00186 int z1, z2, z3, z4, z5;
00187 DCTELEM *dataptr;
00188 int ctr;
00189
00190
00191
00192
00193
00194 dataptr = data;
00195 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
00196 tmp0 = dataptr[0] + dataptr[7];
00197 tmp7 = dataptr[0] - dataptr[7];
00198 tmp1 = dataptr[1] + dataptr[6];
00199 tmp6 = dataptr[1] - dataptr[6];
00200 tmp2 = dataptr[2] + dataptr[5];
00201 tmp5 = dataptr[2] - dataptr[5];
00202 tmp3 = dataptr[3] + dataptr[4];
00203 tmp4 = dataptr[3] - dataptr[4];
00204
00205
00206
00207
00208
00209 tmp10 = tmp0 + tmp3;
00210 tmp13 = tmp0 - tmp3;
00211 tmp11 = tmp1 + tmp2;
00212 tmp12 = tmp1 - tmp2;
00213
00214 dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
00215 dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
00216
00217 z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
00218 dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
00219 CONST_BITS-PASS1_BITS);
00220 dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
00221 CONST_BITS-PASS1_BITS);
00222
00223
00224
00225
00226
00227
00228 z1 = tmp4 + tmp7;
00229 z2 = tmp5 + tmp6;
00230 z3 = tmp4 + tmp6;
00231 z4 = tmp5 + tmp7;
00232 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
00233
00234 tmp4 = MULTIPLY(tmp4, FIX_0_298631336);
00235 tmp5 = MULTIPLY(tmp5, FIX_2_053119869);
00236 tmp6 = MULTIPLY(tmp6, FIX_3_072711026);
00237 tmp7 = MULTIPLY(tmp7, FIX_1_501321110);
00238 z1 = MULTIPLY(z1, - FIX_0_899976223);
00239 z2 = MULTIPLY(z2, - FIX_2_562915447);
00240 z3 = MULTIPLY(z3, - FIX_1_961570560);
00241 z4 = MULTIPLY(z4, - FIX_0_390180644);
00242
00243 z3 += z5;
00244 z4 += z5;
00245
00246 dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
00247 dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
00248 dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
00249 dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
00250
00251 dataptr += DCTSIZE;
00252 }
00253 }
00254
00255
00256
00257
00258
00259 GLOBAL(void)
00260 ff_jpeg_fdct_islow (DCTELEM * data)
00261 {
00262 int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00263 int tmp10, tmp11, tmp12, tmp13;
00264 int z1, z2, z3, z4, z5;
00265 DCTELEM *dataptr;
00266 int ctr;
00267
00268 row_fdct(data);
00269
00270
00271
00272
00273
00274
00275 dataptr = data;
00276 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
00277 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
00278 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
00279 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
00280 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
00281 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
00282 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
00283 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
00284 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
00285
00286
00287
00288
00289
00290 tmp10 = tmp0 + tmp3;
00291 tmp13 = tmp0 - tmp3;
00292 tmp11 = tmp1 + tmp2;
00293 tmp12 = tmp1 - tmp2;
00294
00295 dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
00296 dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
00297
00298 z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
00299 dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
00300 CONST_BITS+PASS1_BITS);
00301 dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
00302 CONST_BITS+PASS1_BITS);
00303
00304
00305
00306
00307
00308
00309 z1 = tmp4 + tmp7;
00310 z2 = tmp5 + tmp6;
00311 z3 = tmp4 + tmp6;
00312 z4 = tmp5 + tmp7;
00313 z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
00314
00315 tmp4 = MULTIPLY(tmp4, FIX_0_298631336);
00316 tmp5 = MULTIPLY(tmp5, FIX_2_053119869);
00317 tmp6 = MULTIPLY(tmp6, FIX_3_072711026);
00318 tmp7 = MULTIPLY(tmp7, FIX_1_501321110);
00319 z1 = MULTIPLY(z1, - FIX_0_899976223);
00320 z2 = MULTIPLY(z2, - FIX_2_562915447);
00321 z3 = MULTIPLY(z3, - FIX_1_961570560);
00322 z4 = MULTIPLY(z4, - FIX_0_390180644);
00323
00324 z3 += z5;
00325 z4 += z5;
00326
00327 dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
00328 CONST_BITS+PASS1_BITS);
00329 dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
00330 CONST_BITS+PASS1_BITS);
00331 dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
00332 CONST_BITS+PASS1_BITS);
00333 dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
00334 CONST_BITS+PASS1_BITS);
00335
00336 dataptr++;
00337 }
00338 }
00339
00340
00341
00342
00343
00344
00345 GLOBAL(void)
00346 ff_fdct248_islow (DCTELEM * data)
00347 {
00348 int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
00349 int tmp10, tmp11, tmp12, tmp13;
00350 int z1;
00351 DCTELEM *dataptr;
00352 int ctr;
00353
00354 row_fdct(data);
00355
00356
00357
00358
00359
00360
00361 dataptr = data;
00362 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
00363 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*1];
00364 tmp1 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
00365 tmp2 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];
00366 tmp3 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];
00367 tmp4 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*1];
00368 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
00369 tmp6 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];
00370 tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];
00371
00372 tmp10 = tmp0 + tmp3;
00373 tmp11 = tmp1 + tmp2;
00374 tmp12 = tmp1 - tmp2;
00375 tmp13 = tmp0 - tmp3;
00376
00377 dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
00378 dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
00379
00380 z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
00381 dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
00382 CONST_BITS+PASS1_BITS);
00383 dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
00384 CONST_BITS+PASS1_BITS);
00385
00386 tmp10 = tmp4 + tmp7;
00387 tmp11 = tmp5 + tmp6;
00388 tmp12 = tmp5 - tmp6;
00389 tmp13 = tmp4 - tmp7;
00390
00391 dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
00392 dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
00393
00394 z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
00395 dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
00396 CONST_BITS+PASS1_BITS);
00397 dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
00398 CONST_BITS+PASS1_BITS);
00399
00400 dataptr++;
00401 }
00402 }