Constructor: Read pre-header, header, and levelLength at current stream position. It might throw an IOException.
83#ifdef __PGFROISUPPORT__
84 , m_roi(false)
85#endif
86 {
88
89 int count, expected;
90
91
93
94
97 if (count != expected) ReturnWithError(MissingData);
98
99
101
102 count = expected = 4;
103 } else {
104 count = expected = 2;
105 }
107 if (count != expected) ReturnWithError(MissingData);
108
109
110 preHeader.hSize =
__VAL(preHeader.hSize);
111
112
113 if (memcmp(preHeader.magic,
PGFMagic, 3) != 0) {
114
115 ReturnWithError(FormatCannotRead);
116 }
117
118
121 if (count != expected) ReturnWithError(MissingData);
122
123
124 header.height =
__VAL(uint32_t(header.height));
125 header.width =
__VAL(uint32_t(header.width));
126
127
128 if (preHeader.version > 0) {
129#ifndef __PGFROISUPPORT__
130
131 if (preHeader.version &
PGFROI) ReturnWithError(FormatCannotRead);
132#endif
133
134 uint32_t size = preHeader.hSize;
135
138 count = 0;
139
140
143
146 if (count != expected) ReturnWithError(MissingData);
147 }
148
149 if (size > (uint32_t)count) {
150 size -= count;
151
152
155 postHeader.userDataLen = size;
156
158 postHeader.cachedUserDataLen = 0;
159 postHeader.userData = nullptr;
161 } else {
162 postHeader.cachedUserDataLen = (policy ==
UP::CachePrefix) ?
__min(size, userDataPolicy) : size;
163
164
165 postHeader.userData = new(std::nothrow) uint8_t[postHeader.cachedUserDataLen];
166 if (!postHeader.userData) ReturnWithError(InsufficientMemory);
167
168
169 count = expected = postHeader.cachedUserDataLen;
171 if (count != expected) ReturnWithError(MissingData);
172
173
174 if (postHeader.cachedUserDataLen < size)
Skip(size - postHeader.cachedUserDataLen);
175 }
176 }
177 }
178
179
180 levelLength = new(std::nothrow) uint32_t[header.nLevels];
181 if (!levelLength) ReturnWithError(InsufficientMemory);
182
183
184 count = expected = header.nLevels*
WordBytes;
186 if (count != expected) ReturnWithError(MissingData);
187
188#ifdef PGF_USE_BIG_ENDIAN
189
190 for (int i = 0; i < header.nLevels; i++) {
191 levelLength[i] =
__VAL(levelLength[i]);
192 }
193#endif
194
195
196 for (int i = 0; i < header.nLevels; i++) {
198 }
199
200 }
201
202
204
205
206#ifdef LIBPGF_USE_OPENMP
208#else
210#endif
211
213#ifdef LIBPGF_USE_OPENMP
215#endif
216
217
222 } else {
227 }
228 }
A macro block is a decoding unit of fixed size (uncoded).
CMacroBlock()
Constructor: Initializes new macro block.
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
CMacroBlock ** m_macroBlocks
array of macroblocks
void Skip(uint64_t offset)
int m_currentBlockIndex
index of current macro block
int m_macroBlockLen
array length
CPGFStream * m_stream
input PGF stream
uint64_t m_streamSizeEstimation
estimation of stream size
uint32_t m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
uint64_t m_startPos
stream position at the beginning of the PGF pre-header
CMacroBlock * m_currentBlock
current macro block (used by main thread)
virtual void Read(int *count, void *buffer)=0
virtual uint64_t GetPos() const =0
constexpr Policy CachePrefix
constexpr size_t HeaderSize
constexpr size_t MagicVersionSize
constexpr size_t MaxUserDataSize
constexpr const char * PGFMagic
PGF identification.
constexpr int Version6
hSize in PGFPreHeader uses 32 bits instead of 16 bits
constexpr size_t ColorTableSize
constexpr int PGFROI
supports Regions Of Interest