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 36 wxImage Image_Rotate(wxImage &base_image, double angle, const wxPoint & centre_of_rotation, bool interpolating, wxPoint * offset_after_rotation); 37 38 //-------------------------------------------------------------------------- 39 // Set the desired compile time conditionals related to display optimization 40 //-------------------------------------------------------------------------- 41 42 43 44 // Specify the Pixel Cache type 45 // Only one of the following must be selected 46 // with due regard for the system type 47 48 //#define __PIX_CACHE_WXIMAGE__ // a safe default 49 //#define __PIX_CACHE_DIBSECTION__ // for MSW 50 //#define __PIX_CACHE_X11IMAGE__ // for X11/Universal, requires ocpnUSE_ocpnBitmap 51 52 // I use these shortcuts.... 53 #ifdef __WXX11__ 54 #define __PIX_CACHE_WXIMAGE__ 55 //#define __PIX_CACHE_X11IMAGE__ 56 #endif 57 58 #ifdef __WXGTK__ 59 #define __PIX_CACHE_WXIMAGE__ 60 //#define __PIX_CACHE_X11IMAGE__ 61 //#define __PIX_CACHE_PIXBUF__ 62 #endif 63 64 #ifdef __WXMSW__ 65 #define __PIX_CACHE_WXIMAGE__ 66 //#define __PIX_CACHE_DIBSECTION__ 67 //#define ocpnUSE_DIBSECTION 68 //#define ocpnUSE_ocpnBitmap 69 #endif 70 71 #ifdef __WXOSX__ 72 #define __PIX_CACHE_WXIMAGE__ 73 #endif 74 75 #ifdef __WXQT__ 76 #define __PIX_CACHE_WXIMAGE__ 77 #endif 78 79 // Some configuration sanity checks 80 81 // Use ocpnBitmap (Optimized wxBitmap) 82 // Required for X11 native systems, optional on MSW 83 // Also required for GTK PixBuf optimized configuration 84 85 #ifdef __PIX_CACHE_X11IMAGE__ 86 #define ocpnUSE_ocpnBitmap 87 #endif 88 89 #ifdef __PIX_CACHE_PIXBUF__ 90 #define ocpnUSE_ocpnBitmap 91 #define opcnUSE_GTK_OPTIMIZE 92 #endif 93 94 95 // For Optimized X11 systems, use MIT shared memory XImage, requires ocpnUSE_ocpnBitmap 96 #ifdef __PIX_CACHE_X11IMAGE__ 97 #define ocpUSE_MITSHM 98 #endif 99 100 101 // The BitsPerPixel value for chart data storage 102 // Todo get this during pixcache ctor 103 #ifdef __PIX_CACHE_WXIMAGE__ // a safe default 104 #define BPP 24 105 #endif 106 #ifdef __PIX_CACHE_DIBSECTION__ // for MSW 107 #define BPP 24 108 #endif 109 #ifdef __PIX_CACHE_X11IMAGE__ // for X11/Universal 110 #define BPP 32 111 #endif 112 #ifdef __PIX_CACHE_PIXBUF__ // for GTK Optimized 113 #define BPP 32 114 #endif 115 116 // A fall back position is smart.... 117 #ifndef BPP 118 #define BPP 24 119 #endif 120 121 // Extended includes 122 #ifdef __PIX_CACHE_X11IMAGE__ 123 #include "wx/x11/private.h" 124 125 // For MIT-SHM Extensions 126 #include <sys/ipc.h> 127 #include <sys/shm.h> 128 #include <X11/extensions/XShm.h> 129 #endif 130 131 #ifdef __WXMSW__ 132 #include "wx/msw/dib.h" // for ocpnMemDC 133 #endif 134 135 // ============================================================================ 136 // Declarations 137 // ============================================================================ 138 139 typedef enum RGBO 140 { 141 RGB = 0, 142 BGR 143 }_RGBO; 144 145 class ocpnBitmap; 146 147 #ifdef __PIX_CACHE_X11IMAGE__ 148 //---------------------------------------------------------------------- 149 // ocpnXImage Definition 150 //---------------------------------------------------------------------- 151 class ocpnXImage 152 { 153 public: 154 ocpnXImage(int width, int height); 155 ~ocpnXImage(); 156 bool PutImage(Pixmap pixmap, GC gc); 157 158 bool buse_mit; 159 XShmSegmentInfo shminfo; 160 XImage *m_img; 161 Display *xdisplay; 162 int xscreen; 163 Visual *xvisual; 164 int bpp; 165 int m_width, m_height; 166 }; 167 #endif 168 169 170 171 172 // ============================================================================ 173 // PixelCache Definition 174 // ============================================================================ 175 class PixelCache 176 { 177 public: 178 179 // Constructors 180 181 PixelCache(int width, int height, int depth); 182 ~PixelCache(); 183 184 void SelectIntoDC(wxMemoryDC &dc); 185 void Update(void); GetRGBO()186 RGBO GetRGBO(){return m_rgbo;} 187 unsigned char *GetpData() const; GetLinePitch()188 int GetLinePitch() const { return line_pitch_bytes; } GetWidth(void)189 int GetWidth(void){ return m_width; } GetHeight(void)190 int GetHeight(void){ return m_height; } 191 size_t GetLength(void); 192 193 // Data storage 194 private: 195 int m_width; 196 int m_height; 197 int m_depth; 198 int line_pitch_bytes; 199 int bytes_per_pixel; 200 RGBO m_rgbo; 201 unsigned char *pData; 202 203 #ifdef ocpnUSE_ocpnBitmap 204 ocpnBitmap *m_pbm; 205 #else 206 wxBitmap *m_pbm; 207 #endif 208 209 wxImage *m_pimage; 210 211 #ifdef __PIX_CACHE_DIBSECTION__ 212 wxDIB *m_pDS; 213 #endif 214 215 #ifdef __PIX_CACHE_X11IMAGE__ 216 XImage *m_pxim; 217 Display *xdisplay; 218 ocpnXImage *m_pocpnXI; 219 220 #endif 221 222 #ifdef ocpUSE_MITSHM 223 XShmSegmentInfo *pshminfo; 224 #endif 225 226 #ifdef __PIX_CACHE_PIXBUF__ 227 unsigned char *m_pdata; 228 GdkPixbuf *m_pixbuf; 229 #endif 230 231 232 }; 233 234 235 #ifdef ocpnUSE_ocpnBitmap 236 237 //------------------------------------------------------------------------------- 238 // ocpn_Bitmap Definition 239 // with helpers 240 //------------------------------------------------------------------------------- 241 242 243 #ifdef __WXMSW__ 244 #include "wx/msw/gdiimage.h" 245 #include "wx/msw/dib.h" 246 #endif 247 248 #ifdef __WXX11__ 249 #include "wx/x11/private.h" 250 #endif 251 252 class WXDLLEXPORT wxDC; 253 class WXDLLEXPORT wxControl; 254 class WXDLLEXPORT wxBitmap; 255 class WXDLLEXPORT wxBitmapHandler; 256 class WXDLLEXPORT wxIcon; 257 class WXDLLEXPORT wxMask; 258 class WXDLLEXPORT wxCursor; 259 class WXDLLEXPORT wxControl; 260 class WXDLLEXPORT wxImage; 261 class WXDLLEXPORT wxPalette; 262 263 // ---------------------------------------------------------------------------- 264 // ocpnBitmapo: an optimized wxBitmap 265 // ---------------------------------------------------------------------------- 266 267 class /*WXDLLEXPORT*/ ocpnBitmap : public wxBitmap 268 { 269 public: 270 // default ctor creates an invalid bitmap, you must Create() it later 271 ocpnBitmap(); //{ Init(); } 272 273 // ctor 274 // Create from Data ocpnBitmap(unsigned char * pPix,int width,int height,int depth)275 ocpnBitmap(unsigned char *pPix, int width, int height, int depth) 276 { (void)CreateFromData(pPix, width, height, depth );} 277 278 // ctor 279 // Create from wxImage ocpnBitmap(const wxImage & image,int depth)280 ocpnBitmap(const wxImage& image, int depth) 281 { CreateFromImage(image, depth );} 282 283 284 285 #ifdef __WXX11__ 286 // Create from ocpnXImage ocpnBitmap(ocpnXImage * ocpn_Ximage,int width,int height,int depth)287 ocpnBitmap(ocpnXImage *ocpn_Ximage, int width, int height, int depth) 288 {CreateFromocpnXImage( ocpn_Ximage, width, height, depth );} 289 #endif 290 291 292 293 // Implementation 294 public: 295 296 297 protected: 298 // creates the bitmap from data, supposed to be called from ctor 299 bool CreateFromData(void *pPix, int width, int height, int depth); 300 301 // or from wximage 302 bool CreateFromImage( const wxImage& image, int depth ); 303 304 305 // or from ocpnXimage 306 #ifdef __WXX11__ 307 bool CreateFromocpnXImage( ocpnXImage *poXI, int width, int height, int depth ); 308 #endif 309 310 private: 311 312 DECLARE_DYNAMIC_CLASS(ocpnBitmap) 313 }; 314 315 316 #endif // ocpnUSE_ocpnBitmap 317 318 319 320 //---------------------------------------------------------------------------- 321 // ocpnMemDC Definition 322 //---------------------------------------------------------------------------- 323 324 class /*WXDLLEXPORT*/ ocpnMemDC : public wxMemoryDC 325 { 326 public: 327 ocpnMemDC(); 328 329 // void SelectObject(const wxBitmap& bitmap){wxMemoryDC::SelectObject(bitmap);} 330 331 // Satisfy wxX11 2.8.0 SelectObject(wxBitmap & bitmap)332 void SelectObject(wxBitmap& bitmap){wxMemoryDC::SelectObject(bitmap);} 333 334 // Add a method to select a DIB section directly into the DC 335 #ifdef ocpnUSE_DIBSECTION 336 void SelectObject(wxDIB& dib); 337 #endif 338 339 protected: 340 341 private: 342 #ifdef ocpnUSE_DIBSECTION 343 wxDIB *m_pselectedDIB; 344 #endif 345 346 DECLARE_DYNAMIC_CLASS(ocpnMemDC) 347 }; 348 349 #endif // _OCPN_PIXEL_H_ 350