libpgf  7.15.32
PGF - Progressive Graphics File
CDecoder Class Reference

PGF decoder. More...

#include <Decoder.h>

Classes

class  CMacroBlock
 A macro block is a decoding unit of fixed size (uncoded) More...
 

Public Member Functions

 CDecoder (CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, UINT32 userDataPolicy)
 
 ~CDecoder ()
 Destructor. More...
 
void Partition (CSubband *band, int quantParam, int width, int height, int startPos, int pitch)
 
void DecodeInterleaved (CWaveletTransform *wtChannel, int level, int quantParam)
 
UINT32 GetEncodedHeaderLength () const
 
void SetStreamPosToStart ()
 Resets stream position to beginning of PGF pre-header. More...
 
void SetStreamPosToData ()
 Resets stream position to beginning of data block. More...
 
void Skip (UINT64 offset)
 
void DequantizeValue (CSubband *band, UINT32 bandPos, int quantParam)
 
UINT32 ReadEncodedData (UINT8 *target, UINT32 len) const
 
void DecodeBuffer ()
 
CPGFStreamGetStream ()
 
void GetNextMacroBlock ()
 

Private Member Functions

void ReadMacroBlock (CMacroBlock *block)
 throws IOException More...
 

Private Attributes

CPGFStreamm_stream
 input PGF stream More...
 
UINT64 m_startPos
 stream position at the beginning of the PGF pre-header More...
 
UINT64 m_streamSizeEstimation
 estimation of stream size More...
 
UINT32 m_encodedHeaderLength
 stream offset from startPos to the beginning of the data part (highest level) More...
 
CMacroBlock ** m_macroBlocks
 array of macroblocks More...
 
int m_currentBlockIndex
 index of current macro block More...
 
int m_macroBlockLen
 array length More...
 
int m_macroBlocksAvailable
 number of decoded macro blocks (including currently used macro block) More...
 
CMacroBlockm_currentBlock
 current macro block (used by main thread) More...
 

Detailed Description

PGF decoder.

PGF decoder class.

Author
C. Stamm, R. Spuler

Definition at line 46 of file Decoder.h.

Constructor & Destructor Documentation

◆ CDecoder()

CDecoder::CDecoder ( CPGFStream stream,
PGFPreHeader preHeader,
PGFHeader header,
PGFPostHeader postHeader,
UINT32 *&  levelLength,
UINT64 &  userDataPos,
bool  useOMP,
UINT32  userDataPolicy 
)

Constructor: Read pre-header, header, and levelLength at current stream position. It might throw an IOException.

Parameters
streamA PGF stream
preHeader[out] A PGF pre-header
header[out] A PGF header
postHeader[out] A PGF post-header
levelLengthThe location of the levelLength array. The array is allocated in this method. The caller has to delete this array.
userDataPosThe stream position of the user data (metadata)
useOMPIf true, then the decoder will use multi-threading based on openMP
userDataPolicyPolicy of user data (meta-data) handling while reading PGF headers.

Constructor Read pre-header, header, and levelLength It might throw an IOException.

Parameters
streamA PGF stream
preHeader[out] A PGF pre-header
header[out] A PGF header
postHeader[out] A PGF post-header
levelLengthThe location of the levelLength array. The array is allocated in this method. The caller has to delete this array.
userDataPosThe stream position of the user data (metadata)
useOMPIf true, then the decoder will use multi-threading based on openMP
userDataPolicyPolicy of user data (meta-data) handling while reading PGF headers.

Definition at line 73 of file Decoder.cpp.

