iBMP.h
Go to the documentation of this file.
00001 /*
00002 imagen - Simple object-oriented imaging library
00003 Copyright (C) 2012 Mark D. Procarione
00004 
00005 imagen is free software: you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation, either
00008 version 3 of the License, or (at your option) any later version.
00009 
00010 imagen is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __IBMP_H__
00017 #define __IBMP_H__
00018 
00019 #include "imagen.h"
00020 
00021 #ifdef IMAGEN_BMP
00022 
00023 #include "iAbstractImage.h"
00024 
00025 namespace imagen
00026 {
00028 
00046     class iBMP : public iAbstractImage
00047     {
00048         private:
00049             #pragma pack(1)
00050 
00051             struct BITMAPFILEHEADER
00052             {
00053                 BITMAPFILEHEADER();
00054                 void clear();
00055 
00056                 iWORD  FileType;     // 00h  Header field magic number
00057                 iDWORD FileSize;     // 02h  Complete file size in bytes
00058                 iWORD  Reserved1;    // 06h  Reserved, application specific
00059                 iWORD  Reserved2;    // 08h  Reserved, application specific
00060                 iDWORD BitmapOffset; // 0Ah  Offset from start of header to image data
00061             };
00062 
00064             struct BITMAPCOREHEADER
00065             {
00066                 BITMAPCOREHEADER();
00067                 void clear();
00068 
00069                 iDWORD Size;         // 00h  Size of the header in bytes
00070                 iWORD  Width;        // 04h  Image width in pixels
00071                 iWORD  Height;       // 06h  Image height in pixels
00072                 iWORD  Planes;       // 08h  Number of color planes
00073                 iWORD  BitsPerPixel; // 0Ah  Number of bits per pixel
00074             };
00075 
00077             struct BITMAPINFOHEADER
00078             {
00079                 BITMAPINFOHEADER();
00080                 void clear();
00081 
00082                 iDWORD Size;            // 00h  Size of the header in bytes
00083                 iLONG  Width;           // 04h  Image width in pixels
00084                 iLONG  Height;          // 08h  Image height in pixels
00085                 iWORD  Planes;          // 0Ch  Number of color planes
00086                 iWORD  BitsPerPixel;    // 0Eh  Number of bits per pixel
00087                 iDWORD Compression;     // 10h  Compression type
00088                 iDWORD SizeOfBitmap;    // 14h  Size of bitmap in bytes
00089                 iLONG  XResolution;     // 18h  Horizontal resolution, in pixels per meter
00090                 iLONG  YResolution;     // 1Ch  Vertical resolution, in pixels per meter
00091                 iDWORD ColorsUsed;      // 20h  Number of color indices
00092                 iDWORD ColorsImportant; // 24h  Number of required color indices
00093             };
00094 
00096             struct BITMAPV4HEADER : BITMAPINFOHEADER
00097             {
00098                 BITMAPV4HEADER();
00099                 void clear();
00100 
00101                 iDWORD RedMask;         // 28h  Red component bit mask
00102                 iDWORD GreenMask;       // 2Ch  Green component bit mask
00103                 iDWORD BlueMask;        // 30h  Blue component bit mask
00104                 iDWORD AlphaMask;       // 34h  Alpha component bit mask
00105                 iDWORD CSType;          // 38h  Color space type
00106                 iLONG  RedX;            // 3Ch  X coordinate of red endpoint
00107                 iLONG  RedY;            // 40h  Y coordinate of red endpoint
00108                 iLONG  RedZ;            // 44h  Z coordinate of red endpoint
00109                 iLONG  GreenX;          // 48h  X coordinate of green endpoint
00110                 iLONG  GreenY;          // 4Ch  Y coordinate of green endpoint
00111                 iLONG  GreenZ;          // 50h  Z coordinate of green endpoint
00112                 iLONG  BlueX;           // 54h  X coordinate of blue endpoint
00113                 iLONG  BlueY;           // 58h  Y coordinate of blue endpoint
00114                 iLONG  BlueZ;           // 5Ch  Z coordinate of blue endpoint
00115                 iDWORD GammaRed;        // 60h  Gamma red coordinate scale value
00116                 iDWORD GammaGreen;      // 64h  Gamma green coordinate scale value
00117                 iDWORD GammaBlue;       // 68h  Gamma blue coordinate scale value
00118             };
00119 
00121             struct BITMAPV5HEADER : BITMAPV4HEADER
00122             {
00123                 BITMAPV5HEADER();
00124                 void clear();
00125 
00126                 iDWORD Intent;          // 6Ch  Rendering intent
00127                 iDWORD ProfileData;     // 70h  Offset from start of BITMAPV5HEADER to start of profile data
00128                 iDWORD ProfileSize;     // 74h  Size of profile data in bytes
00129                 iDWORD Reserved;        // 78h  Reserved member
00130             };
00131             #pragma pack()
00132 
00133         public:
00134             enum BMPCompressFmt
00135             {
00136                 BI_RGB = 0,
00137                 BI_RLE8 = 1,
00138                 BI_RLE4 = 2,
00139                 BI_BITFIELDS = 3,
00140                 BI_JPEG = 4,
00141                 BI_PNG = 5
00142             };
00143 
00144             enum BMPRenderingIntent
00145             {
00146                 RI_COLORIMETRIC = 0,
00147                 RI_BUSINESS = 1,
00148                 RI_GRAPHICS = 2,
00149                 RI_IMAGES = 3
00150             };
00151 
00152             enum BMPColorSpace
00153             {
00154                 CS_CALIBRATED_RGB = 0,
00155                 CS_sRGB = 1,
00156                 CS_CMYK = 2
00157             };
00158 
00159         public:
00161             iBMP();
00162 
00164 
00165             iBMP( const iBMP &img );
00166 
00168             iBMP( const iAbstractImage &img );
00169 
00171 
00175             iBMP( int w, int h, iImageFormat f );
00176 
00178 
00180             iBMP( Iubyte *d, int w, int h, iImageFormat f, int b );
00181 
00183 
00184             iBMP( const char *filename );
00185 
00187 
00188             iBMP( Iubyte *buf, int len );
00189 
00191 
00192             iBMP( iDataStream *s );
00193 
00195             ~iBMP();
00196 
00197             void clear();
00198 
00199             bool isFormatSupported( iImageFormat fmt ) const;
00200 
00201             static bool isValid( iDataStream *s );
00202 
00203             iBMP &operator=( const iBMP &img );
00204 
00205             iBMP &operator=( const iAbstractImage &img );
00206 
00207         protected:
00208             void init();
00209             bool loadImage();
00210             bool saveImage();
00211 
00212         private:
00213             bool readFileHeader();
00214             bool readBitmapHeader();
00215             bool validateHeader();
00216             bool readImageData();
00217 
00218             bool readColTable();
00219 
00220             bool writeFileHeader();
00221             bool writeBitmapHeader();
00222             bool writeImageData();
00223 
00224             bool writeColTable();
00225 
00226         private:
00227             BITMAPFILEHEADER fileheader;
00228             int bmpbits;
00229     };
00230 }
00231 
00232 #endif // IMAGEN_BMP
00233 
00234 #endif // __IBMP_H__