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