76 : m_stream(stream)
77 , m_startPos(0)
82 #ifdef __PGFROISUPPORT__
83 , m_roi(false)
84 #endif
85 {
86  ASSERT(m_stream);
87 
88  int count, expected;
89 
90  // store current stream position
92 
93  // read magic and version
94  count = expected = MagicVersionSize;
95  m_stream->Read(&count, &preHeader);
96  if (count != expected) ReturnWithError(MissingData);
97 
98  // read header size
99  if (preHeader.version & Version6) {
100  // 32 bit header size since version 6
101  count = expected = 4;
102  } else {
103  count = expected = 2;
104  }
105  m_stream->Read(&count, ((UINT8*)&preHeader) + MagicVersionSize);
106  if (count != expected) ReturnWithError(MissingData);
107 
108  // make sure the values are correct read
109  preHeader.hSize = __VAL(preHeader.hSize);
110 
111  // check magic number
112  if (memcmp(preHeader.magic, PGFMagic, 3) != 0) {
113  // error condition: wrong Magic number
114  ReturnWithError(FormatCannotRead);
115  }
116 
117  // read file header
118  count = expected = (preHeader.hSize < HeaderSize) ? preHeader.hSize : HeaderSize;
119  m_stream->Read(&count, &header);
120  if (count != expected) ReturnWithError(MissingData);
121 
122  // make sure the values are correct read
123  header.height = __VAL(UINT32(header.height));
124  header.width = __VAL(UINT32(header.width));
125 
126  // be ready to read all versions including version 0
127  if (preHeader.version > 0) {
128 #ifndef __PGFROISUPPORT__
129  // check ROI usage
130  if (preHeader.version & PGFROI) ReturnWithError(FormatCannotRead);
131 #endif
132 
133  UINT32 size = preHeader.hSize;
134 
135  if (size > HeaderSize) {
136  size -= HeaderSize;
137  count = 0;
138 
139  // read post-header
140  if (header.mode == ImageModeIndexedColor) {
141  if (size < ColorTableSize) ReturnWithError(FormatCannotRead);
142  // read color table
143  count = expected = ColorTableSize;
144  m_stream->Read(&count, postHeader.clut);
145  if (count != expected) ReturnWithError(MissingData);
146  }
147 
148  if (size > (UINT32)count) {
149  size -= count;
150 
151  // read/skip user data
152  UserdataPolicy policy = (UserdataPolicy)((userDataPolicy <= MaxUserDataSize) ? UP_CachePrefix : 0xFFFFFFFF - userDataPolicy);
153  userDataPos = m_stream->GetPos();
154  postHeader.userDataLen = size;
155 
156  if (policy == UP_Skip) {
157  postHeader.cachedUserDataLen = 0;
158  postHeader.userData = nullptr;
159  Skip(size);
160  } else {
161  postHeader.cachedUserDataLen = (policy == UP_CachePrefix) ? __min(size, userDataPolicy) : size;
162 
163  // create user data memory block
164  postHeader.userData = new(std::nothrow) UINT8[postHeader.cachedUserDataLen];
165  if (!postHeader.userData) ReturnWithError(InsufficientMemory);
166 
167  // read user data
168  count = expected = postHeader.cachedUserDataLen;
169  m_stream->Read(&count, postHeader.userData);
170  if (count != expected) ReturnWithError(MissingData);
171 
172  // skip remaining user data
173  if (postHeader.cachedUserDataLen < size) Skip(size - postHeader.cachedUserDataLen);
174  }
175  }
176  }
177 
178  // create levelLength
179  levelLength = new(std::nothrow) UINT32[header.nLevels];
180  if (!levelLength) ReturnWithError(InsufficientMemory);
181 
182  // read levelLength
183  count = expected = header.nLevels*WordBytes;
184  m_stream->Read(&count, levelLength);
185  if (count != expected) ReturnWithError(MissingData);
186 
187 #ifdef PGF_USE_BIG_ENDIAN
188  // make sure the values are correct read
189  for (int i=0; i < header.nLevels; i++) {
190  levelLength[i] = __VAL(levelLength[i]);
191  }
192 #endif
193 
194  // compute the total size in bytes; keep attention: level length information is optional
195  for (int i=0; i < header.nLevels; i++) {
196  m_streamSizeEstimation += levelLength[i];
197  }
198 
199  }
200 
201  // store current stream position
203 
204  // set number of threads
205 #ifdef LIBPGF_USE_OPENMP
206  m_macroBlockLen = omp_get_num_procs();
207 #else
208  m_macroBlockLen = 1;
209 #endif
210 
211  if (useOMP && m_macroBlockLen > 1) {
212 #ifdef LIBPGF_USE_OPENMP
213  omp_set_num_threads(m_macroBlockLen);
214 #endif
215 
216  // create macro block array
217  m_macroBlocks = new(std::nothrow) CMacroBlock*[m_macroBlockLen];
218  if (!m_macroBlocks) ReturnWithError(InsufficientMemory);
219  for (int i = 0; i < m_macroBlockLen; i++) m_macroBlocks[i] = new CMacroBlock();
221  } else {
222  m_macroBlocks = 0;
223  m_macroBlockLen = 1; // there is only one macro block
224  m_currentBlock = new(std::nothrow) CMacroBlock();
225  if (!m_currentBlock) ReturnWithError(InsufficientMemory);
226  }
227 }
#define ImageModeIndexedColor
Definition: PGFplatform.h:100
virtual void Read(int *count, void *buffer)=0
UINT8 version
PGF version.
Definition: PGFtypes.h:115
UINT8 mode
image mode according to Adobe&#39;s image modes
Definition: PGFtypes.h:158
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:205
UINT32 width
image width in pixels
Definition: PGFtypes.h:152
#define ColorTableSize
Definition: PGFtypes.h:275
#define __VAL(x)
Definition: PGFplatform.h:601
UINT32 userDataLen
user data size in bytes (not part of file header)
Definition: PGFtypes.h:171
UINT8 * userData
user data of size userDataLen (optional part of file header)
Definition: PGFtypes.h:170
#define HeaderSize
Definition: PGFtypes.h:274
UINT8 nLevels
number of FWT transforms
Definition: PGFtypes.h:154
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition: Decoder.h:203
int m_macroBlockLen
array length
Definition: Decoder.h:207
#define PGFMagic
PGF identification.
Definition: PGFtypes.h:61
#define Version6
hSize in PGFPreHeader uses 32 bits instead of 16 bits
Definition: PGFtypes.h:72
UINT32 cachedUserDataLen
cached user data size in bytes (not part of file header)
Definition: PGFtypes.h:172
int m_currentBlockIndex
index of current macro block
Definition: Decoder.h:206
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:209
#define WordBytes
sizeof(UINT32)
Definition: PGFplatform.h:76
#define __min(x, y)
Definition: PGFplatform.h:91
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200
void Skip(UINT64 offset)
Definition: Decoder.cpp:449
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition: Decoder.h:208
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition: Decoder.h:201
virtual UINT64 GetPos() const =0
#define PGFROI
supports Regions Of Interest
Definition: PGFtypes.h:70
UserdataPolicy
Definition: PGFtypes.h:101
#define MagicVersionSize
Definition: PGFtypes.h:272
#define MaxUserDataSize
Definition: PGFtypes.h:277
UINT64 m_streamSizeEstimation
estimation of stream size
Definition: Decoder.h:202
UINT32 height
image height in pixels
Definition: PGFtypes.h:153
RGBQUAD clut[ColorTableLen]
color table for indexed color images (optional part of file header)
Definition: PGFtypes.h:169

