libpgf 7.26.45
PGF - Progressive Graphics File
Loading...
Searching...
No Matches
PGFtypes.h
Go to the documentation of this file.
1/*
2 * The Progressive Graphics File; http://www.libpgf.org
3 *
4 * $Date: 2007-06-11 10:56:17 +0200 (Mo, 11 Jun 2007) $
5 * $Revision: 299 $
6 *
7 * This file Copyright (C) 2006 xeraina GmbH, Switzerland
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
28
29#pragma once
30
31#include "PGFplatform.h"
32
33//-------------------------------------------------------------------------------
34// Codec versions
35//
36// Version 2: modified data structure PGFHeader (backward compatibility assured)
37// Version 4: DataT: int32_t instead of int16_t, allows 30 bit per pixel and channel (backward compatibility assured)
38// Version 5: ROI, new block-reordering scheme (backward compatibility assured)
39// Version 6: modified data structure PGFPreHeader: hSize (header size) is now a uint32_t instead of a uint16_t (backward compatibility assured)
40// Version 7: last two bytes in header are now used for extended version numbers; new data representation for bitmaps (backward compatibility assured)
41//
42//-------------------------------------------------------------------------------
43#define PGFMajorNumber 7
44#define PGFYear 26 // leading zeros are possible
45#define PGFWeek 45 // leading zeros are possible
46
47#define PPCAT_NX(A, B) A ## B
48#define PPCAT(A, B) PPCAT_NX(A, B)
49#define STRINGIZE_NX(A) #A
50#define STRINGIZE(A) STRINGIZE_NX(A)
51
52//#define PGFCodecVersionID 0x072102
53#define PGFCodecVersionID PPCAT(PPCAT(PPCAT(0x0, PGFMajorNumber), PGFYear), PGFWeek)
54//#define PGFCodecVersion "7.21.02" ///< Major number, Minor number: Year (2) Week (2)
55#define PGFCodecVersion STRINGIZE(PPCAT(PPCAT(PPCAT(PPCAT(PGFMajorNumber, .), PGFYear), .), PGFWeek))
56
57namespace pgf {
58 //-------------------------------------------------------------------------------
59 // Image constants
60 //-------------------------------------------------------------------------------
61 constexpr const char* PGFMagic = "PGF";
62 constexpr int MaxLevel = 30;
63 constexpr int NSubbands = 4;
64 constexpr int MaxChannels = 8;
65 constexpr int DownsampleThreshold = 3;
66 constexpr int ColorTableLen = 256;
67 // version flags
68 constexpr int Version2 = 2;
69 constexpr int PGF32 = 4;
70 constexpr int PGFROI = 8;
71 constexpr int Version5 = 16;
72 constexpr int Version6 = 32;
73 constexpr int Version7 = 64;
74 // version numbers
75 #ifdef __PGF32SUPPORT__
76 constexpr int PGFVersion = (Version2 | PGF32 | Version5 | Version6 | Version7);
77 #else
78 constexpr int PGFVersion = (Version2 | Version5 | Version6 | Version7);
79 #endif
80
81 //-------------------------------------------------------------------------------
82 // Coder constants
83 //-------------------------------------------------------------------------------
84 constexpr uint32_t BufferSize = 16384;
85 constexpr uint32_t BufferLen = BufferSize/WordWidth;
86 constexpr uint32_t CodeBufferLen = BufferSize;
87 constexpr int RLblockSizeLen = 15;
88 constexpr int LinBlockSize = 8;
89 constexpr int InterBlockSize = 4;
90 #ifdef __PGF32SUPPORT__
91 constexpr int MaxBitPlanes = 31;
92 #else
93 constexpr int MaxBitPlanes = 15;
94 #endif
95 constexpr int MaxBitPlanesLog = 5;
96 constexpr int MaxQuality = MaxBitPlanes;
97
98 //-------------------------------------------------------------------------------
99 // Types
100 //-------------------------------------------------------------------------------
101 namespace Orient {
102 using Orientation = uint8_t;
103
104 constexpr Orientation LL = 0;
105 constexpr Orientation HL = 1;
106 constexpr Orientation LH = 2;
107 constexpr Orientation HH = 3;
108 }
109 namespace UP {
110 using Policy = uint32_t;
111
112 constexpr Policy Skip = 0, CachePrefix = 1, CacheAll = 2;
113 }
115
120
121#pragma pack(1)
127 char magic[3]{};
128 uint8_t version{};
129 };
130 static_assert(sizeof(PGFMagicVersion) == 4, "wrong number of bytes");
131
137 uint32_t hSize{};
138 };
139 static_assert(sizeof(PGFPreHeader) == 8, "wrong number of bytes");
140
146#ifdef PGF_USE_BIG_ENDIAN
147 uint16_t week : 6;
148 uint16_t year : 6;
149 uint16_t major : 4;
150#else
151 uint16_t major : 4;
152 uint16_t year : 6;
153 uint16_t week : 6;
154#endif // PGF_USE_BIG_ENDIAN
155
156 PGFVersionNumber(uint8_t _major, uint8_t _year, uint8_t _week)
157 : major(_major)
158 , year(_year)
159 , week(_week)
160 {
161 }
162 };
163 static_assert(sizeof(PGFVersionNumber) == 2, "wrong number of bytes");
164
169 struct PGFHeader {
170 uint32_t width;
171 uint32_t height;
172 uint8_t nLevels;
173 uint8_t quality;
174 uint8_t bpp;
175 uint8_t channels;
176 uint8_t mode;
179
181 : width(0)
182 , height(0)
183 , nLevels(0)
184 , quality(0)
185 , bpp(0)
186 , channels(0)
189 , version(0, 0, 0)
190 {
191 }
192 };
193 static_assert(sizeof(PGFHeader) == 16, "wrong number of bytes");
194
200 RGBQUAD clut[ColorTableLen]{};
201 uint8_t* userData{};
202 uint32_t userDataLen{};
203 uint32_t cachedUserDataLen{};
204 };
205 static_assert(sizeof(PGFPostHeader) == 1040, "wrong number of bytes");
206
212 uint16_t val;
214 struct RBH {
215#ifdef PGF_USE_BIG_ENDIAN
216 uint16_t tileEnd : 1;
217 uint16_t bufferSize : RLblockSizeLen;
218#else
220 uint16_t tileEnd : 1;
221#endif // PGF_USE_BIG_ENDIAN
222 } rbh;
223 // total: 2 Bytes
224
227 ROIBlockHeader(uint16_t v) { val = v; }
228
232 ROIBlockHeader(uint32_t size, bool end) { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
233 };
234 static_assert(sizeof(ROIBlockHeader::RBH) == 2, "wrong number of bytes");
235 static_assert(sizeof(ROIBlockHeader) == 2, "wrong number of bytes");
236
237#pragma pack()
238
243 struct IOException {
244 OSError error;
245
247 IOException() : error(NoError) {}
248
251 IOException(OSError err) : error(err) {}
252 };
253
258 struct PGFRect {
259 uint32_t left, top, right, bottom;
260
263 : left(0)
264 , top(0)
265 , right(0)
266 , bottom(0)
267 {}
268
274 PGFRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
275 : left(x)
276 , top(y)
277 , right(x + width)
278 , bottom(y + height)
279 {}
280
281#ifdef WIN32
282 PGFRect(const RECT& rect)
283 : left(rect.left)
284 , top(rect.top)
285 , right(rect.right)
286 , bottom(rect.bottom)
287 {
288 ASSERT(rect.left >= 0 && rect.right >= 0 && rect.left <= rect.right);
289 ASSERT(rect.top >= 0 && rect.bottom >= 0 && rect.top <= rect.bottom);
290 }
291
292 PGFRect& operator=(const RECT& rect) {
293 left = rect.left; top = rect.top; right = rect.right; bottom = rect.bottom;
294 return *this;
295 }
296
297 operator RECT() {
298 RECT rect = { (LONG)left, (LONG)top, (LONG)right, (LONG)bottom };
299 return rect;
300 }
301#endif
302
304 uint32_t Width() const { return right - left; }
305
307 uint32_t Height() const { return bottom - top; }
308
313 bool IsInside(uint32_t x, uint32_t y) const { return (x >= left && x < right && y >= top && y < bottom); }
314
321 void Offset(int32_t shiftH, int32_t shiftV) {
322 left += shiftH;
323 top += shiftV;
324 right += shiftH;
325 bottom += shiftV;
326 }
327
335 friend bool Intersect(const PGFRect& rect1, const PGFRect& rect2, PGFRect& resultRect) {
336 if ((rect1.right > rect2.left) && (rect2.right > rect1.left) &&
337 (rect1.bottom > rect2.top) && (rect2.bottom > rect1.top)) {
338
339 resultRect.left = __max(rect1.left, rect2.left);
340 resultRect.top = __max(rect1.top, rect2.top);
341 resultRect.right = __min(rect1.right, rect2.right);
342 resultRect.bottom = __min(rect1.bottom, rect2.bottom);
343 return true;
344 } else { // no intersection
345 resultRect.left = resultRect.top = resultRect.right = resultRect.bottom = 0;
346 return false;
347 }
348 }
349
356 bool operator==(const PGFRect& rect2) const {
357 return (bottom == rect2.bottom && left == rect2.left && right == rect2.right && top == rect2.top);
358 }
359
360 bool operator!=(const PGFRect& rect2) const {
361 return !(*this == rect2);
362 }
363
364 };
365
366#ifdef __PGF32SUPPORT__
367 typedef int32_t DataT;
368#else
369 typedef int16_t DataT;
370#endif
371
372 typedef void (*RefreshCB)(void* p);
373
374 //-------------------------------------------------------------------------------
375 // Image constants
376 //-------------------------------------------------------------------------------
377 constexpr size_t MagicVersionSize = sizeof(pgf::PGFMagicVersion);
378 constexpr size_t PreHeaderSize = sizeof(pgf::PGFPreHeader);
379 constexpr size_t HeaderSize = sizeof(pgf::PGFHeader);
380 constexpr size_t ColorTableSize = (ColorTableLen*sizeof(RGBQUAD));
381 constexpr size_t DataTSize = sizeof(pgf::DataT);
382 constexpr size_t MaxUserDataSize = 0x7FFFFFFF;
383}
PGF platform specific definitions.
constexpr uint8_t ImageModeUnknown
constexpr uint32_t WordWidth
WordBytes*8.
Definition PGFplatform.h:73
#define __min(x, y)
#define __max(x, y)
constexpr Orientation LL
Definition PGFtypes.h:104
constexpr Orientation HH
Definition PGFtypes.h:107
constexpr Orientation LH
Definition PGFtypes.h:106
constexpr Orientation HL
Definition PGFtypes.h:105
uint8_t Orientation
Definition PGFtypes.h:102
constexpr Policy Skip
Definition PGFtypes.h:112
constexpr Policy CachePrefix
Definition PGFtypes.h:112
uint32_t Policy
Definition PGFtypes.h:110
constexpr Policy CacheAll
Definition PGFtypes.h:112
Definition PGFimage.h:33
constexpr int MaxBitPlanes
maximum number of bit planes of m_value: 32 minus sign bit
Definition PGFtypes.h:91
constexpr int PGFVersion
current standard version
Definition PGFtypes.h:76
constexpr size_t HeaderSize
Definition PGFtypes.h:379
constexpr int LinBlockSize
side length of a coefficient block in a HH or LL subband
Definition PGFtypes.h:88
constexpr size_t MagicVersionSize
Definition PGFtypes.h:377
constexpr int PGF32
32 bit values are used -> allows at maximum 30 input bits, otherwise 16 bit values are used -> allows...
Definition PGFtypes.h:69
constexpr size_t MaxUserDataSize
Definition PGFtypes.h:382
constexpr size_t PreHeaderSize
Definition PGFtypes.h:378
constexpr int MaxChannels
maximum number of (color) channels
Definition PGFtypes.h:64
void(*) RefreshCB(void *p)
Definition PGFtypes.h:372
constexpr const char * PGFMagic
PGF identification.
Definition PGFtypes.h:61
constexpr int MaxLevel
maximum number of transform levels
Definition PGFtypes.h:62
constexpr int InterBlockSize
side length of a coefficient block in a HL or LH subband
Definition PGFtypes.h:89
constexpr int MaxQuality
maximum quality
Definition PGFtypes.h:96
constexpr int ColorTableLen
size of color lookup table (clut)
Definition PGFtypes.h:66
int32_t DataT
Definition PGFtypes.h:367
constexpr int RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
Definition PGFtypes.h:87
constexpr int NSubbands
number of subbands per level
Definition PGFtypes.h:63
constexpr uint32_t CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition PGFtypes.h:86
constexpr int Version5
new coding scheme since major version 5
Definition PGFtypes.h:71
constexpr int Version7
Codec major and minor version number stored in PGFHeader.
Definition PGFtypes.h:73
constexpr size_t DataTSize
Definition PGFtypes.h:381
constexpr int Version6
hSize in PGFPreHeader uses 32 bits instead of 16 bits
Definition PGFtypes.h:72
constexpr int MaxBitPlanesLog
number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
Definition PGFtypes.h:95
ProgressMode
Definition PGFtypes.h:114
constexpr int Version2
data structure PGFHeader of major version 2
Definition PGFtypes.h:68
constexpr uint32_t BufferLen
number of words per buffer
Definition PGFtypes.h:85
constexpr int DownsampleThreshold
if quality is larger than this threshold than downsampling is used
Definition PGFtypes.h:65
constexpr size_t ColorTableSize
Definition PGFtypes.h:380
constexpr uint32_t BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
Definition PGFtypes.h:84
constexpr int PGFROI
supports Regions Of Interest
Definition PGFtypes.h:70
OSError error
operating system error code
Definition PGFtypes.h:244
IOException()
Standard constructor.
Definition PGFtypes.h:247
IOException(OSError err)
Definition PGFtypes.h:251
PGF header.
Definition PGFtypes.h:169
uint8_t usedBitsPerChannel
number of used bits per channel in 16- and 32-bit per channel modes
Definition PGFtypes.h:177
uint8_t bpp
bits per pixel
Definition PGFtypes.h:174
uint8_t channels
number of channels
Definition PGFtypes.h:175
uint8_t nLevels
number of FWT transforms
Definition PGFtypes.h:172
uint8_t mode
image mode according to Adobe's image modes
Definition PGFtypes.h:176
uint32_t width
image width in pixels
Definition PGFtypes.h:170
uint8_t quality
quantization parameter: 0=lossless, 4=standard, 6=poor quality
Definition PGFtypes.h:173
uint32_t height
image height in pixels
Definition PGFtypes.h:171
PGFVersionNumber version
codec version number: (since Version 7)
Definition PGFtypes.h:178
PGF identification and version.
Definition PGFtypes.h:126
char magic[3]
PGF identification = "PGF".
Definition PGFtypes.h:127
uint8_t version
PGF version.
Definition PGFtypes.h:128
Optional PGF post-header.
Definition PGFtypes.h:199
uint32_t userDataLen
user data size in bytes (not part of file header)
Definition PGFtypes.h:202
uint32_t cachedUserDataLen
cached user data size in bytes (not part of file header)
Definition PGFtypes.h:203
RGBQUAD clut[ColorTableLen]
color table for indexed color images (optional part of file header)
Definition PGFtypes.h:200
uint8_t * userData
user data of size userDataLen (optional part of file header)
Definition PGFtypes.h:201
PGF pre-header.
Definition PGFtypes.h:136
uint32_t hSize
total size of PGFHeader, [ColorTable], and [UserData] in bytes (since Version 6: 4 Bytes)
Definition PGFtypes.h:137
uint32_t top
Definition PGFtypes.h:259
bool operator!=(const PGFRect &rect2) const
Definition PGFtypes.h:360
friend bool Intersect(const PGFRect &rect1, const PGFRect &rect2, PGFRect &resultRect)
Definition PGFtypes.h:335
uint32_t Height() const
Definition PGFtypes.h:307
uint32_t bottom
Definition PGFtypes.h:259
uint32_t right
Definition PGFtypes.h:259
PGFRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
Definition PGFtypes.h:274
bool operator==(const PGFRect &rect2) const
Definition PGFtypes.h:356
void Offset(int32_t shiftH, int32_t shiftV)
Definition PGFtypes.h:321
uint32_t Width() const
Definition PGFtypes.h:304
bool IsInside(uint32_t x, uint32_t y) const
Definition PGFtypes.h:313
PGFRect()
Standard constructor.
Definition PGFtypes.h:262
uint32_t left
Definition PGFtypes.h:259
version number stored in header since major version 7
Definition PGFtypes.h:145
PGFVersionNumber(uint8_t _major, uint8_t _year, uint8_t _week)
Definition PGFtypes.h:156
uint16_t week
week number in a year
Definition PGFtypes.h:153
uint16_t major
major version number
Definition PGFtypes.h:151
uint16_t year
year since 2000 (year 2001 = 1)
Definition PGFtypes.h:152
Named ROI block header (part of the union).
Definition PGFtypes.h:214
uint16_t bufferSize
number of uncoded uint32_t values in a block
Definition PGFtypes.h:219
uint16_t tileEnd
1: last part of a tile
Definition PGFtypes.h:220
struct pgf::ROIBlockHeader::RBH rbh
ROI block header.
ROIBlockHeader(uint32_t size, bool end)
Definition PGFtypes.h:232
ROIBlockHeader(uint16_t v)
Definition PGFtypes.h:227