jcdctmgr.c
/*
 * Perform forward DCT on one or more blocks of a component.
 *
 * The input samples are taken from the sample_data[] array starting at
 * position start_row/start_col, and moving to the right for any additional
 * blocks. The quantized coefficients are returned in coef_blocks[].
 */
Perform forward DCT on one or more blocks of a component.
The input samples are taken from the sample_data[] array starting at
position start_row/start_col, and moving to the right for any additional
blocks. The quantized coefficients are returned in coef_blocks[].
Perform forward DCT on one or more blocks of a component . The input samples are taken from the sample_data [] array starting at position start_row / start_col and moving to the right for any additional blocks . The quantized coefficients are returned in coef_blocks [] .
METHODDEF(void)
forward_DCT (j_compress_ptr cinfo, jpeg_component_info *compptr,
             JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
             JDIMENSION start_row, JDIMENSION start_col,
             JDIMENSION num_blocks, JBLOCKROW dst)
{
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  DCTELEM *divisors = fdct->divisors[compptr->quant_tbl_no];
  JQUANT_TBL *qtbl = cinfo->quant_tbl_ptrs[compptr->quant_tbl_no];
  DCTELEM *workspace;
  JDIMENSION bi;
  forward_DCT_method_ptr do_dct = fdct->dct;
  convsamp_method_ptr do_convsamp = fdct->convsamp;
  preprocess_method_ptr do_preprocess = fdct->preprocess;
  quantize_method_ptr do_quantize = fdct->quantize;
  workspace = fdct->workspace;
  sample_data += start_row;     
  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
    (*do_convsamp) (sample_data, start_col, workspace);
    if (do_preprocess) {
      (*do_preprocess) (workspace, qtbl);
    }
    (*do_dct) (workspace);
    if (dst) {
      int i;
      if (cinfo->dct_method == JDCT_IFAST) {
        static const INT16 aanscales[DCTSIZE2] = {
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
          22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,
          21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,
          19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,
          16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,
          12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,
          8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,
          4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247
        };
        for (i = 0; i < DCTSIZE2; i++) {
          int x = workspace[i];
          int s = aanscales[i];
          x = (x >= 0) ? (x * 32768 + s) / (2*s) : (x * 32768 - s) / (2*s);
          dst[bi][i] = x;
        }
      } else {
        for (i = 0; i < DCTSIZE2; i++) {
          dst[bi][i] = workspace[i];
        }
      }
    }
    (*do_quantize) (coef_blocks[bi], divisors, workspace);
    if (do_preprocess) {
      int i;
      int maxval = (1 << MAX_COEF_BITS) - 1;
      for (i = 0; i < 64; i++) {
        if (coef_blocks[bi][i] < -maxval)
          coef_blocks[bi][i] = -maxval;
        if (coef_blocks[bi][i] > maxval)
          coef_blocks[bi][i] = maxval;
  }
  }
}
}
METHODDEF ( void ) forward_DCT ( j_compress_ptr cinfo , jpeg_component_info * compptr , JSAMPARRAY sample_data , JBLOCKROW coef_blocks , JDIMENSION start_row , JDIMENSION start_col , JDIMENSION num_blocks , JBLOCKROW dst ) { my_fdct_ptr fdct = ( my_fdct_ptr ) cinfo -> fdct ; DCTELEM * divisors = fdct -> divisors [ compptr -> quant_tbl_no ] ; JQUANT_TBL * qtbl = cinfo -> quant_tbl_ptrs [ compptr -> quant_tbl_no ] ; DCTELEM * workspace ; JDIMENSION bi ; forward_DCT_method_ptr do_dct = fdct -> dct ; convsamp_method_ptr do_convsamp = fdct -> convsamp ; preprocess_method_ptr do_preprocess = fdct -> preprocess ; quantize_method_ptr do_quantize = fdct -> quantize ; workspace = fdct -> workspace ; sample_data += start_row ; for ( bi = 0 ; bi < num_blocks ; bi ++ , start_col += DCTSIZE ) { ( * do_convsamp ) ( sample_data , start_col , workspace ) ; if ( do_preprocess ) { ( * do_preprocess ) ( workspace , qtbl ) ; } ( * do_dct ) ( workspace ) ; if ( dst ) { int i ; if ( cinfo -> dct_method == JDCT_IFAST ) { static const INT16 aanscales [ DCTSIZE2 ] = { 16384 , 22725 , 21407 , 19266 , 16384 , 12873 , 8867 , 4520 , 22725 , 31521 , 29692 , 26722 , 22725 , 17855 , 12299 , 6270 , 21407 , 29692 , 27969 , 25172 , 21407 , 16819 , 11585 , 5906 , 19266 , 26722 , 25172 , 22654 , 19266 , 15137 , 10426 , 5315 , 16384 , 22725 , 21407 , 19266 , 16384 , 12873 , 8867 , 4520 , 12873 , 17855 , 16819 , 15137 , 12873 , 10114 , 6967 , 3552 , 8867 , 12299 , 11585 , 10426 , 8867 , 6967 , 4799 , 2446 , 4520 , 6270 , 5906 , 5315 , 4520 , 3552 , 2446 , 1247 } ; for ( i = 0 ; i < DCTSIZE2 ; i ++ ) { int x = workspace [ i ] ; int s = aanscales [ i ] ; x = ( x >= 0 ) ? ( x * 32768 + s ) / ( 2 * s ) : ( x * 32768 - s ) / ( 2 * s ) ; dst [ bi ] [ i ] = x ; } } else { for ( i = 0 ; i < DCTSIZE2 ; i ++ ) { dst [ bi ] [ i ] = workspace [ i ] ; } } } ( * do_quantize ) ( coef_blocks [ bi ] , divisors , workspace ) ; if ( do_preprocess ) { int i ; int maxval = ( 1 << MAX_COEF_BITS ) - 1 ; for ( i = 0 ; i < 64 ; i ++ ) { if ( coef_blocks [ bi ] [ i ] < - maxval ) coef_blocks [ bi ] [ i ] = - maxval ; if ( coef_blocks [ bi ] [ i ] > maxval ) coef_blocks [ bi ] [ i ] = maxval ; } } } }
Perform forward DCT on one or more blocks of a component.
Perform forward DCT on one or more blocks of a component .
/* This version is used for integer DCT implementations. */ /* This routine is heavily used, so it's worth coding it tightly. */ /* Make sure the compiler doesn't look up these every pass */ /* fold in the vertical offset once */ /* Load data into workspace, applying unsigned->signed conversion */ /* Perform the DCT */ /* Save unquantized transform coefficients for later trellis quantization */ /* precomputed values scaled up by 14 bits */ /* Quantize/descale the coefficients, and store into coef_blocks[] */