◆ ~CDecoder()

CDecoder::~CDecoder ( )

Destructor.

Definition at line 231 of file Decoder.cpp.

231  {
232  if (m_macroBlocks) {
233  for (int i=0; i < m_macroBlockLen; i++) delete m_macroBlocks[i];
234  delete[] m_macroBlocks;
235  } else {
236  delete m_currentBlock;
237  }
238 }
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:205
int m_macroBlockLen
array length
Definition: Decoder.h:207
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:209

Member Function Documentation

◆ DecodeBuffer()

void CDecoder::DecodeBuffer ( )

Reads next block(s) from stream and decodes them It might throw an IOException.

Definition at line 494 of file Decoder.cpp.

494  {
495  ASSERT(m_macroBlocksAvailable <= 0);
496 
497  // macro block management
498  if (m_macroBlockLen == 1) {
499  ASSERT(m_currentBlock);
503  } else {
505  for (int i=0; i < m_macroBlockLen; i++) {
506  // read sequentially several blocks
507  try {
510  } catch(IOException& ex) {
511  if (ex.error == MissingData || ex.error == FormatCannotRead) {
512  break; // no further data available or the data isn't valid PGF data (might occur in streaming or PPPExt)
513  } else {
514  throw;
515  }
516  }
517  }
518 #ifdef LIBPGF_USE_OPENMP
519  // decode in parallel
520  #pragma omp parallel for default(shared) //no declared exceptions in next block
521 #endif
522  for (int i=0; i < m_macroBlocksAvailable; i++) {
524  }
525 
526  // prepare current macro block
529  }
530 }
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:205
int m_macroBlockLen
array length
Definition: Decoder.h:207
int m_currentBlockIndex
index of current macro block
Definition: Decoder.h:206
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:209
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition: Decoder.h:208
OSError error
operating system error code
Definition: PGFtypes.h:215
void ReadMacroBlock(CMacroBlock *block)
throws IOException
Definition: Decoder.cpp:535
PGF exception.
Definition: PGFtypes.h:208

