libpgf: PGFtypes.h Source File

| libpgf 7.21.2 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#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 // leading zeros are possible
46#define PGFWeek 07 // leading zeros are possible
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)
113 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 // total: 2 Bytes
145};
146
151 struct PGFHeader {
152 PGFHeader() : width(0), height(0), nLevels(0), quality(0), bpp(0), channels(0), mode(ImageModeUnknown), usedBitsPerChannel(0), version(0, 0, 0) {}
153 UINT32 width;
154 UINT32 height;
155 UINT8 nLevels;
156 UINT8 quality;
157 UINT8 bpp;
158 UINT8 channels;
159 UINT8 mode;
160 UINT8 usedBitsPerChannel;
161 PGFVersionNumber version;
162 // total: 16 Bytes
163};
164
169 struct PGFPostHeader {
170 RGBQUAD clut[ColorTableLen];
171 UINT8 *userData;
172 UINT32 userDataLen;
173 UINT32 cachedUserDataLen;
174};
175
180 union ROIBlockHeader {
181 UINT16 val;
183 struct RBH {
184#ifdef PGF_USE_BIG_ENDIAN
185 UINT16 tileEnd : 1;
186 UINT16 bufferSize: RLblockSizeLen;
187#else
188 UINT16 bufferSize: RLblockSizeLen;
189 UINT16 tileEnd : 1;
190#endif // PGF_USE_BIG_ENDIAN
191 } rbh;
192 // total: 2 Bytes
193
196 ROIBlockHeader(UINT16 v) { val = v; }
197
201 ROIBlockHeader(UINT32 size, bool end) { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
202};
203
204#pragma pack()
205
210 struct IOException {
211 OSError error;
212
214 IOException() : error(NoError) {}
215
218 IOException(OSError err) : error(err) {}
219};
220
225 struct PGFRect {
226 UINT32 left, top, right, bottom;
227
229 PGFRect() : left(0), top(0), right(0), bottom(0) {}
230
236 PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {}
237
238#ifdef WIN32
239 PGFRect(const RECT& rect) : left(rect.left), top(rect.top), right(rect.right), bottom(rect.bottom) {
240 ASSERT(rect.left >= 0 && rect.right >= 0 && rect.left <= rect.right);
241 ASSERT(rect.top >= 0 && rect.bottom >= 0 && rect.top <= rect.bottom);
242 }
243
244 PGFRect& operator=(const RECT& rect) {
245 left = rect.left; top = rect.top; right = rect.right; bottom = rect.bottom;
246 return *this;
247 }
248
249 operator RECT() {
250 RECT rect = { (LONG)left, (LONG)top, (LONG)right, (LONG)bottom };
251 return rect;
252 }
253#endif
254
256 UINT32 Width() const { return right - left; }
257
259 UINT32 Height() const { return bottom - top; }
260
265 bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); }
266};
267
268#ifdef __PGF32SUPPORT__
269 typedef INT32 DataT;
270#else
271typedef INT16 DataT;
272#endif
273
274 typedef void (*RefreshCB)(void *p);
275
276//-------------------------------------------------------------------------------
277// Image constants
278//-------------------------------------------------------------------------------
279#define MagicVersionSize sizeof(PGFMagicVersion)
280#define PreHeaderSize sizeof(PGFPreHeader)
281#define HeaderSize sizeof(PGFHeader)
282#define ColorTableSize (ColorTableLen*sizeof(RGBQUAD))
283#define DataTSize sizeof(DataT)
284#define MaxUserDataSize 0x7FFFFFFF
285
286#endif //PGF_PGFTYPES_H
PGFplatform.h
PGF platform specific definitions.
ImageModeUnknown
#define ImageModeUnknown
Definition PGFplatform.h:119
ProgressMode
ProgressMode
Definition PGFtypes.h:100
PM_Relative
@ PM_Relative
Definition PGFtypes.h:100
PM_Absolute
@ PM_Absolute
Definition PGFtypes.h:100
UserdataPolicy
UserdataPolicy
Definition PGFtypes.h:101
UP_CachePrefix
@ UP_CachePrefix
Definition PGFtypes.h:101
UP_Skip
@ UP_Skip
Definition PGFtypes.h:101
UP_CacheAll
@ UP_CacheAll
Definition PGFtypes.h:101
RefreshCB
void(* RefreshCB)(void *p)
Definition PGFtypes.h:274
Orientation
Orientation
Definition PGFtypes.h:99
LL
@ LL
Definition PGFtypes.h:99
HL
@ HL
Definition PGFtypes.h:99
LH
@ LH
Definition PGFtypes.h:99
HH
@ HH
Definition PGFtypes.h:99
ColorTableLen
#define ColorTableLen
size of color lookup table (clut)
Definition PGFtypes.h:66
RLblockSizeLen
#define RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
Definition PGFtypes.h:85
DataT
INT32 DataT
Definition PGFtypes.h:269
IOException::error
OSError error
operating system error code
Definition PGFtypes.h:211
IOException::IOException
IOException(OSError err)
Definition PGFtypes.h:218
IOException::IOException
IOException()
Standard constructor.
Definition PGFtypes.h:214
PGFHeader::mode
UINT8 mode
image mode according to Adobe's image modes
Definition PGFtypes.h:159
PGFHeader::version
PGFVersionNumber version
codec version number: (since Version 7)
Definition PGFtypes.h:161
PGFHeader::height
UINT32 height
image height in pixels
Definition PGFtypes.h:154
PGFHeader::width
UINT32 width
image width in pixels
Definition PGFtypes.h:153
PGFHeader::nLevels
UINT8 nLevels
number of FWT transforms
Definition PGFtypes.h:155
PGFHeader::channels
UINT8 channels
number of channels
Definition PGFtypes.h:158
PGFHeader::usedBitsPerChannel
UINT8 usedBitsPerChannel
number of used bits per channel in 16- and 32-bit per channel modes
Definition PGFtypes.h:160
PGFHeader::quality
UINT8 quality
quantization parameter: 0=lossless, 4=standard, 6=poor quality
Definition PGFtypes.h:156
PGFHeader::PGFHeader
PGFHeader()
Definition PGFtypes.h:152
PGFHeader::bpp
UINT8 bpp
bits per pixel
Definition PGFtypes.h:157
PGFMagicVersion
PGF identification and version.
Definition PGFtypes.h:113
PGFMagicVersion::magic
char magic[3]
PGF identification = "PGF".
Definition PGFtypes.h:114
PGFMagicVersion::version
UINT8 version
PGF version.
Definition PGFtypes.h:115
PGFPostHeader
Optional PGF post-header.
Definition PGFtypes.h:169
PGFPostHeader::userDataLen
UINT32 userDataLen
user data size in bytes (not part of file header)
Definition PGFtypes.h:172
PGFPostHeader::cachedUserDataLen
UINT32 cachedUserDataLen
cached user data size in bytes (not part of file header)
Definition PGFtypes.h:173
PGFPostHeader::clut
RGBQUAD clut[ColorTableLen]
color table for indexed color images (optional part of file header)
Definition PGFtypes.h:170
PGFPostHeader::userData
UINT8 * userData
user data of size userDataLen (optional part of file header)
Definition PGFtypes.h:171
PGFPreHeader
PGF pre-header.
Definition PGFtypes.h:123
PGFPreHeader::hSize
UINT32 hSize
total size of PGFHeader, [ColorTable], and [UserData] in bytes (since Version 6: 4 Bytes)
Definition PGFtypes.h:124
PGFRect::Height
UINT32 Height() const
Definition PGFtypes.h:259
PGFRect::IsInside
bool IsInside(UINT32 x, UINT32 y) const
Definition PGFtypes.h:265
PGFRect::PGFRect
PGFRect()
Standard constructor.
Definition PGFtypes.h:229
PGFRect::Width
UINT32 Width() const
Definition PGFtypes.h:256
PGFRect::top
UINT32 top
Definition PGFtypes.h:226
PGFRect::bottom
UINT32 bottom
Definition PGFtypes.h:226
PGFRect::right
UINT32 right
Definition PGFtypes.h:226
PGFRect::PGFRect
PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height)
Definition PGFtypes.h:236
PGFRect::left
UINT32 left
Definition PGFtypes.h:226
PGFVersionNumber
version number stored in header since major version 7
Definition PGFtypes.h:132
PGFVersionNumber::major
UINT16 major
major version number
Definition PGFtypes.h:140
PGFVersionNumber::PGFVersionNumber
PGFVersionNumber(UINT8 _major, UINT8 _year, UINT8 _week)
Definition PGFtypes.h:133
PGFVersionNumber::week
UINT16 week
week number in a year
Definition PGFtypes.h:142
PGFVersionNumber::year
UINT16 year
year since 2000 (year 2001 = 1)
Definition PGFtypes.h:141
ROIBlockHeader::RBH
Named ROI block header (part of the union).
Definition PGFtypes.h:183
ROIBlockHeader::RBH::tileEnd
UINT16 tileEnd
1: last part of a tile
Definition PGFtypes.h:189
ROIBlockHeader::RBH::bufferSize
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition PGFtypes.h:188
ROIBlockHeader::rbh
struct ROIBlockHeader::RBH rbh
ROI block header.
ROIBlockHeader::val
UINT16 val
Definition PGFtypes.h:181
ROIBlockHeader::ROIBlockHeader
ROIBlockHeader(UINT32 size, bool end)
Definition PGFtypes.h:201
ROIBlockHeader::ROIBlockHeader
ROIBlockHeader(UINT16 v)
Definition PGFtypes.h:196