Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
vtBitmap.h
1 //
2 // vtBitmap.h
3 //
4 // Copyright (c) 2003-2008 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef VTBITMAP_H
9 #define VTBITMAP_H
10 
11 #include "vtdata/vtDIB.h"
12 
13 // wxWidgets 2.9.x and USE_DIBSECTIONS draws upside-down bitmaps. Until it's
14 // figured out, we disable DIBSECTIONS for newer wx.
15 #if WIN32 && (wxVERSION_NUMBER < 2900)
16 #define USE_DIBSECTIONS 1
17 #endif
18 
25 class vtBitmap : public vtBitmapBase
26 {
27 public:
28  vtBitmap();
29  virtual ~vtBitmap();
30 
31  bool Allocate(int iXSize, int iYSize, int iDepth = 24);
32  bool IsAllocated() const;
33  void SetPixel24(int x, int y, uchar r, uchar g, uchar b);
34  void SetPixel24(int x, int y, const RGBi &rgb)
35  {
36  SetPixel24(x, y, rgb.r, rgb.g, rgb.b);
37  }
38  void GetPixel24(int x, int y, RGBi &rgb) const;
39 
40  void SetPixel32(int x, int y, const RGBAi &rgba);
41  void GetPixel32(int x, int y, RGBAi &rgba) const;
42 
43  uchar GetPixel8(int x, int y) const;
44  void SetPixel8(int x, int y, uchar color);
45 
46  uint GetWidth() const;
47  uint GetHeight() const;
48  uint GetDepth() const;
49 
50  void ContentsChanged();
51 
52  bool ReadPNGFromMemory(uchar *buf, int len);
53  bool WriteJPEG(const char *fname, int quality);
54 
55  wxBitmap *m_pBitmap;
56 
57 protected:
58  bool Allocate8(int iXSize, int iYSize);
59  bool Allocate24(int iXSize, int iYSize);
60 
61 #if USE_DIBSECTIONS
62  // A DIBSection is a special kind of bitmap, handled as a HBITMAP,
63  // created with special methods, and accessed as a giant raw
64  // memory array.
65  uchar *m_pScanline;
66  int m_iScanlineWidth;
67 #else
68  // For non-Windows platforms, or Windows platforms if we're being more
69  // cautious, the Bitmap is device-dependent and therefore can't be
70  // relied upon to store data the way we expect. Hence, we must have
71  // both a wxImage (portable and easy to use, but can't be directly
72  // rendered) and a wxBitmap (which can be drawn to the window).
73  //
74  // This is less memory efficient and slower.
75  //
76  wxImage *m_pImage;
77 #endif
78 };
79 
80 #endif // VTBITMAP_H
81