◆ DecodeInterleaved()

void CDecoder::DecodeInterleaved ( CWaveletTransform wtChannel,
int  level,
int  quantParam 
)

Deccoding and dequantization of HL and LH subband (interleaved) using partitioning scheme. Partitioning scheme: The plane is partitioned in squares of side length InterBlockSize. It might throw an IOException.

Parameters
wtChannelA wavelet transform channel containing the HL and HL band
levelWavelet transform level
quantParamDequantization value

Definition at line 333 of file Decoder.cpp.

333  {
334  CSubband* hlBand = wtChannel->GetSubband(level, HL);
335  CSubband* lhBand = wtChannel->GetSubband(level, LH);
336  const div_t lhH = div(lhBand->GetHeight(), InterBlockSize);
337  const div_t hlW = div(hlBand->GetWidth(), InterBlockSize);
338  const int hlws = hlBand->GetWidth() - InterBlockSize;
339  const int hlwr = hlBand->GetWidth() - hlW.rem;
340  const int lhws = lhBand->GetWidth() - InterBlockSize;
341  const int lhwr = lhBand->GetWidth() - hlW.rem;
342  int hlPos, lhPos;
343  int hlBase = 0, lhBase = 0, hlBase2, lhBase2;
344 
345  ASSERT(lhBand->GetWidth() >= hlBand->GetWidth());
346  ASSERT(hlBand->GetHeight() >= lhBand->GetHeight());
347 
348  if (!hlBand->AllocMemory()) ReturnWithError(InsufficientMemory);
349  if (!lhBand->AllocMemory()) ReturnWithError(InsufficientMemory);
350 
351  // correct quantParam with normalization factor
352  quantParam -= level;
353  if (quantParam < 0) quantParam = 0;
354 
355  // main height
356  for (int i=0; i < lhH.quot; i++) {
357  // main width
358  hlBase2 = hlBase;
359  lhBase2 = lhBase;
360  for (int j=0; j < hlW.quot; j++) {
361  hlPos = hlBase2;
362  lhPos = lhBase2;
363  for (int y=0; y < InterBlockSize; y++) {
364  for (int x=0; x < InterBlockSize; x++) {
365  DequantizeValue(hlBand, hlPos, quantParam);
366  DequantizeValue(lhBand, lhPos, quantParam);
367  hlPos++;
368  lhPos++;
369  }
370  hlPos += hlws;
371  lhPos += lhws;
372  }
373  hlBase2 += InterBlockSize;
374  lhBase2 += InterBlockSize;
375  }
376  // rest of width
377  hlPos = hlBase2;
378  lhPos = lhBase2;
379  for (int y=0; y < InterBlockSize; y++) {
380  for (int x=0; x < hlW.rem; x++) {
381  DequantizeValue(hlBand, hlPos, quantParam);
382  DequantizeValue(lhBand, lhPos, quantParam);
383  hlPos++;
384  lhPos++;
385  }
386  // width difference between HL and LH
387  if (lhBand->GetWidth() > hlBand->GetWidth()) {
388  DequantizeValue(lhBand, lhPos, quantParam);
389  }
390  hlPos += hlwr;
391  lhPos += lhwr;
392  hlBase += hlBand->GetWidth();
393  lhBase += lhBand->GetWidth();
394  }
395  }
396  // main width
397  hlBase2 = hlBase;
398  lhBase2 = lhBase;
399  for (int j=0; j < hlW.quot; j++) {
400  // rest of height
401  hlPos = hlBase2;
402  lhPos = lhBase2;
403  for (int y=0; y < lhH.rem; y++) {
404  for (int x=0; x < InterBlockSize; x++) {
405  DequantizeValue(hlBand, hlPos, quantParam);
406  DequantizeValue(lhBand, lhPos, quantParam);
407  hlPos++;
408  lhPos++;
409  }
410  hlPos += hlws;
411  lhPos += lhws;
412  }
413  hlBase2 += InterBlockSize;
414  lhBase2 += InterBlockSize;
415  }
416  // rest of height
417  hlPos = hlBase2;
418  lhPos = lhBase2;
419  for (int y=0; y < lhH.rem; y++) {
420  // rest of width
421  for (int x=0; x < hlW.rem; x++) {
422  DequantizeValue(hlBand, hlPos, quantParam);
423  DequantizeValue(lhBand, lhPos, quantParam);
424  hlPos++;
425  lhPos++;
426  }
427  // width difference between HL and LH
428  if (lhBand->GetWidth() > hlBand->GetWidth()) {
429  DequantizeValue(lhBand, lhPos, quantParam);
430  }
431  hlPos += hlwr;
432  lhPos += lhwr;
433  hlBase += hlBand->GetWidth();
434  }
435  // height difference between HL and LH
436  if (hlBand->GetHeight() > lhBand->GetHeight()) {
437  // total width
438  hlPos = hlBase;
439  for (int j=0; j < hlBand->GetWidth(); j++) {
440  DequantizeValue(hlBand, hlPos, quantParam);
441  hlPos++;
442  }
443  }
444 }
bool AllocMemory()
Definition: Subband.cpp:77
Wavelet channel class.
Definition: Subband.h:42
int GetHeight() const
Definition: Subband.h:123
Definition: PGFtypes.h:99
Definition: PGFtypes.h:99
CSubband * GetSubband(int level, Orientation orientation)
#define InterBlockSize
side length of a coefficient block in a HL or LH subband
Definition: PGFtypes.h:87
int GetWidth() const
Definition: Subband.h:128
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam)
Definition: Decoder.cpp:462

