]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dib.h
Removed erroneous copyright names and corrected licence spelling
[wxWidgets.git] / include / wx / msw / dib.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
6d167489 2// Name: wx/msw/dib.h
53eff2a2
VZ
3// Purpose: wxDIB class representing Win32 device independent bitmaps
4// Author: Vadim Zeitlin
2bda0e17 5// Modified by:
53eff2a2 6// Created: 03.03.03 (replaces the old file with the same name)
2bda0e17 7// RCS-ID: $Id$
53eff2a2 8// Copyright: (c) 1997-2003 wxWindows team
6d167489 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
53eff2a2
VZ
12#ifndef _WX_MSW_DIB_H_
13#define _WX_MSW_DIB_H_
8fb3a512 14
423a556f 15class WXDLLEXPORT wxBitmap;
6d167489
VZ
16class WXDLLEXPORT wxPalette;
17
53eff2a2
VZ
18#include "wx/msw/private.h"
19
20// ----------------------------------------------------------------------------
21// wxDIB: represents a DIB section
22// ----------------------------------------------------------------------------
23
24class WXDLLEXPORT wxDIB
25{
26public:
27 // ctors and such
28 // --------------
29
30 // create an uninitialized DIB with the given width, height and depth (only
31 // 24 and 32 bpp DIBs are currently supported)
32 //
33 // after using this ctor, GetData() and GetHandle() may be used if IsOk()
34 // returns true
35 wxDIB(int width, int height, int depth)
36 { Init(); (void)Create(width, height, depth); }
37
38 // same as ctor but with return value
39 bool Create(int width, int height, int depth);
40
41 // dtor is not virtual, this class is not meant to be used polymorphically
42 ~wxDIB()
43 {
44 if ( m_handle && !::DeleteObject(m_handle) )
45 {
46 wxLogLastError(wxT("DeleteObject(hDIB)"));
47 }
48 }
49
50
51 // operations
52 // ----------
53
54 // get the handle from the DIB and reset it, i.e. this object won't destroy
55 // the DIB after this (but the caller should do it)
56 HBITMAP Detach() { HBITMAP hbmp = m_handle; m_handle = 0; return hbmp; }
57
58
59 // accessors
60 // ---------
61
62 // return true if DIB was successfully created, false otherwise
63 bool IsOk() const { return m_handle != 0; }
64
65 // get the bitmap size
66 wxSize GetSize() const { DoGetObject(); return wxSize(m_width, m_height); }
67 int GetWidth() const { DoGetObject(); return m_width; }
68 int GetHeight() const { DoGetObject(); return m_height; }
69
70 // get the number of bits per pixel, or depth
71 int GetDepth() const { DoGetObject(); return m_depth; }
72
73 // get the DIB handle
74 HBITMAP GetHandle() const { return m_handle; }
75
76 // get raw pointer to bitmap bits, you should know what you do if you
77 // decide to use it
78 void *GetData() const { DoGetObject(); return m_data; }
79
80
81 // wxImage conversion
82 // ------------------
83
84#if wxUSE_IMAGE
85 // create a DIB from the given image, the DIB will be either 24 or 32 (if
86 // the image has alpha channel) bpp
87 wxDIB(const wxImage& image) { Init(); (void)Create(image); }
88
89 // same as the above ctor but with the return code
90 bool Create(const wxImage& image);
91
92 // create wxImage having the same data as this DIB
93 wxImage ConvertToImage() const;
94#endif // wxUSE_IMAGE
95
96
97 // helper functions
98 // ----------------
99
100 // return the size of one line in a DIB with given width and depth: the
101 // point here is that as the scan lines need to be DWORD aligned so we may
102 // need to add some padding
103 static unsigned long GetLineSize(int width, int depth)
104 {
105 return ((width*depth + 31) & ~31) >> 3;
106 }
107
108private:
109 // common part of all ctors
110 void Init()
111 {
112 m_handle = 0;
113
114 m_data = NULL;
115
116 m_width =
117 m_height =
118 m_depth = 0;
119 }
120
121 // the DIB section handle, 0 if invalid
122 HBITMAP m_handle;
123
124 // NB: we could store only m_handle and not any of the other fields as
125 // we may always retrieve them from it using ::GetObject(), but we
126 // decide to still store them for efficiency concerns -- however if we
127 // don't have them from the very beginning (e.g. DIB constructed from a
128 // bitmap), we only retrieve them when necessary and so these fields
129 // should *never* be accessed directly, even from inside wxDIB code
130
131 // function which must be called before accessing any members and which
132 // gets their values from m_handle, if not done yet
133 void DoGetObject() const;
134
135 // pointer to DIB bits, may be NULL
136 void *m_data;
137
138 // size and depth of the image
139 int m_width,
140 m_height,
141 m_depth;
142
143
144 // DIBs can't be copied
145 wxDIB(const wxDIB&);
146 wxDIB& operator=(const wxDIB&);
147};
148
6d56eb5c 149
6d167489
VZ
150// ----------------------------------------------------------------------------
151// Functions for working with DIBs
152// ----------------------------------------------------------------------------
153
53eff2a2
VZ
154// WARNING: these functions are private to wxWindows and shouldn't be used
155// by the user code, they risk to disappear in the next versions!
156
6d167489
VZ
157// VZ: we have 3 different sets of functions: from bitmap.cpp (wxCreateDIB and
158// wxFreeDIB), from dib.cpp and from dataobj.cpp - surely there is some
159// redundancy between them? (FIXME)
160
161// defined in bitmap.cpp
162extern bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel,
163 HPALETTE hPal, LPBITMAPINFO* lpDIBHeader);
164extern void wxFreeDIB(LPBITMAPINFO lpDIBHeader);
165
166// defined in ole/dataobj.cpp
6d56eb5c
VZ
167extern WXDLLEXPORT size_t wxConvertBitmapToDIB(LPBITMAPINFO pbi, const wxBitmap& bitmap);
168extern WXDLLEXPORT wxBitmap wxConvertDIBToBitmap(const LPBITMAPINFO pbi);
6d167489
VZ
169
170// the rest is defined in dib.cpp
423a556f 171
2bda0e17 172// Save (device dependent) wxBitmap as a DIB
6d167489 173bool wxSaveBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette *colourmap = NULL);
2bda0e17
KB
174
175// Load device independent bitmap into device dependent bitmap
6d56eb5c 176wxBitmap *wxLoadBitmap(wxChar *filename, wxPalette **colourmap = NULL);
2bda0e17
KB
177
178// Load into existing bitmap;
fef15b42 179bool wxLoadIntoBitmap(wxChar *filename, wxBitmap *bitmap, wxPalette **pal = NULL);
2bda0e17 180
a61ddc47
UJ
181HANDLE wxBitmapToDIB (HBITMAP hBitmap, HPALETTE hPal);
182BOOL wxReadDIB(LPTSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette);
183HANDLE wxReadDIB2(LPTSTR lpFileName);
184LPSTR wxFindDIBBits (LPSTR lpbi);
185HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo);
2bda0e17 186
53eff2a2 187#endif // _WX_MSW_DIB_H_
8fb3a512 188