home *** CD-ROM | disk | FTP | other *** search
- #include <math.h>
- #include "matrix.h"
- #include "jpdedu.h"
-
- using namespace std ;
-
- //
- // Description:
- //
- // The IDCT process can produce rounding errors that result in sample
- // values being outside the legal range. This function clamps
- // sample value into the legal range.
- //
- // Unclamped values give strange results when converted to bytes.
- // -1 (0xFFFFFFFF) would be converted to 255 (0xFF) instead of 0 and
- // 256 (0x00000100) gets converted to 0.
- //
- // Parameters:
- // value: The value to clamp
- //
- // Return Value:
- // "value" clamped to MinSampleValue..MaxSampleValue
- //
-
- static inline JPEGSAMPLE SampleRange (long value)
- {
- if (value < JpegMinSampleValue)
- return JpegMinSampleValue ;
- else if (value > JpegMaxSampleValue)
- return JpegMaxSampleValue ;
- else
- return (JPEGSAMPLE) value ;
- }
-
- //
- // Description:
- //
- // This function descales a scaled integer value.
- //
- // This implementation is simplay a shift operation. We
- // use an inline function to give one place to change in case
- // we want to switch to a rounded scale.
- //
- // Parameters:
- // value: The value to descale
- // amount: The amount to descale
- //
- // Return Value:
- // The descaled value.
- //
- static inline long Descale (long value, int amount)
- {
- // A more precise value would be
- // result = (value + (1 << (amount - 1))) >> amount ;
- return value >> amount ;
- }
-
- //
- // Description:
- //
- // Class Copy Constructor
- //
- JpegDecoderDataUnit::JpegDecoderDataUnit(const JpegDecoderDataUnit &du)
- {
- memcpy (values, du.values, sizeof (values)) ;
- return ;
- }
-
- //
- // Description:
- //
- // Class assignment operator
- //
- JpegDecoderDataUnit &JpegDecoderDataUnit::operator=(const JpegDecoderDataUnit&du)
- {
- memcpy (values, du.values, sizeof (values)) ;
- return *this ;
- }
-
- JpegDecoderDataUnit &JpegDecoderDataUnit::InverseDCT (
- const JpegDecoderCoefficientBlock data,
- const JpegDecoderQuantizationTable &qt)
- {
- InitializeDctMatrix () ;
-
- MATRIX source, temp, destination ;
- unsigned int ii, jj ;
- for (ii = 0 ; ii < JpegSampleWidth ; ++ ii)
- {
- for (jj = 0 ; jj < JpegSampleWidth ; ++ jj)
- {
- source [ii][jj] = data [ii][jj]
- * qt [JpegZigZagOutputOrder (ii * JpegSampleWidth + jj)] ;
- }
- }
- Multiply (IDctMatrix, source, temp) ;
- Multiply (temp, DctMatrix, destination) ;
- for (ii = 0 ; ii < JpegSampleWidth ; ++ ii)
- {
- for (jj = 0 ; jj < JpegSampleWidth ; ++ jj)
- {
- values [ii][jj] = SampleRange (destination [ii][jj] + 0.5 + JpegMidpointSampleValue) ;
- }
- }
- return *this ;
- }
-
- void JpegDecoderDataUnit::Print (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 ;
- }
-
-
-
-