◆ DequantizeValue()

void CDecoder::DequantizeValue ( CSubband band,
UINT32  bandPos,
int  quantParam 
)

Dequantization of a single value at given position in subband. It might throw an IOException.

Parameters
bandA subband
bandPosA valid position in subband band
quantParamThe quantization parameter

Dequantization of a single value at given position in subband. If encoded data is available, then stores dequantized band value into buffer m_value at position m_valuePos. Otherwise reads encoded data block and decodes it. It might throw an IOException.

Parameters
bandA subband
bandPosA valid position in subband band
quantParamThe quantization parameter

Definition at line 462 of file Decoder.cpp.

462  {
463  ASSERT(m_currentBlock);
464 
466  // all data of current macro block has been read --> prepare next macro block
468  }
469 
470  band->SetData(bandPos, m_currentBlock->m_value[m_currentBlock->m_valuePos] << quantParam);
472 }
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:79
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:77
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:209
bool IsCompletelyRead() const
Definition: Decoder.h:68
void GetNextMacroBlock()
Definition: Decoder.cpp:477
void SetData(UINT32 pos, DataT v)
Definition: Subband.h:102

◆ GetEncodedHeaderLength()

UINT32 CDecoder::GetEncodedHeaderLength ( ) const
inline

Returns the length of all encoded headers in bytes.

Returns
The length of all encoded headers in bytes

Definition at line 136 of file Decoder.h.

136 { return m_encodedHeaderLength; }
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition: Decoder.h:203

◆ GetNextMacroBlock()

void CDecoder::GetNextMacroBlock ( )

Gets next macro block It might throw an IOException.

Definition at line 477 of file Decoder.cpp.

477  {
478  // current block has been read --> prepare next current block
480 
481  if (m_macroBlocksAvailable > 0) {
483  } else {
484  DecodeBuffer();
485  }
486  ASSERT(m_currentBlock);
487 }
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:205
void DecodeBuffer()
Definition: Decoder.cpp:494
int m_currentBlockIndex
index of current macro block
Definition: Decoder.h:206
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:209
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition: Decoder.h:208

