@@ -442,11 +442,31 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
442442 /* Save unquantized transform coefficients for later trellis quantization */
443443 if (dst ) {
444444 int i ;
445- for (i = 0 ; i < DCTSIZE2 ; i ++ ) {
446- dst [bi ][i ] = workspace [i ];
447- //printf("d%d ", workspace[i]);
445+ if (cinfo -> dct_method == JDCT_IFAST ) {
446+ static const INT16 aanscales [DCTSIZE2 ] = {
447+ /* precomputed values scaled up by 14 bits */
448+ 16384 , 22725 , 21407 , 19266 , 16384 , 12873 , 8867 , 4520 ,
449+ 22725 , 31521 , 29692 , 26722 , 22725 , 17855 , 12299 , 6270 ,
450+ 21407 , 29692 , 27969 , 25172 , 21407 , 16819 , 11585 , 5906 ,
451+ 19266 , 26722 , 25172 , 22654 , 19266 , 15137 , 10426 , 5315 ,
452+ 16384 , 22725 , 21407 , 19266 , 16384 , 12873 , 8867 , 4520 ,
453+ 12873 , 17855 , 16819 , 15137 , 12873 , 10114 , 6967 , 3552 ,
454+ 8867 , 12299 , 11585 , 10426 , 8867 , 6967 , 4799 , 2446 ,
455+ 4520 , 6270 , 5906 , 5315 , 4520 , 3552 , 2446 , 1247
456+ };
457+
458+ for (i = 0 ; i < DCTSIZE2 ; i ++ ) {
459+ int x = workspace [i ];
460+ int s = aanscales [i ];
461+ x = (x >= 0 ) ? (x * 32768 + s ) / (2 * s ) : (x * 32768 - s ) / (2 * s );
462+ dst [bi ][i ] = x ;
463+ }
464+
465+ } else {
466+ for (i = 0 ; i < DCTSIZE2 ; i ++ ) {
467+ dst [bi ][i ] = workspace [i ];
468+ }
448469 }
449- //printf("\n");
450470 }
451471
452472 /* Quantize/descale the coefficients, and store into coef_blocks[] */
@@ -540,6 +560,26 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
540560 /* Perform the DCT */
541561 (* do_dct ) (workspace );
542562
563+ /* Save unquantized transform coefficients for later trellis quantization */
564+ /* Currently save as integer values. Could save float values but would require */
565+ /* modifications to memory allocation and trellis quantization */
566+
567+ if (dst ) {
568+ int i ;
569+ static const double aanscalefactor [DCTSIZE ] = {
570+ 1.0 , 1.387039845 , 1.306562965 , 1.175875602 ,
571+ 1.0 , 0.785694958 , 0.541196100 , 0.275899379
572+ };
573+
574+ for (i = 0 ; i < DCTSIZE2 ; i ++ ) {
575+ float v = workspace [i ];
576+ v /= aanscalefactor [i %8 ];
577+ v /= aanscalefactor [i /8 ];
578+ int x = (v >= 0.0 ) ? (int )(v + 0.5 ) : (int )(v - 0.5 );
579+ dst [bi ][i ] = x ;
580+ }
581+ }
582+
543583 /* Quantize/descale the coefficients, and store into coef_blocks[] */
544584 (* do_quantize ) (coef_blocks [bi ], divisors , workspace );
545585 }
0 commit comments