rasdaman complete source
wx_pixmap.h
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community 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 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community 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 rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
23 
33 #ifndef wx_pixmap_h
34 #define wx_pixmap_h
35 
36 
37 // should be in <wx/defs.h>, but only for OS/2 (?): -- PB 2006-jan-01
38 typedef unsigned long COLORREF;
39 
40 // #include "wx_stat.h"
41 #include <wx/generic/statusbr.h>
42 
43 #ifdef __GNUG__
44 #pragma interface
45 #endif
46 
47 #include "wx/object.h"
48 
49 // changed in new wxWindows
50 //#include "wx_prec.h"
51 #include "wx/wxprec.h"
52 
53 
54 
55 
56 /* Weights for colour matching */
57 #define COLOUR_WEIGHT_RED 4
58 #define COLOUR_WEIGHT_GREEN 9
59 #define COLOUR_WEIGHT_BLUE 1
60 
61 
62 /* No changes below this line should be necessary. */
63 
64 
65 /* Flag bits for initialising functions*/
66 #define WX_PIXFLAG_TRANSLATE 1 /* class-resident mode translation enabled? */
67 #define WX_PIXFLAG_DITHER 2 /* Dither image. Overrides WX_PIXFLAG_TRANSLATE. */
68 #define WX_PIXFLAG_SAMEPALETTE 4 /* The palette is the same as the old one */
69 #define WX_PIXFLAG_FASTDITHER 8 /* Fast rather than best ditherer */
70 #define WX_PIXMODE_PALETTE 1 /* force making new colour tables on a mode change */
71 
72 
73 
74 /* Structure for a permuted colour map (for more efficient colour matching) */
75 typedef struct wx_permute_cmap
76 {
77  unsigned char red, green, blue, number;
79 
80 
81 
82 
83 /*
84  * Translation tables for true-colour-pixmaps to <= 8bpp modes and fast ditherer.
85  * Shared! Define WX_PIXMAP_GLOBAL_VOLATILE to free global translation tables
86  * as soon as no more references to it exist. Default is to keep them.
87  */
88 extern unsigned char *TrueTransTab;
89 extern unsigned char *FastDitherTab;
90 extern int TrueTransCount;
91 extern int FastDitherCount;
92 
93 
94 
95 class wxPixmap;
96 
97 /* Type of pixmap translation function */
98 typedef void (*wx_pixmap_translate)(const unsigned char *src, unsigned char *dest, int width, int height, int srcPitch, int destPitch, const unsigned char *tt);
99 /* Type of pixmap dithering function */
100 typedef void (wxPixmap::*wx_pixmap_dither)(unsigned char *dest, int destPad);
101 /* Type of colour-matching functions (used in ditherers) */
102 typedef int (wxPixmap::*pixmap_colour_match)(unsigned char r, unsigned char g, unsigned char b);
103 
104 
105 /*
106  * Class for efficiently displaying raster images of any depth, initialising
107  * them from binary data.
108  * The macro wx_pixmap_alloc_cols distinguishes between two colour models.
109  * If it's defined the colours are allocated (X), otherwise the current
110  * colourmap is read and processed internally (much faster and usually
111  * much more accurate).
112  */
113 
114 class WXDLLEXPORT wxPixmap : public wxObject
115 {
116 public:
117  /* Public member functions */
118  wxPixmap(void);
119  wxPixmap(wxWindow *Win, int Width, int Height, int Depth, int Pad, char *Data, unsigned int Flags=WX_PIXFLAG_TRANSLATE, wxColour *Palette=NULL);
120  ~wxPixmap(void);
121  int newPixmap(wxWindow *Win, int Width, int Height, int Depth, int Pad, char *Data, unsigned int Flags=WX_PIXFLAG_TRANSLATE, wxColour *Palette=NULL);
122  int plotPixmap(int PosX, int PosY);
123  void invalidatePixmap(void);
124  int getWidth(void);
125  int getHeight(void);
126  int getDepth(void);
127  int getPitch(void);
128  char *getData(void);
129  wxColour *getPalette(void);
130  int getModeDepth(void);
131  int getModePitch(void);
132  char *getModeData(void);
133  unsigned char *getTranslationTable(void);
134  void modeChange(unsigned int Flags);
135  void buildTranslationTable(void);
136  void refreshGlobalTables(void);
137  bool setBusyCursor(bool newMode);
138 #ifndef wx_pixmap_alloc_cols
139  void processParentPalette(bool forceUpdate=FALSE);
140  void processPixmapPalette(void);
141  wx_permute_cmap *getParentPalette(void);
142  int findBestColour(unsigned char red, unsigned char green, unsigned char blue);
143  int findFastColour(unsigned char red, unsigned char green, unsigned char blue);
144  /* Include auto-generated ditherer headers; these need the colour maps set up
145  correctly, so it only works with wx_pixmap_alloc_cols not defined. */
146 #include "wx_pixmap_dither.h"
147 #endif
148 
149 protected:
150  /* protected member functions */
151  void errorMemory(void);
152  void errorGeneric(char *message);
153  void initVariables(void);
154  void freeResources(int Depth, unsigned int Flags);
155  void translateToMode(void);
156  void ditherToMode(void);
157  void getDisplayAttributes(void);
158  void initColoursForMode(bool forceUpdate=FALSE);
159  void setupTranslators(void);
160 #ifndef wx_pixmap_alloc_cols
161  void sortParentPalette(int from, int to); /* Quicksorter */
162  void buildInverseTable(void);
163 #endif
164 
165  /* protected variables */
166  int width, height, depth, pad, pitch; /* parameters for image */
167  int displayDepth, displayPitch, displayPad; /* parameters for current display */
168  char *data; /* Raw source data */
169  char *modeData; /* Translated data suitable for plotting */
170  union
171  {
172  unsigned char *c;
174  } TransTab; /* Colour translation table. */
175  /* COLORREF is defined in wxWindows */
177  wxColour *palette; /* Source data palette */
178  wxWindow *parentWin; /* The parent window date should be plotted to */
179  unsigned int pixFlags;
180 #ifdef wx_pixmap_alloc_cols
181  char ColourAlloc[32]; /* bitfield (256 bits). Bit i set ==> X-colour #i allocated OK. */
182  /* only used for displayDepth <= 8. */
183 #else
185  wx_permute_cmap *parentPalette, *pixmapPalette;
186  unsigned char parentInverse[256];
187 #endif
190  // wxDebugStreamBuf streamBuf; -- PB 2006-jan-01
191  wxOutputStream streamBuf;
192  std::ostream *errorstr;
193  int destBitorder, destByteorder, rgbOrder;
194  wx_pixmap_translate pixtrans1, pixtrans2, pixtrans4, pixtrans8, pixtrans12;
195  wx_pixmap_translate pixtrans15, pixtrans24, pixtrans32;
196  wx_pixmap_dither pixdither1, pixdither2, pixdither4, pixdither8, pixdither12;
197  wx_pixmap_dither pixdither15, pixdither24, pixdither32;
199 
200 #ifdef wx_x
201  /* System Specifics */
202  Display *display;
203  XVisualInfo visualInfo;
204  XImage *xim;
205  XGCValues xgcvals;
206  XWindowAttributes xat;
207  GC myGC;
208  int screen;
209  Window rootwin, windowHandle;
210 #endif
211 
212 #ifdef wx_msw
213  void win_translate_24_to_24(unsigned char *dest);
214 
215  BITMAP bmDesc;
216  HBITMAP bitmap;
218  HWND desktop;
219  HDC rootDC, winDC, srcDC;
220  HGDIOBJ oldDCObject;
221  HPALETTE currentPal;
222 #endif
223 };
224 
225 
226 #endif
XVisualInfo visualInfo
Definition: wx_pixmap.h:203
unsigned char number
Definition: wx_pixmap.h:77
HPALETTE currentPal
Definition: wx_pixmap.h:221
HWND windowHandle
Definition: wx_pixmap.h:217
Display * display
Definition: wx_pixmap.h:202
wx_pixmap_translate pixtrans32
Definition: wx_pixmap.h:195
bool busyCursorMode
Definition: wx_pixmap.h:189
wxWindow * parentWin
Definition: wx_pixmap.h:178
void(wxPixmap::* wx_pixmap_dither)(unsigned char *dest, int destPad)
Definition: wx_pixmap.h:100
unsigned char blue
Definition: wx_pixmap.h:77
bool validDisplay
Definition: wx_pixmap.h:188
wx_pixmap_dither pixdither8
Definition: wx_pixmap.h:196
unsigned char * TrueTransTab
int TransTabSize
Definition: wx_pixmap.h:176
GC myGC
Definition: wx_pixmap.h:207
XWindowAttributes xat
Definition: wx_pixmap.h:206
XGCValues xgcvals
Definition: wx_pixmap.h:205
#define FALSE
Definition: defs.h:70
int FastDitherCount
int TrueTransCount
struct wx_permute_cmap wx_permute_cmap
HWND desktop
Definition: wx_pixmap.h:218
int(wxPixmap::* pixmap_colour_match)(unsigned char r, unsigned char g, unsigned char b)
Definition: wx_pixmap.h:102
wxOutputStream streamBuf
Definition: wx_pixmap.h:191
std::ostream * errorstr
Definition: wx_pixmap.h:192
wx_permute_cmap * pixmapPalette
Definition: wx_pixmap.h:185
unsigned char * FastDitherTab
Definition: wx_pixmap.h:75
BITMAP bmDesc
Definition: wx_pixmap.h:215
int parentPaletteDepth
Definition: wx_pixmap.h:184
unsigned long COLORREF
Definition: wx_pixmap.h:38
int screen
Definition: wx_pixmap.h:208
char * data
Definition: wx_pixmap.h:168
Definition: wx_pixmap.h:114
int width
Definition: wx_pixmap.h:166
int rgbOrder
Definition: wx_pixmap.h:193
void(* wx_pixmap_translate)(const unsigned char *src, unsigned char *dest, int width, int height, int srcPitch, int destPitch, const unsigned char *tt)
Definition: wx_pixmap.h:98
unsigned char green
Definition: wx_pixmap.h:77
wx_pixmap_dither pixdither32
Definition: wx_pixmap.h:197
int height
Definition: wx_pixmap.h:166
pixmap_colour_match colour_matcher
Definition: wx_pixmap.h:198
int displayPitch
Definition: wx_pixmap.h:167
unsigned int pixFlags
Definition: wx_pixmap.h:179
HGDIOBJ oldDCObject
Definition: wx_pixmap.h:220
unsigned char red
Definition: wx_pixmap.h:77
HDC winDC
Definition: wx_pixmap.h:219
unsigned char * c
Definition: wx_pixmap.h:172
HBITMAP bitmap
Definition: wx_pixmap.h:216
COLORREF * l
Definition: wx_pixmap.h:173
char * modeData
Definition: wx_pixmap.h:169
wx_pixmap_translate pixtrans8
Definition: wx_pixmap.h:194
wxColour * palette
Definition: wx_pixmap.h:177
Window windowHandle
Definition: wx_pixmap.h:209
XImage * xim
Definition: wx_pixmap.h:204