◆ GetStream()

CPGFStream* CDecoder::GetStream ( )
inline
Returns
Stream

Definition at line 174 of file Decoder.h.

174 { return m_stream; }
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200

◆ Partition()

void CDecoder::Partition ( CSubband band,
int  quantParam,
int  width,
int  height,
int  startPos,
int  pitch 
)

Unpartitions a rectangular region of a given subband. Partitioning scheme: The plane is partitioned in squares of side length LinBlockSize. Read wavelet coefficients from the output buffer of a macro block. It might throw an IOException.

Parameters
bandA subband
quantParamDequantization value
widthThe width of the rectangle
heightThe height of the rectangle
startPosThe relative subband position of the top left corner of the rectangular region
pitchThe number of bytes in row of the subband

Definition at line 266 of file Decoder.cpp.

266  {
267  ASSERT(band);
268 
269  const div_t ww = div(width, LinBlockSize);
270  const div_t hh = div(height, LinBlockSize);
271  const int ws = pitch - LinBlockSize;
272  const int wr = pitch - ww.rem;
273  int pos, base = startPos, base2;
274 
275  // main height
276  for (int i=0; i < hh.quot; i++) {
277  // main width
278  base2 = base;
279  for (int j=0; j < ww.quot; j++) {
280  pos = base2;
281  for (int y=0; y < LinBlockSize; y++) {
282  for (int x=0; x < LinBlockSize; x++) {
283  DequantizeValue(band, pos, quantParam);
284  pos++;
285  }
286  pos += ws;
287  }
288  base2 += LinBlockSize;
289  }
290  // rest of width
291  pos = base2;
292  for (int y=0; y < LinBlockSize; y++) {
293  for (int x=0; x < ww.rem; x++) {
294  DequantizeValue(band, pos, quantParam);
295  pos++;
296  }
297  pos += wr;
298  base += pitch;
299  }
300  }
301  // main width
302  base2 = base;
303  for (int j=0; j < ww.quot; j++) {
304  // rest of height
305  pos = base2;
306  for (int y=0; y < hh.rem; y++) {
307  for (int x=0; x < LinBlockSize; x++) {
308  DequantizeValue(band, pos, quantParam);
309  pos++;
310  }
311  pos += ws;
312  }
313  base2 += LinBlockSize;
314  }
315  // rest of height
316  pos = base2;
317  for (int y=0; y < hh.rem; y++) {
318  // rest of width
319  for (int x=0; x < ww.rem; x++) {
320  DequantizeValue(band, pos, quantParam);
321  pos++;
322  }
323  pos += wr;
324  }
325 }
#define LinBlockSize
side length of a coefficient block in a HH or LL subband
Definition: PGFtypes.h:86
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam)
Definition: Decoder.cpp:462

◆ ReadEncodedData()

UINT32 CDecoder::ReadEncodedData ( UINT8 *  target,
UINT32  len 
) const

Copies data from the open stream to a target buffer. It might throw an IOException.

Parameters
targetThe target buffer
lenThe number of bytes to read
Returns
The number of bytes copied to the target buffer

Definition at line 246 of file Decoder.cpp.

246  {
247  ASSERT(m_stream);
248 
249  int count = len;
250  m_stream->Read(&count, target);
251 
252  return count;
253 }
virtual void Read(int *count, void *buffer)=0
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200

◆ ReadMacroBlock()

void CDecoder::ReadMacroBlock ( CMacroBlock block)
private

throws IOException

Definition at line 535 of file Decoder.cpp.

