libpgf  6.12.24
PGF - Progressive Graphics File
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PGFtypes.h
Go to the documentation of this file.
00001 /*
00002  * The Progressive Graphics File; http://www.libpgf.org
00003  * 
00004  * $Date: 2007-06-11 10:56:17 +0200 (Mo, 11 Jun 2007) $
00005  * $Revision: 299 $
00006  * 
00007  * This file Copyright (C) 2006 xeraina GmbH, Switzerland
00008  * 
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
00011  * as published by the Free Software Foundation; either version 2.1
00012  * of the License, or (at your option) any later version.
00013  * 
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022  */
00023 
00028 
00029 #ifndef PGF_PGFTYPES_H
00030 #define PGF_PGFTYPES_H
00031 
00032 #include "PGFplatform.h"
00033 
00034 //-------------------------------------------------------------------------------
00035 //      Constraints
00036 //-------------------------------------------------------------------------------
00037 // BufferSize <= UINT16_MAX
00038 
00039 //-------------------------------------------------------------------------------
00040 //      Codec versions
00041 //
00042 // Version 2:   modified data structure PGFHeader (backward compatibility assured)
00043 // Version 4:   DataT: INT32 instead of INT16, allows 31 bit per pixel and channel (backward compatibility assured)
00044 // Version 5:   ROI, new block-reordering scheme (backward compatibility assured)
00045 // Version 6:   modified data structure PGFPreHeader: hSize (header size) is now a UINT32 instead of a UINT16 (backward compatibility assured)
00046 //
00047 //-------------------------------------------------------------------------------
00048 #define PGFCodecVersion         "6.12.24"                       ///< Major number
00049 
00050 #define PGFCodecVersionID   0x061224            ///< Codec version ID to use for API check in client implementation
00051 
00052 //-------------------------------------------------------------------------------
00053 //      Image constants
00054 //-------------------------------------------------------------------------------
00055 #define Magic                           "PGF"                           ///< PGF identification
00056 #define MaxLevel                        30                                      ///< maximum number of transform levels
00057 #define NSubbands                       4                                       ///< number of subbands per level
00058 #define MaxChannels                     8                                       ///< maximum number of (color) channels
00059 #define DownsampleThreshold 3                                   ///< if quality is larger than this threshold than downsampling is used
00060 #define ColorTableLen           256                                     ///< size of color lookup table (clut)
00061 // version flags
00062 #define Version2                        2                                       ///< data structure PGFHeader of major version 2
00063 #define PGF32                           4                                       ///< 32 bit values are used -> allows at maximum 31 bits, otherwise 16 bit values are used -> allows at maximum 15 bits
00064 #define PGFROI                          8                                       ///< supports Regions Of Interest
00065 #define Version5                        16                                      ///< new coding scheme since major version 5
00066 #define Version6                        32                                      ///< new HeaderSize: 32 bits instead of 16 bits 
00067 // version numbers
00068 #ifdef __PGF32SUPPORT__
00069 #define PGFVersion                      (Version2 | PGF32 | Version5 | Version6)        ///< current standard version
00070 #else
00071 #define PGFVersion                      (Version2 |         Version5 | Version6)        ///< current standard version
00072 #endif
00073 
00074 //-------------------------------------------------------------------------------
00075 //      Coder constants
00076 //-------------------------------------------------------------------------------
00077 #define BufferSize                      16384                           ///< must be a multiple of WordWidth
00078 #define RLblockSizeLen          15                                      ///< block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
00079 #define LinBlockSize            8                                       ///< side length of a coefficient block in a HH or LL subband
00080 #define InterBlockSize          4                                       ///< side length of a coefficient block in a HL or LH subband
00081 #ifdef __PGF32SUPPORT__
00082         #define MaxBitPlanes    31                                      ///< maximum number of bit planes of m_value: 32 minus sign bit
00083 #else
00084         #define MaxBitPlanes    15                                      ///< maximum number of bit planes of m_value: 16 minus sign bit
00085 #endif
00086 #define MaxBitPlanesLog         5                                       ///< number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
00087 #define MaxQuality                      MaxBitPlanes            ///< maximum quality
00088 
00089 //-------------------------------------------------------------------------------
00090 // Types
00091 //-------------------------------------------------------------------------------
00092 enum Orientation { LL=0, HL=1, LH=2, HH=3 };
00093 
00098 
00099 #pragma pack(1)
00100 
00101 
00102 
00103 
00104 struct PGFMagicVersion {
00105         char magic[3];                          
00106         UINT8 version;                          
00107         // total: 4 Bytes
00108 };
00109 
00114 struct PGFPreHeader : PGFMagicVersion {
00115         UINT32 hSize;                           
00116         // total: 8 Bytes
00117 };
00118 
00123 struct PGFHeader {
00124         PGFHeader() : width(0), height(0), nLevels(0), quality(0), bpp(0), channels(0), mode(ImageModeUnknown), usedBitsPerChannel(0), reserved1(0), reserved2(0) {}
00125         UINT32 width;                           
00126         UINT32 height;                          
00127         UINT8 nLevels;                          
00128         UINT8 quality;                          
00129         UINT8 bpp;                                      
00130         UINT8 channels;                         
00131         UINT8 mode;                                     
00132         UINT8 usedBitsPerChannel;       
00133         UINT8 reserved1, reserved2;     
00134         // total: 16 Bytes
00135 };
00136 
00141 struct PGFPostHeader {
00142         RGBQUAD clut[ColorTableLen];
00143         UINT8 *userData;                        
00144         UINT32 userDataLen;                     
00145 };
00146 
00151 union ROIBlockHeader {
00154         ROIBlockHeader(UINT16 v) { val = v; }
00158         ROIBlockHeader(UINT32 size, bool end)   { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
00159         
00160         UINT16 val; 
00161 
00162         struct RBH {
00163 #ifdef PGF_USE_BIG_ENDIAN
00164                 UINT16 tileEnd   :                              1;      
00165                 UINT16 bufferSize: RLblockSizeLen;      
00166 #else
00167                 UINT16 bufferSize: RLblockSizeLen;      
00168                 UINT16 tileEnd   :                              1;      
00169 #endif // PGF_USE_BIG_ENDIAN
00170         } rbh;  
00171         // total: 2 Bytes
00172 };
00173 
00174 #pragma pack()
00175 
00180 struct IOException {
00182         IOException() : error(NoError) {}
00185         IOException(OSError err) : error(err) {}
00186 
00187         OSError error;                          
00188 };
00189 
00194 struct PGFRect {
00196         PGFRect() : left(0), top(0), right(0), bottom(0) {}
00202         PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {}
00203 
00205         UINT32 Width() const                                    { return right - left; }
00207         UINT32 Height() const                                   { return bottom - top; }
00208         
00213         bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); }
00214 
00215         UINT32 left, top, right, bottom;
00216 };
00217 
00218 #ifdef __PGF32SUPPORT__
00219 typedef INT32 DataT;
00220 #else
00221 typedef INT16 DataT;
00222 #endif
00223 
00224 typedef void (*RefreshCB)(void *p);
00225 
00226 //-------------------------------------------------------------------------------
00227 // Image constants
00228 //-------------------------------------------------------------------------------
00229 #define MagicVersionSize        sizeof(PGFMagicVersion)
00230 #define PreHeaderSize           sizeof(PGFPreHeader)
00231 #define HeaderSize                      sizeof(PGFHeader)
00232 #define ColorTableSize          ColorTableLen*sizeof(RGBQUAD)
00233 #define DataTSize                       sizeof(DataT)
00234 
00235 #endif //PGF_PGFTYPES_H