libpgf  7.21.2
PGF - Progressive Graphics File
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 #ifndef PGF_PGFTYPES_H
30 #define PGF_PGFTYPES_H
31 
32 #include "PGFplatform.h"
33 
34 //-------------------------------------------------------------------------------
35 // Codec versions
36 //
37 // Version 2: modified data structure PGFHeader (backward compatibility assured)
38 // Version 4: DataT: INT32 instead of INT16, allows 30 bit per pixel and channel (backward compatibility assured)
39 // Version 5: ROI, new block-reordering scheme (backward compatibility assured)
40 // Version 6: modified data structure PGFPreHeader: hSize (header size) is now a UINT32 instead of a UINT16 (backward compatibility assured)
41 // Version 7: last two bytes in header are now used for extended version numbers; new data representation for bitmaps (backward compatibility assured)
42 //
43 //-------------------------------------------------------------------------------
44 #define PGFMajorNumber 7
45 #define PGFYear 21
46 #define PGFWeek 2
47 
48 #define PPCAT_NX(A, B) A ## B
49 #define PPCAT(A, B) PPCAT_NX(A, B)
50 #define STRINGIZE_NX(A) #A
51 #define STRINGIZE(A) STRINGIZE_NX(A)
52 
53 //#define PGFCodecVersionID 0x072102
54 #define PGFCodecVersionID PPCAT(PPCAT(PPCAT(0x0, PGFMajorNumber), PGFYear), PGFWeek)
55 //#define PGFCodecVersion "7.21.02" ///< Major number, Minor number: Year (2) Week (2)
56 #define PGFCodecVersion STRINGIZE(PPCAT(PPCAT(PPCAT(PPCAT(PGFMajorNumber, .), PGFYear), .), PGFWeek))
57 
58 //-------------------------------------------------------------------------------
59 // Image constants
60 //-------------------------------------------------------------------------------
61 #define PGFMagic "PGF"
62 #define MaxLevel 30
63 #define NSubbands 4
64 #define MaxChannels 8
65 #define DownsampleThreshold 3
66 #define ColorTableLen 256
67 // version flags
68 #define Version2 2
69 #define PGF32 4
70 #define PGFROI 8
71 #define Version5 16
72 #define Version6 32
73 #define Version7 64
74 // version numbers
75 #ifdef __PGF32SUPPORT__
76 #define PGFVersion (Version2 | PGF32 | Version5 | Version6 | Version7)
77 #else
78 #define PGFVersion (Version2 | Version5 | Version6 | Version7)
79 #endif
80 
81 //-------------------------------------------------------------------------------
82 // Coder constants
83 //-------------------------------------------------------------------------------
84 #define BufferSize 16384
85 #define RLblockSizeLen 15
86 #define LinBlockSize 8
87 #define InterBlockSize 4
88 #ifdef __PGF32SUPPORT__
89  #define MaxBitPlanes 31
90 #else
91  #define MaxBitPlanes 15
92 #endif
93 #define MaxBitPlanesLog 5
94 #define MaxQuality MaxBitPlanes
95 
96 //-------------------------------------------------------------------------------
97 // Types
98 //-------------------------------------------------------------------------------
99 enum Orientation { LL = 0, HL = 1, LH = 2, HH = 3 };
102 
107 
108 #pragma pack(1)
109 struct PGFMagicVersion {
114  char magic[3];
115  UINT8 version;
116  // total: 4 Bytes
117 };
118 
124  UINT32 hSize;
125  // total: 8 Bytes
126 };
127 
133  PGFVersionNumber(UINT8 _major, UINT8 _year, UINT8 _week) : major(_major), year(_year), week(_week) {}
134 
135 #ifdef PGF_USE_BIG_ENDIAN
136  UINT16 week : 6;
137  UINT16 year : 6;
138  UINT16 major : 4;
139 #else
140  UINT16 major : 4;
141  UINT16 year : 6;
142  UINT16 week : 6;
143 #endif // PGF_USE_BIG_ENDIAN
144 };
145 
150 struct PGFHeader {
152  UINT32 width;
153  UINT32 height;
154  UINT8 nLevels;
155  UINT8 quality;
156  UINT8 bpp;
157  UINT8 channels;
158  UINT8 mode;
161  // total: 16 Bytes
162 };
163 
169  RGBQUAD clut[ColorTableLen];
170  UINT8 *userData;
171  UINT32 userDataLen;
173 };
174 
180  UINT16 val;
181  struct RBH {
183 #ifdef PGF_USE_BIG_ENDIAN
184  UINT16 tileEnd : 1;
185  UINT16 bufferSize: RLblockSizeLen;
186 #else
188  UINT16 tileEnd : 1;
189 #endif // PGF_USE_BIG_ENDIAN
190  } rbh;
191  // total: 2 Bytes
192 
195  ROIBlockHeader(UINT16 v) { val = v; }
196 
200  ROIBlockHeader(UINT32 size, bool end) { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
201 };
202 
203 #pragma pack()
204 
209 struct IOException {
210  OSError error;
211 
213  IOException() : error(NoError) {}
214 
217  IOException(OSError err) : error(err) {}
218 };
219 
224 struct PGFRect {
225  UINT32 left, top, right, bottom;
226 
228  PGFRect() : left(0), top(0), right(0), bottom(0) {}
229 
235  PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {}
236 
237 #ifdef WIN32
238  PGFRect(const RECT& rect) : left(rect.left), top(rect.top), right(rect.right), bottom(rect.bottom) {
239  ASSERT(rect.left >= 0 && rect.right >= 0 && rect.left <= rect.right);
240  ASSERT(rect.top >= 0 && rect.bottom >= 0 && rect.top <= rect.bottom);
241  }
242 
243  PGFRect& operator=(const RECT& rect) {
244  left = rect.left; top = rect.top; right = rect.right; bottom = rect.bottom;
245  return *this;
246  }
247 
248  operator RECT() {
249  RECT rect = { (LONG)left, (LONG)top, (LONG)right, (LONG)bottom };
250  return rect;
251  }
252 #endif
253 
255  UINT32 Width() const { return right - left; }
256 
258  UINT32 Height() const { return bottom - top; }
259 
264  bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); }
265 };
266 
267 #ifdef __PGF32SUPPORT__
268 typedef INT32 DataT;
269 #else
270 typedef INT16 DataT;
271 #endif
272 
273 typedef void (*RefreshCB)(void *p);
274 
275 //-------------------------------------------------------------------------------
276 // Image constants
277 //-------------------------------------------------------------------------------
278 #define MagicVersionSize sizeof(PGFMagicVersion)
279 #define PreHeaderSize sizeof(PGFPreHeader)
280 #define HeaderSize sizeof(PGFHeader)
281 #define ColorTableSize (ColorTableLen*sizeof(RGBQUAD))
282 #define DataTSize sizeof(DataT)
283 #define MaxUserDataSize 0x7FFFFFFF
284 
285 #endif //PGF_PGFTYPES_H
struct ROIBlockHeader::RBH rbh
ROI block header.
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:187
UINT8 version
PGF version.
Definition: PGFtypes.h:115
UINT8 mode
image mode according to Adobe's image modes
Definition: PGFtypes.h:158
IOException(OSError err)
Definition: PGFtypes.h:217
Definition: PGFtypes.h:99
PGF platform specific definitions.
UINT32 width
image width in pixels
Definition: PGFtypes.h:152
void(* RefreshCB)(void *p)
Definition: PGFtypes.h:273
INT32 DataT
Definition: PGFtypes.h:268
UINT32 userDataLen
user data size in bytes (not part of file header)
Definition: PGFtypes.h:171
PGF identification and version.
Definition: PGFtypes.h:113
UINT16 tileEnd
1: last part of a tile
Definition: PGFtypes.h:188
UINT8 * userData
user data of size userDataLen (optional part of file header)
Definition: PGFtypes.h:170
PGF pre-header.
Definition: PGFtypes.h:123
UINT8 nLevels
number of FWT transforms
Definition: PGFtypes.h:154
UINT32 right
Definition: PGFtypes.h:225
#define RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
Definition: PGFtypes.h:85
Orientation
Definition: PGFtypes.h:99
UINT8 usedBitsPerChannel
number of used bits per channel in 16- and 32-bit per channel modes
Definition: PGFtypes.h:159
IOException()
Standard constructor.
Definition: PGFtypes.h:213
Block header used with ROI coding scheme.
Definition: PGFtypes.h:179
PGF header.
Definition: PGFtypes.h:150
UINT32 cachedUserDataLen
cached user data size in bytes (not part of file header)
Definition: PGFtypes.h:172
Named ROI block header (part of the union)
Definition: PGFtypes.h:182
#define ColorTableLen
size of color lookup table (clut)
Definition: PGFtypes.h:66
PGFVersionNumber(UINT8 _major, UINT8 _year, UINT8 _week)
Definition: PGFtypes.h:133
UINT8 bpp
bits per pixel
Definition: PGFtypes.h:156
char magic[3]
PGF identification = "PGF".
Definition: PGFtypes.h:114
PGFHeader()
Definition: PGFtypes.h:151
UINT32 Height() const
Definition: PGFtypes.h:258
Definition: PGFtypes.h:99
UINT16 week
week number in a year
Definition: PGFtypes.h:142
ROIBlockHeader(UINT32 size, bool end)
Definition: PGFtypes.h:200
UINT32 hSize
total size of PGFHeader, [ColorTable], and [UserData] in bytes (since Version 6: 4 Bytes)
Definition: PGFtypes.h:124
UINT16 year
year since 2000 (year 2001 = 1)
Definition: PGFtypes.h:141
PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height)
Definition: PGFtypes.h:235
Definition: PGFtypes.h:99
Optional PGF post-header.
Definition: PGFtypes.h:168
UINT32 top
Definition: PGFtypes.h:225
#define ImageModeUnknown
Definition: PGFplatform.h:119
PGFRect()
Standard constructor.
Definition: PGFtypes.h:228
UINT32 left
Definition: PGFtypes.h:225
UserdataPolicy
Definition: PGFtypes.h:101
UINT16 val
Definition: PGFtypes.h:180
Definition: PGFtypes.h:99
ROIBlockHeader(UINT16 v)
Definition: PGFtypes.h:195
OSError error
operating system error code
Definition: PGFtypes.h:210
UINT16 major
major version number
Definition: PGFtypes.h:140
UINT8 channels
number of channels
Definition: PGFtypes.h:157
Rectangle.
Definition: PGFtypes.h:224
PGFVersionNumber version
codec version number: (since Version 7)
Definition: PGFtypes.h:160
UINT32 Width() const
Definition: PGFtypes.h:255
bool IsInside(UINT32 x, UINT32 y) const
Definition: PGFtypes.h:264
PGF exception.
Definition: PGFtypes.h:209
UINT8 quality
quantization parameter: 0=lossless, 4=standard, 6=poor quality
Definition: PGFtypes.h:155
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
version number stored in header since major version 7
Definition: PGFtypes.h:132
UINT32 bottom
Definition: PGFtypes.h:225
ProgressMode
Definition: PGFtypes.h:100