535  {
536  ASSERT(block);
537 
538  UINT16 wordLen;
540  int count, expected;
541 
542 #ifdef TRACE
543  //UINT32 filePos = (UINT32)m_stream->GetPos();
544  //printf("DecodeBuffer: %d\n", filePos);
545 #endif
546 
547  // read wordLen
548  count = expected = sizeof(UINT16);
549  m_stream->Read(&count, &wordLen);
550  if (count != expected) ReturnWithError(MissingData);
551  wordLen = __VAL(wordLen); // convert wordLen
552  if (wordLen > BufferSize) ReturnWithError(FormatCannotRead);
553 
554 #ifdef __PGFROISUPPORT__
555  // read ROIBlockHeader
556  if (m_roi) {
557  count = expected = sizeof(ROIBlockHeader);
558  m_stream->Read(&count, &h.val);
559  if (count != expected) ReturnWithError(MissingData);
560  h.val = __VAL(h.val); // convert ROIBlockHeader
561  }
562 #endif
563  // save header
564  block->m_header = h;
565 
566  // read data
567  count = expected = wordLen*WordBytes;
568  m_stream->Read(&count, block->m_codeBuffer);
569  if (count != expected) ReturnWithError(MissingData);
570 
571 #ifdef PGF_USE_BIG_ENDIAN
572  // convert data
573  count /= WordBytes;
574  for (int i=0; i < count; i++) {
575  block->m_codeBuffer[i] = __VAL(block->m_codeBuffer[i]);
576  }
577 #endif
578 
579 #ifdef __PGFROISUPPORT__
580  ASSERT(m_roi && h.rbh.bufferSize <= BufferSize || h.rbh.bufferSize == BufferSize);
581 #else
582  ASSERT(h.rbh.bufferSize == BufferSize);
583 #endif
584 }
virtual void Read(int *count, void *buffer)=0
#define __VAL(x)
Definition: PGFplatform.h:601
#define BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
Definition: PGFtypes.h:84
Block header used with ROI coding scheme.
Definition: PGFtypes.h:179
#define WordBytes
sizeof(UINT32)
Definition: PGFplatform.h:76
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200

◆ SetStreamPosToData()

void CDecoder::SetStreamPosToData ( )
inline

Resets stream position to beginning of data block.

Definition at line 144 of file Decoder.h.

144 { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
virtual void SetPos(short posMode, INT64 posOff)=0
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition: Decoder.h:203
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition: Decoder.h:201

◆ SetStreamPosToStart()

void CDecoder::SetStreamPosToStart ( )
inline

Resets stream position to beginning of PGF pre-header.

Definition at line 140 of file Decoder.h.

140 { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
virtual void SetPos(short posMode, INT64 posOff)=0
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition: Decoder.h:201

◆ Skip()

void CDecoder::Skip ( UINT64  offset)

Skips a given number of bytes in the open stream. It might throw an IOException.

Definition at line 449 of file Decoder.cpp.

449  {
450  m_stream->SetPos(FSFromCurrent, offset);
451 }
virtual void SetPos(short posMode, INT64 posOff)=0
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200

Member Data Documentation

◆ m_currentBlock

CMacroBlock* CDecoder::m_currentBlock
private

current macro block (used by main thread)

Definition at line 209 of file Decoder.h.

◆ m_currentBlockIndex

int CDecoder::m_currentBlockIndex
private

index of current macro block

Definition at line 206 of file Decoder.h.

◆ m_encodedHeaderLength

UINT32 CDecoder::m_encodedHeaderLength
private

stream offset from startPos to the beginning of the data part (highest level)

Definition at line 203 of file Decoder.h.

◆ m_macroBlockLen

int CDecoder::m_macroBlockLen
private

array length

Definition at line 207 of file Decoder.h.

◆ m_macroBlocks

CMacroBlock** CDecoder::m_macroBlocks
private

array of macroblocks

Definition at line 205 of file Decoder.h.

◆ m_macroBlocksAvailable

int CDecoder::m_macroBlocksAvailable
private

number of decoded macro blocks (including currently used macro block)

Definition at line 208 of file Decoder.h.

◆ m_startPos

UINT64 CDecoder::m_startPos
private

stream position at the beginning of the PGF pre-header

Definition at line 201 of file Decoder.h.

◆ m_stream

CPGFStream* CDecoder::m_stream
private

input PGF stream

Definition at line 200 of file Decoder.h.

◆ m_streamSizeEstimation

UINT64 CDecoder::m_streamSizeEstimation
private

estimation of stream size

Definition at line 202 of file Decoder.h.


The documentation for this class was generated from the following files: