Main Page   Class Hierarchy   Compound List   File List   Compound Members  

vtDIB.h

00001 //
00002 // vtDIB.h
00003 //
00004 // Copyright (c) 2001 Virtual Terrain Project
00005 // Free for all uses, see license.txt for details.
00006 //
00007 
00008 #ifndef VTDATA_DIBH
00009 #define VTDATA_DIBH
00010 
00011 // for non-Win32 systems (or code which does include the Win32 headers),
00012 // define some Microsoft types used by the DIB code
00013 #ifdef _WINGDI_
00014 
00015 typedef DWORD dword;
00016 
00017 #else
00018 
00019 typedef unsigned long dword;
00020 typedef unsigned short word;
00021 typedef unsigned char byte;
00022 
00023 #if WIN32
00024 #include <pshpack2.h>
00025 #endif
00026 
00027 #ifdef __GNUC__
00028 #  define PACKED __attribute__((packed))
00029 #else
00030 #  define PACKED
00031 #endif
00032 
00033 typedef struct tagBITMAPFILEHEADER {
00034     word    bfType;
00035     dword   bfSize;
00036     word    bfReserved1;
00037     word    bfReserved2;
00038     dword   bfOffBits;
00039 } PACKED BITMAPFILEHEADER;
00040 #if WIN32
00041 #include <poppack.h>
00042 #endif
00043 
00044 typedef struct tagBITMAPINFOHEADER{
00045     dword   biSize;
00046     long    biWidth;
00047     long    biHeight;
00048     word    biPlanes;
00049     word    biBitCount;
00050     dword   biCompression;
00051     dword   biSizeImage;
00052     long    biXPelsPerMeter;
00053     long    biYPelsPerMeter;
00054     dword   biClrUsed;
00055     dword   biClrImportant;
00056 } PACKED BITMAPINFOHEADER;
00057 
00058 typedef struct tagRGBQUAD {
00059     byte    rgbBlue;
00060     byte    rgbGreen;
00061     byte    rgbRed;
00062     byte    rgbReserved;
00063 } PACKED RGBQUAD;
00064 
00065 /* constants for the biCompression field */
00066 #define BI_RGB        0L
00067 #define BI_RLE8       1L
00068 #define BI_RLE4       2L
00069 #define BI_BITFIELDS  3L
00070 
00071 #define RGB(r,g,b)          ((dword)(((byte)(r)|((word)((byte)(g))<<8))|(((dword)(byte)(b))<<16)))
00072 
00073 #define GetRValue(rgb)      ((byte)(rgb))
00074 #define GetGValue(rgb)      ((byte)(((word)(rgb)) >> 8))
00075 #define GetBValue(rgb)      ((byte)((rgb)>>16))
00076 
00077 #endif // #ifndef _WINGDI_
00078 
00079 
00080 class vtDIB
00081 {
00082 public:
00083     vtDIB();
00084     vtDIB(const char *fname);       // load new DIB from file
00085     vtDIB(int width, int height, int bitdepth, bool create_palette);    // create new DIB
00086     vtDIB(void *pDIB);              // wrap an existing DIB
00087     ~vtDIB();
00088 
00089     bool ReadBMP(const char *fname);
00090     bool WriteBMP(const char *fname);
00091 //  bool ReadPNG(const char *filename);
00092 
00093     unsigned long GetPixel24(int x, int y);
00094     void SetPixel24(int x, int y, dword color);
00095 
00096     unsigned char GetPixel8(int x, int y);
00097     void SetPixel8(int x, int y, byte color);
00098 
00099     bool GetPixel1(int x, int y);
00100     void SetPixel1(int x, int y, bool color);
00101 
00102     int GetWidth() { return m_iWidth; }
00103     int GetHeight() { return m_iHeight; }
00104     int GetDepth() { return m_iBitCount; }
00105 
00106     void *GetHandle() { return m_pDIB; }
00107     BITMAPINFOHEADER *GetDIBHeader() { return m_Hdr; }
00108     void *GetDIBData() { return m_Data; }
00109 
00110     void Lock();
00111     void Unlock();
00112     void LeaveInternalDIB(bool bLeaveIt);
00113 
00114     bool    m_bLoadedSuccessfully;
00115 
00116 private:
00117     void ComputeByteWidth();
00118 
00119     bool    m_bLeaveIt;
00120 
00121     // When locked, these two fields point to the header and data
00122     BITMAPINFOHEADER *m_Hdr;
00123     void    *m_Data;
00124 
00125     void    *m_pDIB;
00126     int     m_iWidth, m_iHeight, m_iBitCount;
00127     int     m_iByteWidth;
00128     int     m_iPaletteSize;
00129 };
00130 
00131 #endif

Generated at Fri Aug 17 14:40:42 2001 for vtdata library by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000