summaryrefslogtreecommitdiffstats
path: root/applications/rview/wx_pixmap.h
blob: 8ce86d2dbf35ac0ef690053e1c991af5ddfedef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/

/**
 *  PURPOSE:	
 *		Efficient bitmaps of colour depths 1, 2, 4, 8, 16, 24 and 32bpp
 *  
 *  COMMENTS:
 *     		None
 */


#ifndef wx_pixmap_h
#define wx_pixmap_h


// should be in <wx/defs.h>, but only for OS/2 (?): -- PB 2006-jan-01
typedef unsigned long COLORREF;

// #include "wx_stat.h"
#include <wx/generic/statusbr.h>

#ifdef __GNUG__
#pragma interface
#endif

#include "wx/object.h"

// changed in new wxWindows
//#include "wx_prec.h"
#include "wx/wxprec.h"




/* Weights for colour matching */
#define COLOUR_WEIGHT_RED	4
#define COLOUR_WEIGHT_GREEN	9
#define COLOUR_WEIGHT_BLUE	1


/* No changes below this line should be necessary. */


/* Flag bits for initialising functions*/
#define WX_PIXFLAG_TRANSLATE		1	/* class-resident mode translation enabled? */
#define WX_PIXFLAG_DITHER		2	/* Dither image. Overrides WX_PIXFLAG_TRANSLATE. */
#define WX_PIXFLAG_SAMEPALETTE		4	/* The palette is the same as the old one */
#define WX_PIXFLAG_FASTDITHER		8	/* Fast rather than best ditherer */
#define WX_PIXMODE_PALETTE		1	/* force making new colour tables on a mode change */



/* Structure for a permuted colour map (for more efficient colour matching) */
typedef struct wx_permute_cmap {
  unsigned char red, green, blue, number;
} wx_permute_cmap;




/*
 *  Translation tables for true-colour-pixmaps to <= 8bpp modes and fast ditherer.
 *  Shared! Define WX_PIXMAP_GLOBAL_VOLATILE to free global translation tables
 *  as soon as no more references to it exist. Default is to keep them.
 */
extern unsigned char *TrueTransTab;
extern unsigned char *FastDitherTab;
extern int TrueTransCount;
extern int FastDitherCount;



class wxPixmap;

/* Type of pixmap translation function */
typedef void (*wx_pixmap_translate)(const unsigned char *src, unsigned char *dest, int width, int height, int srcPitch, int destPitch, const unsigned char *tt);
/* Type of pixmap dithering function */
typedef void (wxPixmap::*wx_pixmap_dither)(unsigned char *dest, int destPad);
/* Type of colour-matching functions (used in ditherers) */
typedef int (wxPixmap::*pixmap_colour_match)(unsigned char r, unsigned char g, unsigned char b);


/*
 *  Class for efficiently displaying raster images of any depth, initialising
 *  them from binary data.
 *  The macro wx_pixmap_alloc_cols distinguishes between two colour models.
 *  If it's defined the colours are allocated (X), otherwise the current
 *  colourmap is read and processed internally (much faster and usually
 *  much more accurate).
 */

class WXDLLEXPORT wxPixmap : public wxObject
{
  public:
  /* Public member functions */
  wxPixmap(void);
  wxPixmap(wxWindow *Win, int Width, int Height, int Depth, int Pad, char *Data, unsigned int Flags=WX_PIXFLAG_TRANSLATE, wxColour *Palette=NULL);
  ~wxPixmap(void);
  int newPixmap(wxWindow *Win, int Width, int Height, int Depth, int Pad, char *Data, unsigned int Flags=WX_PIXFLAG_TRANSLATE, wxColour *Palette=NULL);
  int plotPixmap(int PosX, int PosY);
  void invalidatePixmap(void);
  int getWidth(void);
  int getHeight(void);
  int getDepth(void);
  int getPitch(void);
  char *getData(void);
  wxColour *getPalette(void);
  int getModeDepth(void);
  int getModePitch(void);
  char *getModeData(void);
  unsigned char *getTranslationTable(void);
  void modeChange(unsigned int Flags);
  void buildTranslationTable(void);
  void refreshGlobalTables(void);
  bool setBusyCursor(bool newMode);
#ifndef wx_pixmap_alloc_cols
  void processParentPalette(bool forceUpdate=FALSE);
  void processPixmapPalette(void);
  wx_permute_cmap *getParentPalette(void);
  int findBestColour(unsigned char red, unsigned char green, unsigned char blue);
  int findFastColour(unsigned char red, unsigned char green, unsigned char blue);
  /* Include auto-generated ditherer headers; these need the colour maps set up
     correctly, so it only works with wx_pixmap_alloc_cols not defined. */
#include "wx_pixmap_dither.h"
#endif

  protected:
  /* protected member functions */
  void errorMemory(void);
  void errorGeneric(char *message);
  void initVariables(void);
  void freeResources(int Depth, unsigned int Flags);
  void translateToMode(void);
  void ditherToMode(void);
  void getDisplayAttributes(void);
  void initColoursForMode(bool forceUpdate=FALSE);
  void setupTranslators(void);
#ifndef wx_pixmap_alloc_cols
  void sortParentPalette(int from, int to);	/* Quicksorter */
  void buildInverseTable(void);
#endif

  /* protected variables */
  int width, height, depth, pad, pitch;		/* parameters for image */
  int displayDepth, displayPitch, displayPad;	/* parameters for current display */
  char *data;		/* Raw source data */
  char *modeData;	/* Translated data suitable for plotting */
  union {unsigned char *c; COLORREF *l;} TransTab;	/* Colour translation table. */
							/* COLORREF is defined in wxWindows */
  int TransTabSize;
  wxColour *palette;	/* Source data palette */
  wxWindow *parentWin;	/* The parent window date should be plotted to */
  unsigned int pixFlags;
#ifdef wx_pixmap_alloc_cols
  char ColourAlloc[32];	/* bitfield (256 bits). Bit i set ==> X-colour #i allocated OK. */
			/* only used for displayDepth <= 8. */
#else
  int parentPaletteDepth;
  wx_permute_cmap *parentPalette, *pixmapPalette;
  unsigned char parentInverse[256];
#endif
  bool validDisplay;
  bool busyCursorMode;
  // wxDebugStreamBuf streamBuf; -- PB 2006-jan-01
  wxOutputStream streamBuf;
  std::ostream *errorstr;
  int destBitorder, destByteorder, rgbOrder;
  wx_pixmap_translate pixtrans1, pixtrans2, pixtrans4, pixtrans8, pixtrans12;
  wx_pixmap_translate pixtrans15, pixtrans24, pixtrans32;
  wx_pixmap_dither pixdither1, pixdither2, pixdither4, pixdither8, pixdither12;
  wx_pixmap_dither pixdither15, pixdither24, pixdither32;
  pixmap_colour_match colour_matcher;

#ifdef wx_x
  /* System Specifics */
  Display *display;
  XVisualInfo visualInfo;
  XImage *xim;
  XGCValues xgcvals;
  XWindowAttributes xat;
  GC myGC;
  int screen;
  Window rootwin, windowHandle;
#endif

#ifdef wx_msw
  void win_translate_24_to_24(unsigned char *dest);

  BITMAP bmDesc;
  HBITMAP bitmap;
  HWND windowHandle;
  HWND desktop;
  HDC rootDC, winDC, srcDC;
  HGDIOBJ oldDCObject;
  HPALETTE currentPal;
#endif
};


#endif