libpgf  6.11.32
PGF - Progressive Graphics File
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 3:   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.11.32"                       // Major number
00049                                                                                                 // Minor number: Year (2) Week (2)
00050 #define PGFCodecVersionID   0x061132            // 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 DefaultBGColor          255                                     // default background color is white
00061 #define ColorTableLen           256                                     // size of color lookup table (clut)
00062 // version flags
00063 #define Version2                        2                                       // data structure PGFHeader of major version 2
00064 #define PGF32                           4                                       // 32 bit values are used -> allows at maximum 31 bits, otherwise 16 bit values are used -> allows at maximum 15 bits
00065 #define PGFROI                          8                                       // supports Regions Of Interest
00066 #define Version5                        16                                      // new coding scheme since major version 5
00067 #define Version6                        32                                      // new HeaderSize: 32 bits instead of 16 bits 
00068 // version numbers
00069 #ifdef __PGF32SUPPORT__
00070 #define PGFVersion                      (Version2 | PGF32 | Version5 | Version6)        // current standard version
00071 #else
00072 #define PGFVersion                      (Version2 |         Version5 | Version6)        // current standard version
00073 #endif
00074 
00075 //-------------------------------------------------------------------------------
00076 //      Coder constants
00077 //-------------------------------------------------------------------------------
00078 #define BufferSize                      16384                           // must be a multiple of WordWidth
00079 #define RLblockSizeLen          15                                      // block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
00080 #define LinBlockSize            8                                       // side length of a coefficient block in a HH or LL subband
00081 #define InterBlockSize          4                                       // side length of a coefficient block in a HL or LH subband
00082 #ifdef __PGF32SUPPORT__
00083         #define MaxBitPlanes    31                                      // maximum number of bit planes of m_value: 32 minus sign bit
00084 #else
00085         #define MaxBitPlanes    15                                      // maximum number of bit planes of m_value: 16 minus sign bit
00086 #endif
00087 #define MaxBitPlanesLog         5                                       // number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
00088 #define MaxQuality                      MaxBitPlanes            // maximum quality
00089 
00090 //-------------------------------------------------------------------------------
00091 // Types
00092 //-------------------------------------------------------------------------------
00093 enum Orientation { LL=0, HL=1, LH=2, HH=3 };
00094 
00095 // general file structure
00096 // PGFPreHeaderV6 PGFHeader PGFPostHeader LevelLengths Level_n-1 Level_n-2 ... Level_0
00097 // PGFPostHeader ::= [ColorTable] [UserData]
00098 // LevelLengths  ::= UINT32[nLevels]
00099 
00100 #pragma pack(1)
00101 
00102 
00103 
00104 
00105 struct PGFMagicVersion {
00106         char magic[3];                          // PGF identification = "PGF"
00107         UINT8 version;                          // PGF version
00108         // total: 4 Bytes
00109 };
00110 
00115 struct PGFPreHeader : PGFMagicVersion {
00116         UINT32 hSize;                           // total size of PGFHeader, [ColorTable], and [UserData] in bytes
00117         // total: 8 Bytes
00118 };
00119 
00124 struct PGFHeader {
00125         UINT32 width;
00126         UINT32 height;
00127         UINT8 nLevels;
00128         UINT8 quality;
00129         UINT8 bpp;                                      // bits per pixel
00130         UINT8 channels;                         // number of channels
00131         UINT8 mode;                                     // image mode according to Adobe's image modes
00132         RGBTRIPLE background;           // background color used in RGBA color mode or number of bits per channel in 16-bit per channel modes
00133         // total: 16 Bytes
00134 };
00135 
00140 struct PGFPostHeader {
00141         RGBQUAD clut[ColorTableLen];// color table for indexed color images
00142         UINT8 *userData;                        // user data of size userDataLen
00143         UINT32 userDataLen;                     // user data size in bytes
00144 };
00145 
00150 union ROIBlockHeader {
00153         ROIBlockHeader(UINT16 v) { val = v; }
00157         ROIBlockHeader(UINT32 size, bool end)   { ASSERT(size < (1 << RLblockSizeLen)); rbh.bufferSize = size; rbh.tileEnd = end; }
00158         
00159         UINT16 val;
00161         struct RBH {
00162 #ifdef PGF_USE_BIG_ENDIAN
00163                 UINT16 tileEnd   :                              1;      // 1: last part of a tile
00164                 UINT16 bufferSize: RLblockSizeLen;      // number of uncoded UINT32 values in a block
00165 #else
00166                 UINT16 bufferSize: RLblockSizeLen;      // number of uncoded UINT32 values in a block
00167                 UINT16 tileEnd   :                              1;      // 1: last part of a tile
00168 #endif // PGF_USE_BIG_ENDIAN
00169         } rbh;
00170         // total: 2 Bytes
00171 };
00172 
00173 #pragma pack()
00174 
00179 struct IOException {
00181         IOException() : error(NoError) {}
00184         IOException(OSError err) : error(err) {}
00185 
00186         OSError error;                          // operating system error code
00187 };
00188 
00193 struct PGFRect {
00195         PGFRect() : left(0), top(0), right(0), bottom(0) {}
00201         PGFRect(UINT32 x, UINT32 y, UINT32 width, UINT32 height) : left(x), top(y), right(x + width), bottom(y + height) {}
00202 
00204         UINT32 Width() const                                    { return right - left; }
00206         UINT32 Height() const                                   { return bottom - top; }
00207         
00212         bool IsInside(UINT32 x, UINT32 y) const { return (x >= left && x < right && y >= top && y < bottom); }
00213 
00214         UINT32 left, top, right, bottom;
00215 };
00216 
00217 #ifdef __PGF32SUPPORT__
00218 typedef INT32 DataT;
00219 #else
00220 typedef INT16 DataT;
00221 #endif
00222 
00223 typedef void (*RefreshCB)(void *p);
00224 
00225 //-------------------------------------------------------------------------------
00226 // Image constants
00227 //-------------------------------------------------------------------------------
00228 #define MagicVersionSize        sizeof(PGFMagicVersion)
00229 #define PreHeaderSize           sizeof(PGFPreHeader)
00230 #define HeaderSize                      sizeof(PGFHeader)
00231 #define ColorTableSize          ColorTableLen*sizeof(RGBQUAD)
00232 #define DataTSize                       sizeof(DataT)
00233 
00234 #endif //PGF_PGFTYPES_H