| 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 };
100 enum ProgressMode { PM_Relative, PM_Absolute };
101 enum UserdataPolicy { UP_Skip = 0, UP_CachePrefix = 1, UP_CacheAll = 2 };
102
107
108 #pragma pack(1)
109 struct PGFMagicVersion {
114 char magic[3];
115 UINT8 version;
116 // total: 4 Bytes
117 };
118
123 struct PGFPreHeader : PGFMagicVersion {
124 UINT32 hSize;
125 // total: 8 Bytes
126 };
127
132 struct PGFVersionNumber {
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 {
151 PGFHeader() : width(0), height(0), nLevels(0), quality(0), bpp(0), channels(0), mode(ImageModeUnknown), usedBitsPerChannel(0), version(0, 0, 0) {}
152 UINT32 width;
153 UINT32 height;
154 UINT8 nLevels;
155 UINT8 quality;
156 UINT8 bpp;
157 UINT8 channels;
158 UINT8 mode;
159 UINT8 usedBitsPerChannel;
160 PGFVersionNumber version;
161 // total: 16 Bytes
162 };
163
168 struct PGFPostHeader {
169 RGBQUAD clut[ColorTableLen];
170 UINT8 *userData;
171 UINT32 userDataLen;
172 UINT32 cachedUserDataLen;
173 };
174
179 union ROIBlockHeader {
180 UINT16 val;
181 struct RBH {
183 #ifdef PGF_USE_BIG_ENDIAN
184 UINT16 tileEnd : 1;
185 UINT16 bufferSize: RLblockSizeLen;
186 #else
187 UINT16 bufferSize: RLblockSizeLen;
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
ROIBlockHeader::rbh
struct ROIBlockHeader::RBH rbh
ROI block header.
ROIBlockHeader::RBH::bufferSize
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:187
PGFMagicVersion::version
UINT8 version
PGF version.
Definition: PGFtypes.h:115
PGFHeader::mode
UINT8 mode
image mode according to Adobe's image modes
Definition: PGFtypes.h:158
UP_Skip
Definition: PGFtypes.h:101
IOException::IOException
IOException(OSError err)
Definition: PGFtypes.h:217
HH
Definition: PGFtypes.h:99
PGFplatform.h
PGF platform specific definitions.
PGFHeader::width
UINT32 width
image width in pixels
Definition: PGFtypes.h:152
RefreshCB
void(* RefreshCB)(void *p)
Definition: PGFtypes.h:273
UP_CachePrefix
Definition: PGFtypes.h:101
PM_Relative
Definition: PGFtypes.h:100
DataT
INT32 DataT
Definition: PGFtypes.h:268
PGFPostHeader::userDataLen
UINT32 userDataLen
user data size in bytes (not part of file header)
Definition: PGFtypes.h:171
PGFMagicVersion
PGF identification and version.
Definition: PGFtypes.h:113
ROIBlockHeader::RBH::tileEnd
UINT16 tileEnd
1: last part of a tile
Definition: PGFtypes.h:188
PGFPostHeader::userData
UINT8 * userData
user data of size userDataLen (optional part of file header)
Definition: PGFtypes.h:170
PGFPreHeader
PGF pre-header.
Definition: PGFtypes.h:123
PGFHeader::nLevels
UINT8 nLevels
number of FWT transforms
Definition: PGFtypes.h:154
PGFRect::right
UINT32 right
Definition: PGFtypes.h:225
RLblockSizeLen
#define RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
Definition: PGFtypes.h:85
Orientation
Orientation
Definition: PGFtypes.h:99
PGFHeader::usedBitsPerChannel
UINT8 usedBitsPerChannel
number of used bits per channel in 16- and 32-bit per channel modes
Definition: PGFtypes.h:159
IOException::IOException
IOException()
Standard constructor.
Definition: PGFtypes.h:213
ROIBlockHeader
Block header used with ROI coding scheme.
Definition: PGFtypes.h:179
PGFHeader
PGF header.
Definition: PGFtypes.h:150
UP_CacheAll
Definition: PGFtypes.h:101
PGFPostHeader::cachedUserDataLen
UINT32 cachedUserDataLen
cached user data size in bytes (not part of file header)
Definition: PGFtypes.h:172
PM_Absolute
Definition: PGFtypes.h:100
ROIBlockHeader::RBH
Named ROI block header (part of the union)
Definition: PGFtypes.h:182
ColorTableLen
#define ColorTableLen
size of color lookup table (clut)
Definition: PGFtypes.h:66
PGFVersionNumber::PGFVersionNumber
PGFVersionNumber(UINT8 _major, UINT8 _year, UINT8 _week)
Definition: PGFtypes.h:133
PGFHeader::bpp
UINT8 bpp
bits per pixel
Definition: PGFtypes.h:156
PGFMagicVersion::magic
char magic[3]
PGF identification = "PGF".
Definition: PGFtypes.h:114
PGFHeader::PGFHeader
PGFHeader()
Definition: PGFtypes.h:151
PGFRect::Height
UINT32 Height() const
Definition: PGFtypes.h:258
LH
Definition: PGFtypes.h:99
PGFVersionNumber::week
UINT16 week
week number in a year
Definition: PGFtypes.h:142
ROIBlockHeader::ROIBlockHeader
ROIBlockHeader(UINT32 size, bool end)
Definition: PGFtypes.h:200
PGFPreHeader::hSize
UINT32 hSize
total size of PGFHeader, [ColorTable], and [UserData] in bytes (since Version 6: 4 Bytes)
Definition: PGFtypes.h:124
PGFVersionNumber::year
UINT16 year
year since 2000 (year 2001 = 1)
Definition: PGFtypes.h:141
PGFRect::PGFRect
PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height)
Definition: PGFtypes.h:235
HL
Definition: PGFtypes.h:99
PGFPostHeader
Optional PGF post-header.
Definition: PGFtypes.h:168
PGFRect::top
UINT32 top
Definition: PGFtypes.h:225
ImageModeUnknown
#define ImageModeUnknown
Definition: PGFplatform.h:119
PGFRect::PGFRect
PGFRect()
Standard constructor.
Definition: PGFtypes.h:228
PGFRect::left
UINT32 left
Definition: PGFtypes.h:225
UserdataPolicy
UserdataPolicy
Definition: PGFtypes.h:101
ROIBlockHeader::val
UINT16 val
Definition: PGFtypes.h:180
LL
Definition: PGFtypes.h:99
ROIBlockHeader::ROIBlockHeader
ROIBlockHeader(UINT16 v)
Definition: PGFtypes.h:195
IOException::error
OSError error
operating system error code
Definition: PGFtypes.h:210
PGFVersionNumber::major
UINT16 major
major version number
Definition: PGFtypes.h:140
PGFHeader::channels
UINT8 channels
number of channels
Definition: PGFtypes.h:157
PGFRect
Rectangle.
Definition: PGFtypes.h:224
PGFHeader::version
PGFVersionNumber version
codec version number: (since Version 7)
Definition: PGFtypes.h:160
PGFRect::Width
UINT32 Width() const
Definition: PGFtypes.h:255
PGFRect::IsInside
bool IsInside(UINT32 x, UINT32 y) const
Definition: PGFtypes.h:264
IOException
PGF exception.
Definition: PGFtypes.h:209
PGFHeader::quality
UINT8 quality
quantization parameter: 0=lossless, 4=standard, 6=poor quality
Definition: PGFtypes.h:155
PGFHeader::height
UINT32 height
image height in pixels
Definition: PGFtypes.h:153
PGFPostHeader::clut
RGBQUAD clut[ColorTableLen]
color table for indexed color images (optional part of file header)
Definition: PGFtypes.h:169
PGFVersionNumber
version number stored in header since major version 7
Definition: PGFtypes.h:132
PGFRect::bottom
UINT32 bottom
Definition: PGFtypes.h:225
ProgressMode
ProgressMode
Definition: PGFtypes.h:100