OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_pixel.h
1
2/******************************************************************************
3 *
4 * Project: OpenCPN
5 * Purpose: Optimized wxBitmap Object
6 * Author: David Register
7 *
8 ***************************************************************************
9 * Copyright (C) 2010 by David S. Register *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************
26 *
27 *
28 *
29 */
30
31#ifndef _OCPN_PIXEL_H_
32#define _OCPN_PIXEL_H_
33
34//#include "dychart.h" // for configuration stuff
35
36wxImage Image_Rotate(wxImage &base_image, double angle,
37 const wxPoint &centre_of_rotation, bool interpolating,
38 wxPoint *offset_after_rotation);
39
40//--------------------------------------------------------------------------
41// Set the desired compile time conditionals related to display
42// optimization
43//--------------------------------------------------------------------------
44
45// Specify the Pixel Cache type
46// Only one of the following must be selected
47// with due regard for the system type
48
49//#define __PIX_CACHE_WXIMAGE__ // a safe default
50//#define __PIX_CACHE_DIBSECTION__ // for MSW
51//#define __PIX_CACHE_X11IMAGE__ // for
52//X11/Universal, requires ocpnUSE_ocpnBitmap
53
54// I use these shortcuts....
55#ifdef __WXX11__
56#define __PIX_CACHE_WXIMAGE__
57//#define __PIX_CACHE_X11IMAGE__
58#endif
59
60#ifdef __WXGTK__
61#define __PIX_CACHE_WXIMAGE__
62//#define __PIX_CACHE_X11IMAGE__
63//#define __PIX_CACHE_PIXBUF__
64#endif
65
66#ifdef __WXMSW__
67#define __PIX_CACHE_WXIMAGE__
68//#define __PIX_CACHE_DIBSECTION__
69//#define ocpnUSE_DIBSECTION
70//#define ocpnUSE_ocpnBitmap
71#endif
72
73#ifdef __WXOSX__
74#define __PIX_CACHE_WXIMAGE__
75#endif
76
77#ifdef __WXQT__
78#define __PIX_CACHE_WXIMAGE__
79#endif
80
81// Some configuration sanity checks
82
83// Use ocpnBitmap (Optimized wxBitmap)
84// Required for X11 native systems, optional on MSW
85// Also required for GTK PixBuf optimized configuration
86
87#ifdef __PIX_CACHE_X11IMAGE__
88#define ocpnUSE_ocpnBitmap
89#endif
90
91#ifdef __PIX_CACHE_PIXBUF__
92#define ocpnUSE_ocpnBitmap
93#define opcnUSE_GTK_OPTIMIZE
94#endif
95
96// For Optimized X11 systems, use MIT shared memory XImage, requires
97// ocpnUSE_ocpnBitmap
98#ifdef __PIX_CACHE_X11IMAGE__
99#define ocpUSE_MITSHM
100#endif
101
102// The BitsPerPixel value for chart data storage
103// Todo get this during pixcache ctor
104#ifdef __PIX_CACHE_WXIMAGE__ // a safe default
105#define BPP 24
106#endif
107#ifdef __PIX_CACHE_DIBSECTION__ // for MSW
108#define BPP 24
109#endif
110#ifdef __PIX_CACHE_X11IMAGE__ // for X11/Universal
111#define BPP 32
112#endif
113#ifdef __PIX_CACHE_PIXBUF__ // for GTK Optimized
114#define BPP 32
115#endif
116
117// A fall back position is smart....
118#ifndef BPP
119#define BPP 24
120#endif
121
122// Extended includes
123#ifdef __PIX_CACHE_X11IMAGE__
124#include <wx/x11/private.h>
125
126// For MIT-SHM Extensions
127#include <sys/ipc.h>
128#include <sys/shm.h>
129#include <X11/extensions/XShm.h>
130#endif
131
132#ifdef __WXMSW__
133#include <wx/msw/dib.h> // for ocpnMemDC
134#endif
135
136// ============================================================================
137// Declarations
138// ============================================================================
139
140typedef enum RGBO { RGB = 0, BGR } _RGBO;
141
142class ocpnBitmap;
143
144#ifdef __PIX_CACHE_X11IMAGE__
145//----------------------------------------------------------------------
146// ocpnXImage Definition
147//----------------------------------------------------------------------
148class ocpnXImage {
149public:
150 ocpnXImage(int width, int height);
151 ~ocpnXImage();
152 bool PutImage(Pixmap pixmap, GC gc);
153
154 bool buse_mit;
155 XShmSegmentInfo shminfo;
156 XImage *m_img;
157 Display *xdisplay;
158 int xscreen;
159 Visual *xvisual;
160 int bpp;
161 int m_width, m_height;
162};
163#endif
164
165// ============================================================================
166// PixelCache Definition
167// ============================================================================
169public:
170 // Constructors
171
172 PixelCache(int width, int height, int depth);
173 ~PixelCache();
174
175 void SelectIntoDC(wxMemoryDC &dc);
176 void Update(void);
177 RGBO GetRGBO() { return m_rgbo; }
178 unsigned char *GetpData() const;
179 int GetLinePitch() const { return line_pitch_bytes; }
180 int GetWidth(void) { return m_width; }
181 int GetHeight(void) { return m_height; }
182 size_t GetLength(void);
183
184 // Data storage
185private:
186 int m_width;
187 int m_height;
188 int m_depth;
189 int line_pitch_bytes;
190 int bytes_per_pixel;
191 RGBO m_rgbo;
192 unsigned char *pData;
193
194#ifdef ocpnUSE_ocpnBitmap
195 ocpnBitmap *m_pbm;
196#else
197 wxBitmap *m_pbm;
198#endif
199
200 wxImage *m_pimage;
201
202#ifdef __PIX_CACHE_DIBSECTION__
203 wxDIB *m_pDS;
204#endif
205
206#ifdef __PIX_CACHE_X11IMAGE__
207 XImage *m_pxim;
208 Display *xdisplay;
209 ocpnXImage *m_pocpnXI;
210
211#endif
212
213#ifdef ocpUSE_MITSHM
214 XShmSegmentInfo *pshminfo;
215#endif
216
217#ifdef __PIX_CACHE_PIXBUF__
218 unsigned char *m_pdata;
219 GdkPixbuf *m_pixbuf;
220#endif
221};
222
223#ifdef ocpnUSE_ocpnBitmap
224
225//-------------------------------------------------------------------------------
226// ocpn_Bitmap Definition
227// with helpers
228//-------------------------------------------------------------------------------
229
230#ifdef __WXMSW__
231#include <wx/msw/gdiimage.h>
232#include <wx/msw/dib.h>
233#endif
234
235#ifdef __WXX11__
236#include <wx/x11/private.h>
237#endif
238
239class WXDLLEXPORT wxDC;
240class WXDLLEXPORT wxControl;
241class WXDLLEXPORT wxBitmap;
242class WXDLLEXPORT wxBitmapHandler;
243class WXDLLEXPORT wxIcon;
244class WXDLLEXPORT wxMask;
245class WXDLLEXPORT wxCursor;
246class WXDLLEXPORT wxControl;
247class WXDLLEXPORT wxImage;
248class WXDLLEXPORT wxPalette;
249
250// ----------------------------------------------------------------------------
251// ocpnBitmapo: an optimized wxBitmap
252// ----------------------------------------------------------------------------
253
254class /*WXDLLEXPORT*/ ocpnBitmap : public wxBitmap {
255public:
256 // default ctor creates an invalid bitmap, you must Create() it later
257 ocpnBitmap(); //{ Init(); }
258
259 // ctor
260 // Create from Data
261 ocpnBitmap(unsigned char *pPix, int width, int height, int depth) {
262 (void)CreateFromData(pPix, width, height, depth);
263 }
264
265 // ctor
266 // Create from wxImage
267 ocpnBitmap(const wxImage &image, int depth) { CreateFromImage(image, depth); }
268
269#ifdef __WXX11__
270 // Create from ocpnXImage
271 ocpnBitmap(ocpnXImage *ocpn_Ximage, int width, int height, int depth) {
272 CreateFromocpnXImage(ocpn_Ximage, width, height, depth);
273 }
274#endif
275
276 // Implementation
277public:
278protected:
279 // creates the bitmap from data, supposed to be called from ctor
280 bool CreateFromData(void *pPix, int width, int height, int depth);
281
282 // or from wximage
283 bool CreateFromImage(const wxImage &image, int depth);
284
285// or from ocpnXimage
286#ifdef __WXX11__
287 bool CreateFromocpnXImage(ocpnXImage *poXI, int width, int height, int depth);
288#endif
289
290private:
291 DECLARE_DYNAMIC_CLASS(ocpnBitmap)
292};
293
294#endif // ocpnUSE_ocpnBitmap
295
296//----------------------------------------------------------------------------
297// ocpnMemDC Definition
298//----------------------------------------------------------------------------
299
300class /*WXDLLEXPORT*/ ocpnMemDC : public wxMemoryDC {
301public:
302 ocpnMemDC();
303
304 // void SelectObject(const wxBitmap&
305 // bitmap){wxMemoryDC::SelectObject(bitmap);}
306
307 // Satisfy wxX11 2.8.0
308 void SelectObject(wxBitmap &bitmap) { wxMemoryDC::SelectObject(bitmap); }
309
310// Add a method to select a DIB section directly into the DC
311#ifdef ocpnUSE_DIBSECTION
312 void SelectObject(wxDIB &dib);
313#endif
314
315protected:
316private:
317#ifdef ocpnUSE_DIBSECTION
318 wxDIB *m_pselectedDIB;
319#endif
320
321 DECLARE_DYNAMIC_CLASS(ocpnMemDC)
322};
323
324#endif // _OCPN_PIXEL_H_