Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
vtDIB.h
1 //
2 // vtDIB.h
3 //
4 // Copyright (c) 2001-2005 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef VTDATA_DIBH
9 #define VTDATA_DIBH
10 
11 #include "MathTypes.h"
12 
13 class vtProjection;
14 
19 {
20 public:
21  virtual ~vtBitmapBase() {}
22 
23  virtual uchar GetPixel8(int x, int y) const = 0;
24  virtual void GetPixel24(int x, int y, RGBi &rgb) const = 0;
25  virtual void GetPixel32(int x, int y, RGBAi &rgba) const = 0;
26 
27  virtual void SetPixel8(int x, int y, uchar color) = 0;
28  virtual void SetPixel24(int x, int y, const RGBi &rgb) = 0;
29  virtual void SetPixel32(int x, int y, const RGBAi &rgba) = 0;
30 
31  virtual uint GetWidth() const = 0;
32  virtual uint GetHeight() const = 0;
33  virtual uint GetDepth() const = 0;
34 
35  void ScalePixel8(int x, int y, float fScale);
36  void ScalePixel24(int x, int y, float fScale);
37  void ScalePixel32(int x, int y, float fScale);
38  void BlitTo(vtBitmapBase &target, int x, int y);
39 };
40 
41 // for non-Win32 systems (or code which doesn't include the Win32 headers),
42 // define some Microsoft types used by the DIB code
43 #ifdef _WINGDI_
44 // #ifndef _WINDEF_
45  typedef DWORD dword;
46 // #endif
47 #else
48  typedef unsigned long dword;
49  typedef unsigned short word;
50  typedef uchar byte;
52  #define RGB(r,g,b) ((dword)(((byte)(r)|((word)((byte)(g))<<8))|(((dword)(byte)(b))<<16)))
53  #define GetRValue(rgb) ((byte)(rgb))
54  #define GetGValue(rgb) ((byte)(((word)(rgb)) >> 8))
55  #define GetBValue(rgb) ((byte)((rgb)>>16))
56 #endif
57 
63 class vtDIB : public vtBitmapBase
64 {
65 public:
66  vtDIB();
67  vtDIB(void *pDIB); // wrap an existing DIB
68  virtual ~vtDIB();
69 
70  bool Create(int width, int height, int bitdepth, bool create_palette = false);
71  bool Create24From8bit(const vtDIB &from);
72 
73  bool Read(const char *fname, bool progress_callback(int) = NULL);
74  bool ReadBMP(const char *fname, bool progress_callback(int) = NULL);
75  bool ReadJPEG(const char *fname, bool progress_callback(int) = NULL);
76  bool ReadPNG(const char *fname, bool progress_callback(int) = NULL);
77 
78  bool WriteBMP(const char *fname);
79  bool WriteJPEG(const char *fname, int quality, bool progress_callback(int) = NULL);
80  bool WritePNG(const char *fname);
81  bool WriteTIF(const char *fname, const DRECT *area = NULL,
82  const vtProjection *proj = NULL, bool progress_callback(int) = NULL);
83 
84  uint GetPixel24(int x, int y) const;
85  void GetPixel24(int x, int y, RGBi &rgb) const;
86  void GetPixel24From8bit(int x, int y, RGBi &rgb) const;
87  void SetPixel24(int x, int y, dword color);
88  void SetPixel24(int x, int y, const RGBi &rgb);
89 
90  void GetPixel32(int x, int y, RGBAi &rgba) const;
91  void SetPixel32(int x, int y, const RGBAi &rgba);
92 
93  uchar GetPixel8(int x, int y) const;
94  void SetPixel8(int x, int y, uchar color);
95 
96  bool GetPixel1(int x, int y) const;
97  void SetPixel1(int x, int y, bool color);
98 
99  void SetColor(const RGBi &rgb);
100  void Invert();
101  void Blit(vtDIB &target, int x, int y);
102 
103  uint GetWidth() const { return m_iWidth; }
104  uint GetHeight() const { return m_iHeight; }
105  uint GetDepth() const { return m_iBitCount; }
106 
107  void *GetHandle() const { return m_pDIB; }
108  BITMAPINFOHEADER *GetDIBHeader() const { return m_Hdr; }
109  void *GetDIBData() const { return m_Data; }
110 
111  void LeaveInternalDIB(bool bLeaveIt);
112 
113  bool m_bLoadedSuccessfully;
114 
115 private:
116  void _ComputeByteWidth();
117 
118  bool m_bLeaveIt;
119 
120  // The DIB's header and data
121  BITMAPINFOHEADER *m_Hdr;
122  void *m_Data;
123 
124  void *m_pDIB;
125  uint m_iWidth, m_iHeight, m_iBitCount, m_iByteCount;
126  uint m_iByteWidth;
127  uint m_iPaletteSize;
128 };
129 
130 #endif // VTDATA_DIBH
131