⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpgdecoderdataunit.cpp

📁 Jpeg编解码器的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    double f0 = e0 ;
    double f1 = e1 ;
    double f2 = e2 ;
    double f3 = e3 ;
    double f4 = e4 ;
    double f5 = e5 ;
    double f6 = e4 + e6 ;
    double f7 = e7 ;

    double g0 = f0 ;
    double g1 = f1 ;
    double g2 = f2 ;
    double g3 = f2 + f3 ;
    double g4 = f4 ;
    double g5 = f4 + f5 ;
    double g6 = f5 + f6 ;
    double g7 = f6 + f7 ;

    double h0 = g0 + g3 ;
    double h1 = g1 + g2 ;
    double h2 = g1 - g2 ;
    double h3 = g0 - g3 ;
    double h4 = g4 ;
    double h5 = g5 ;
    double h6 = g6 ;
    double h7 = g7 ;

    double rounding = JPEGMIDPOINTSAMPLEVALUE + 0.5 ;
    values [0][ii] = SampleRange ((long)((h0 + h7) + rounding)) ;
    values [1][ii] = SampleRange ((long)((h1 + h6) + rounding)) ;
    values [2][ii] = SampleRange ((long)((h2 + h5) + rounding)) ;
    values [3][ii] = SampleRange ((long)((h3 + h4) + rounding)) ;
    values [4][ii] = SampleRange ((long)((h3 - h4) + rounding)) ;
    values [5][ii] = SampleRange ((long)((h2 - h5) + rounding)) ;
    values [6][ii] = SampleRange ((long)((h1 - h6) + rounding)) ;
    values [7][ii] = SampleRange ((long)((h0 - h7) + rounding)) ;
  }
  return *this ;
}

