libpgf  6.11.42
PGF - Progressive Graphics File
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 // Constraints
36 //-------------------------------------------------------------------------------
37 // BufferSize <= UINT16_MAX
38 
39 //-------------------------------------------------------------------------------
40 // Codec versions
41 //
42 // Version 2: modified data structure PGFHeader (backward compatibility assured)
43 // Version 3: DataT: INT32 instead of INT16, allows 31 bit per pixel and channel (backward compatibility assured)
44 // Version 5: ROI, new block-reordering scheme (backward compatibility assured)
45 // Version 6: modified data structure PGFPreHeader: hSize (header size) is now a UINT32 instead of a UINT16 (backward compatibility assured)
46 //
47 //-------------------------------------------------------------------------------
48 #define PGFCodecVersion "6.11.42"
49 
50 #define PGFCodecVersionID 0x061142
51 
52 //-------------------------------------------------------------------------------
53 // Image constants
54 //-------------------------------------------------------------------------------
55 #define Magic "PGF"
56 #define MaxLevel 30
57 #define NSubbands 4
58 #define MaxChannels 8
59 #define DownsampleThreshold 3
60 #define DefaultBGColor 255
61 #define ColorTableLen 256
62 // version flags
63 #define Version2 2
64 #define PGF32 4
65 #define PGFROI 8
66 #define Version5 16
67 #define Version6 32
68 // version numbers
69 #ifdef __PGF32SUPPORT__
70 #define PGFVersion (Version2 | PGF32 | Version5 | Version6)
71 #else
72 #define PGFVersion (Version2 | Version5 | Version6)
73 #endif
74 
75 //-------------------------------------------------------------------------------
76 // Coder constants
77 //-------------------------------------------------------------------------------
78 #define BufferSize 16384
79 #define RLblockSizeLen 15
80 #define LinBlockSize 8
81 #define InterBlockSize 4
82 #ifdef __PGF32SUPPORT__
83  #define MaxBitPlanes 31
84 #else
85  #define MaxBitPlanes 15
86 #endif
87 #define MaxBitPlanesLog 5
88 #define MaxQuality MaxBitPlanes
89 
90 //-------------------------------------------------------------------------------
91 // Types
92 //-------------------------------------------------------------------------------
93 enum Orientation { LL=0, HL=1, LH=2, HH=3 };
94 
99 
100 #pragma pack(1)
101 
102 
103 
104 
106  char magic[3];
107  UINT8 version;
108  // total: 4 Bytes
109 };
110 
116  UINT32 hSize;
117  // total: 8 Bytes
118 };
119 
124 struct PGFHeader {
126  UINT32 width;
127  UINT32 height;
128  UINT8 nLevels;
129  UINT8 quality;
130  UINT8 bpp;
131  UINT8 channels;
132  UINT8 mode;
135  // total: 16 Bytes
136 };
137 
143  RGBQUAD clut[ColorTableLen];
144  UINT8 *userData;
145  UINT32 userDataLen;
146 };
147 
155  ROIBlockHeader(UINT16 v) { val = v; }
159  ROIBlockHeader(UINT32 size, bool end) { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
160 
161  UINT16 val;
162 
163  struct RBH {
164 #ifdef PGF_USE_BIG_ENDIAN
165  UINT16 tileEnd : 1;
166  UINT16 bufferSize: RLblockSizeLen;
167 #else
169  UINT16 tileEnd : 1;
170 #endif // PGF_USE_BIG_ENDIAN
171  } rbh;
172  // total: 2 Bytes
173 };
174 
175 #pragma pack()
176 
181 struct IOException {
183  IOException() : error(NoError) {}
186  IOException(OSError err) : error(err) {}
187 
188  OSError error;
189 };
190 
195 struct PGFRect {
197  PGFRect() : left(0), top(0), right(0), bottom(0) {}
203  PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {}
204 
206  UINT32 Width() const { return right - left; }
208  UINT32 Height() const { return bottom - top; }
209 
214  bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); }
215 
216  UINT32 left, top, right, bottom;
217 };
218 
219 #ifdef __PGF32SUPPORT__
220 typedef INT32 DataT;
221 #else
222 typedef INT16 DataT;
223 #endif
224 
225 typedef void (*RefreshCB)(void *p);
226 
227 //-------------------------------------------------------------------------------
228 // Image constants
229 //-------------------------------------------------------------------------------
230 #define MagicVersionSize sizeof(PGFMagicVersion)
231 #define PreHeaderSize sizeof(PGFPreHeader)
232 #define HeaderSize sizeof(PGFHeader)
233 #define ColorTableSize ColorTableLen*sizeof(RGBQUAD)
234 #define DataTSize sizeof(DataT)
235 
236 #endif //PGF_PGFTYPES_H