libpgf  7.15.32
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 31 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 15
46 #define PGFWeek 32
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 0x071532
54 #define PGFCodecVersionID PPCAT(PPCAT(PPCAT(0x0, PGFMajorNumber), PGFYear), PGFWeek)
55 //#define PGFCodecVersion "7.15.32" ///< 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 
182  ROIBlockHeader(UINT16 v) { val = v; }
186  ROIBlockHeader(UINT32 size, bool end) { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
187 
188  UINT16 val;
189  struct RBH {
191 #ifdef PGF_USE_BIG_ENDIAN
192  UINT16 tileEnd : 1;
193  UINT16 bufferSize: RLblockSizeLen;
194 #else
196  UINT16 tileEnd : 1;
197 #endif // PGF_USE_BIG_ENDIAN
198  } rbh;
199  // total: 2 Bytes
200 };
201 
202 #pragma pack()
203 
208 struct IOException {
210  IOException() : error(NoError) {}
213  IOException(OSError err) : error(err) {}
214 
215  OSError error;
216 };
217 
222 struct PGFRect {
224  PGFRect() : left(0), top(0), right(0), bottom(0) {}
230  PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {}
231 
232 #ifdef WIN32
233  PGFRect(const RECT& rect) : left(rect.left), top(rect.top), right(rect.right), bottom(rect.bottom) {
234  ASSERT(rect.left >= 0 && rect.right >= 0 && rect.left <= rect.right);
235  ASSERT(rect.top >= 0 && rect.bottom >= 0 && rect.top <= rect.bottom);
236  }
237  PGFRect& operator=(const RECT& rect) {
238  left = rect.left; top = rect.top; right = rect.right; bottom = rect.bottom;
239  return *this;
240  }
241  operator RECT() {
242  RECT rect = { left, top, right, bottom };
243  return rect;
244  }
245 #endif
246 
248  UINT32 Width() const { return right - left; }
250  UINT32 Height() const { return bottom - top; }
251 
256  bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); }
257 
258  UINT32 left, top, right, bottom;
259 };
260 
261 #ifdef __PGF32SUPPORT__
262 typedef INT32 DataT;
263 #else
264 typedef INT16 DataT;
265 #endif
266 
267 typedef void (*RefreshCB)(void *p);
268 
269 //-------------------------------------------------------------------------------
270 // Image constants
271 //-------------------------------------------------------------------------------
272 #define MagicVersionSize sizeof(PGFMagicVersion)
273 #define PreHeaderSize sizeof(PGFPreHeader)
274 #define HeaderSize sizeof(PGFHeader)
275 #define ColorTableSize (ColorTableLen*sizeof(RGBQUAD))
276 #define DataTSize sizeof(DataT)
277 #define MaxUserDataSize 0x7FFFFFFF
278 
279 #endif //PGF_PGFTYPES_H
struct ROIBlockHeader::RBH rbh
ROI block header.
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:195
UINT8 version
PGF version.
Definition: PGFtypes.h:115
UINT8 mode
image mode according to Adobe&#39;s image modes
Definition: PGFtypes.h:158
IOException(OSError err)
Definition: PGFtypes.h:213
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:267
INT32 DataT
Definition: PGFtypes.h:262
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:196
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:258
#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:210
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:190
#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:250
Definition: PGFtypes.h:99
UINT16 week
week number in a year
Definition: PGFtypes.h:142
ROIBlockHeader(UINT32 size, bool end)
Definition: PGFtypes.h:186
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:230
Definition: PGFtypes.h:99
Optional PGF post-header.
Definition: PGFtypes.h:168
UINT32 top
Definition: PGFtypes.h:258
#define ImageModeUnknown
Definition: PGFplatform.h:119
PGFRect()
Standard constructor.
Definition: PGFtypes.h:224
UINT32 left
Definition: PGFtypes.h:258
UserdataPolicy
Definition: PGFtypes.h:101
UINT16 val
Definition: PGFtypes.h:188
Definition: PGFtypes.h:99
ROIBlockHeader(UINT16 v)
Definition: PGFtypes.h:182
OSError error
operating system error code
Definition: PGFtypes.h:215
UINT16 major
major version number
Definition: PGFtypes.h:140
UINT8 channels
number of channels
Definition: PGFtypes.h:157
Rectangle.
Definition: PGFtypes.h:222
PGFVersionNumber version
codec version number: (since Version 7)
Definition: PGFtypes.h:160
UINT32 Width() const
Definition: PGFtypes.h:248
bool IsInside(UINT32 x, UINT32 y) const
Definition: PGFtypes.h:256
PGF exception.
Definition: PGFtypes.h:208
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:258
ProgressMode
Definition: PGFtypes.h:100