5 #ifndef CHARLS_DECODERSTATEGY
6 #define CHARLS_DECODERSTATEGY
34 virtual size_t DecodeScan(
void* outputData,
const JlsRect& size,
const void* compressedData,
size_t byteCount,
bool bCheck) = 0;
36 void Init(BYTE* compressedBytes,
size_t byteCount)
40 _position = compressedBytes;
41 _endPosition = compressedBytes + byteCount;
42 _nextFFPosition = FindNextFF();
46 inlinehint
void Skip(LONG length)
49 _readCache = _readCache << length;
53 void OnLineBegin(LONG ,
void* , LONG )
57 void OnLineEnd(LONG pixelCount,
const void* ptypeBuffer, LONG pixelStride)
59 _processLine->NewLineDecoded(ptypeBuffer, pixelCount, pixelStride);
64 if ((*_position) != 0xFF)
68 if ((*_position) != 0xFF)
77 inlinehint
bool OptimizedRead()
80 if (_position < _nextFFPosition - (
sizeof(bufType)-1))
83 int bytesToRead = (bufferbits - _validBits) >> 3;
84 _position += bytesToRead;
85 _validBits += bytesToRead * 8;
86 ASSERT(_validBits >= bufferbits - 8);
92 typedef size_t bufType;
95 bufferbits =
sizeof( bufType ) * 8
100 ASSERT(_validBits <=bufferbits - 8);
107 if (_position >= _endPosition)
115 bufType valnew = _position[0];
120 if (_position == _endPosition - 1 || (_position[1] & 0x80) != 0)
129 _readCache |= valnew << (bufferbits - 8 - _validBits);
138 while (_validBits < bufferbits - 8);
140 _nextFFPosition = FindNextFF();
148 BYTE* pbyteNextFF = _position;
150 while (pbyteNextFF < _endPosition)
152 if (*pbyteNextFF == 0xFF)
164 BYTE* GetCurBytePos()
const
166 LONG validBits = _validBits;
167 BYTE* compressedBytes = _position;
171 LONG cbitLast = compressedBytes[-1] == 0xFF ? 7 : 8;
173 if (validBits < cbitLast )
174 return compressedBytes;
176 validBits -= cbitLast;
182 inlinehint LONG ReadValue(LONG length)
184 if (_validBits < length)
187 if (_validBits < length)
191 ASSERT(length != 0 && length <= _validBits);
193 LONG result = LONG(_readCache >> (bufferbits - length));
199 inlinehint LONG PeekByte()
206 return _readCache >> (bufferbits - 8);
211 inlinehint
bool ReadBit()
218 bool bSet = (_readCache & (bufType(1) << (bufferbits - 1))) != 0;
225 inlinehint LONG Peek0Bits()
231 bufType valTest = _readCache;
233 for (LONG count = 0; count < 16; count++)
235 if ((valTest & (bufType(1) << (bufferbits - 1))) != 0)
245 inlinehint LONG ReadHighbits()
247 LONG count = Peek0Bits();
255 for (LONG highbits = 15; ; highbits++)
263 LONG ReadLongValue(LONG length)
266 return ReadValue(length);
268 return (ReadValue(length - 24) << 24) + ReadValue(24);
280 BYTE* _nextFFPosition;