//
//  Description:
//
//    This is a scaled integer implementation of the Inverse
//    Discrete Cosine Transform (IDCT).
//
//    This implementation uses a factorization of the DCT matrix.
//    The first steps in this factorization is a matrix multiplication
//    is the multiplication of each row/column by a scale. This
//    scalor multipliation has been combined with quantization
//    to eliminate 128 multiplication steps.
//
//    We use a lot of temporaries here in order to clearly
//    show the matrix multiplication steps.  Hopefully
//    your compiler will optimize out the unnecessary
//    intermediate variables.
//
//    If your compiler does not aggressively optimize. It is possible
//    to reorder the operations to reduce the number of temporaries
//    required.
//
//  Parameters:
//    data: The 8x8 matrix to perform the IDCT on.
//    qt: The prescaled quantization table.
//
JpegDecoderDataUnit &JpegDecoderDataUnit::integerInverseDCT (
                          const JpegCoefficientBlock data,
                          const JpegDecoderQuantizationTable  &qt)
{
  unsigned int ii ;
  long tmp [JPEGSAMPLESIZE] ;

  for (ii = 0 ; ii < JPEGSAMPLESIZE ; ii += JPEGSAMPLEWIDTH)
  {
    // This optimization does not seem to be worth the trouble in the
    // second loop.
    if ((data [ii+1] | data [ii+2] | data [ii+3] | data [ii+4] |
        data [ii+5] | data [ii+6] | data [ii+7]) == 0)
    {
      tmp [ii] = data [ii] * qt.integer_scaling [ii] ;
      tmp [ii+1] = tmp [ii] ;
      tmp [ii+2] = tmp [ii] ;
      tmp [ii+3] = tmp [ii] ;
      tmp [ii+4] = tmp [ii] ;
      tmp [ii+5] = tmp [ii] ;
      tmp [ii+6] = tmp [ii] ;
      tmp [ii+7] = tmp [ii] ;
    }
    else
    {
      long a0 = data [ii+0] * qt.integer_scaling [ii+0] ;
      long a1 = data [ii+4] * qt.integer_scaling [ii+4] ;
      long a2 = data [ii+2] * qt.integer_scaling [ii+2] ;
      long a3 = data [ii+6] * qt.integer_scaling [ii+6] ;
      long a4 = data [ii+1] * qt.integer_scaling [ii+1] ;
      long a5 = data [ii+5] * qt.integer_scaling [ii+5] ;
      long a6 = data [ii+3] * qt.integer_scaling [ii+3] ;
      long a7 = data [ii+7] * qt.integer_scaling [ii+7] ;

      long b0 = a0 ;
      long b1 = a1 ;
      long b2 = a2 - a3 ;
      long b3 = a2 + a3 ;
      long b4 = a4 - a7 ;
      long b5 = a5 + a6;
      long b6 = a5 - a6 ;
      long b7 = a4 + a7 ;

      long c0 = b0 ;
      long c1 = b1 ;
      long c2 = b2 ;
      long c3 = b3 ;
      long c4 = Descale (ISEC2 * b4, IntegerScale) ;
      long c5 = b7 - b5 ;
      long c6 = Descale (ISEC6 * b6, IntegerScale) ;
      long c7 = b5 + b7 ;

      long d0 = c0 ;
      long d1 = c1 ;
      long d2 = c2 ;
      long d3 = c3 ;
      long d4 = c4 + c6 ;
      long d5 = c5 ;
      long d6 = c4 - c6 ;
      long d7 = c7 ;

      long e0 = d0 + d1 ;
      long e1 = d0 - d1 ;
      long e2 = Descale (d2 * IC4, IntegerScale) ;
      long e3 = d3 ;
      long e4 = Descale (d4 * IC4, IntegerScale) ;
      long e5 = Descale (d5 * IC4, IntegerScale) ;
      long e6 = d6 ;
      long e7 = d7 ;

      long f0 = e0 ;
      long f1 = e1 ;
      long f2 = e2 ;
      long f3 = e3 ;
      long f4 = e4 ;
      long f5 = e5 ;
      long f6 = e4 + e6 ;
      long f7 = e7 ;

      long g0 = f0 ;
      long g1 = f1 ;
      long g2 = f2 ;
      long g3 = f2 + f3 ;
      long g4 = f4 ;
      long g5 = f4 + f5 ;
      long g6 = f5 + f6 ;
      long g7 = f6 + f7 ;

      long h0 = g0 + g3 ;
      long h1 = g1 + g2 ;
      long h2 = g1 - g2 ;
      long h3 = g0 - g3 ;
      long h4 = g4 ;
      long h5 = g5 ;
      long h6 = g6 ;
      long h7 = g7 ;

      tmp [ii] = h0 + h7 ;
      tmp [ii+1] = h1 + h6 ;
      tmp [ii+2] = h2 + h5 ;
      tmp [ii+3] = h3 + h4 ;
      tmp [ii+4] = h3 - h4 ;
      tmp [ii+5] = h2 - h5 ;
      tmp [ii+6] = h1 - h6 ;
      tmp [ii+7] = h0 - h7 ;
    }
  }

  for (ii = 0 ; ii < JPEGSAMPLEWIDTH ; ++ ii)
  {
    long a0 = tmp [ii] ;
    long a1 = tmp [ii+32] ;
    long a2 = tmp [ii+16] ;
    long a3 = tmp [ii+48] ;
    long a4 = tmp [ii+8] ;
    long a5 = tmp [ii+40] ;
    long a6 = tmp [ii+24] ;
    long a7 = tmp [ii+56] ;

    long b0 = a0 ;
    long b1 = a1 ;
    long b2 = a2 - a3 ;
    long b3 = a2 + a3 ;
    long b4 = a4 - a7 ;
    long b5 = a5 + a6;
    long b6 = a5 - a6 ;
    long b7 = a4 + a7 ;

    long c0 = b0 ;
    long c1 = b1 ;
    long c2 = b2 ;
    long c3 = b3 ;
    long c4 = Descale (ISEC2 * b4, IntegerScale) ;
    long c5 = b7 - b5 ;
    long c6 = Descale (ISEC6 * b6, IntegerScale) ;
    long c7 = b5 + b7 ;

    long d0 = c0 ;
    long d1 = c1 ;
    long d2 = c2 ;
    long d3 = c3 ;
    long d4 = c4 + c6 ;
    long d5 = c5 ;
    long d6 = c4 - c6 ;
    long d7 = c7 ;

    long e0 = d0 + d1 ;
    long e1 = d0 - d1 ;
    long e2 = Descale (d2 * IC4, IntegerScale) ;
    long e3 = d3 ;
    long e4 = Descale (d4 * IC4, IntegerScale) ;
    long e5 = Descale (d5 * IC4, IntegerScale) ;
    long e6 = d6 ;
    long e7 = d7 ;

    long f0 = e0 ;
    long f1 = e1 ;
    long f2 = e2 ;
    long f3 = e3 ;
    long f4 = e4 ;
    long f5 = e5 ;
    long f6 = e4 + e6 ;
    long f7 = e7 ;

    const long rounding = (JPEGMAXSAMPLEVALUE + 2) << (JpegDecoderQuantizationTable::QuantizationIntegerScale-1) ;
    long g0 = f0 + rounding ;
    long g1 = f1 + rounding ;
    long g2 = f2 ;
    long g3 = f2 + f3 ;
    long g4 = f4 ;
    long g5 = f4 + f5 ;
    long g6 = f5 + f6 ;
    long g7 = f6 + f7 ;

    long h0 = g0 + g3 ;
    long h1 = g1 + g2 ;
    long h2 = g1 - g2 ;
    long h3 = g0 - g3 ;
    long h4 = g4 ;
    long h5 = g5 ;
    long h6 = g6 ;
    long h7 = g7 ;

    values [0][ii] = SampleRange (Descale (h0 + h7, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [1][ii] = SampleRange (Descale (h1 + h6, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [2][ii] = SampleRange (Descale (h2 + h5, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [3][ii] = SampleRange (Descale (h3 + h4, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [4][ii] = SampleRange (Descale (h3 - h4, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [5][ii] = SampleRange (Descale (h2 - h5, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [6][ii] = SampleRange (Descale (h1 - h6, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
    values [7][ii] = SampleRange (Descale (h0 - h7, JpegDecoderQuantizationTable::QuantizationIntegerScale)) ;
  }
  return *this ;
}

//
//  Description:
//
//    This function writes the contents of the data unit to a stream.
//    It is only for debugging.
//
//  Parameters:
//    strm:  The output stream
//
void JpegDecoderDataUnit::printOn (std::ostream &strm) const
{
  for (int ii = 0 ; ii < JPEGSAMPLEWIDTH ; ++ ii)
  {
    for (int jj = 0 ; jj < JPEGSAMPLEWIDTH ; ++ jj)
    {
      strm << (int) values [ii][jj] << " " ;
    }
    strm << endl ;
  }
  return ;
}



} // End Namespace ColosseumPrivate


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -