Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXImage.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * I m a g e O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXImage.h,v 1.64 2006/01/22 17:58:05 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXIMAGE_H
25 #define FXIMAGE_H
26 
27 #ifndef FXDRAWABLE_H
28 #include "FXDrawable.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// Image rendering hints
35 enum {
36  IMAGE_KEEP = 0x00000001, /// Keep pixel data in client
37  IMAGE_OWNED = 0x00000002, /// Pixel data is owned by image
38  IMAGE_DITHER = 0, /// Dither image to look better
39  IMAGE_NEAREST = 0x00000004, /// Turn off dithering and map to nearest color
40  IMAGE_OPAQUE = 0x00000008, /// Force opaque background
41  IMAGE_ALPHACOLOR = 0x00000010, /// Override transparancy color
42  IMAGE_SHMI = 0x00000020, /// Using shared memory image
43  IMAGE_SHMP = 0x00000040, /// Using shared memory pixmap
44  IMAGE_ALPHAGUESS = 0x00000080 /// Guess transparency color from corners
45  };
46 
47 
48 class FXDC;
49 class FXDCWindow;
50 
51 
52 /**
53 * An Image is a rectangular array of pixels. It supports two representations
54 * of these pixels: a client-side pixel buffer which is stored as an array of
55 * FXColor, and a server-side pixmap which is stored in an organization directly
56 * compatible with the screen, for fast drawing onto the device.
57 * The server-side representation is not directly accessible from the current
58 * process as it lives in the process of the X Server or GDI.
59 */
60 class FXAPI FXImage : public FXDrawable {
62  friend class FXDC;
63  friend class FXDCWindow;
64 protected:
65  FXColor *data; // Pixel data
66  FXuint options; // Options
67 private:
68 #ifdef WIN32
69  virtual FXID GetDC() const;
70  virtual int ReleaseDC(FXID) const;
71 #endif
72 #ifndef WIN32
73  void render_true_32(void *xim,FXuchar *img);
74  void render_true_24(void *xim,FXuchar *img);
75  void render_true_16_fast(void *xim,FXuchar *img);
76  void render_true_16_dither(void *xim,FXuchar *img);
77  void render_true_8_fast(void *xim,FXuchar *img);
78  void render_true_8_dither(void *xim,FXuchar *img);
79  void render_true_N_fast(void *xim,FXuchar *img);
80  void render_true_N_dither(void *xim,FXuchar *img);
81  void render_index_4_fast(void *xim,FXuchar *img);
82  void render_index_4_dither(void *xim,FXuchar *img);
83  void render_index_8_fast(void *xim,FXuchar *img);
84  void render_index_8_dither(void *xim,FXuchar *img);
85  void render_index_N_fast(void *xim,FXuchar *img);
86  void render_index_N_dither(void *xim,FXuchar *img);
87  void render_gray_8_fast(void *xim,FXuchar *img);
88  void render_gray_8_dither(void *xim,FXuchar *img);
89  void render_gray_N_fast(void *xim,FXuchar *img);
90  void render_gray_N_dither(void *xim,FXuchar *img);
91  void render_mono_1_fast(void *xim,FXuchar *img);
92  void render_mono_1_dither(void *xim,FXuchar *img);
93 #endif
94 protected:
95  FXImage();
96 private:
97  FXImage(const FXImage&);
98  FXImage &operator=(const FXImage&);
99 public:
100 
101  /**
102  * Create an image. If a client-side pixel buffer has been specified,
103  * the image does not own the pixel buffer unless the IMAGE_OWNED flag is
104  * set. If the IMAGE_OWNED flag is set but a NULL pixel buffer is
105  * passed, a pixel buffer will be automatically created and will be owned
106  * by the image. The flags IMAGE_SHMI and IMAGE_SHMP may be specified for
107  * large images to instruct render() to use shared memory to communicate
108  * with the server.
109  */
110  FXImage(FXApp* a,const FXColor *pix=NULL,FXuint opts=0,FXint w=1,FXint h=1);
111 
112  /// Change options
113  void setOptions(FXuint opts);
114 
115  /// To get to the option flags
116  FXuint getOptions() const { return options; }
117 
118  /**
119  * Populate the image with new pixel data of the same size; it will assume
120  * ownership of the pixel data if image IMAGE_OWNED option is passed.
121  * The server-side representation of the image, if it exists, is not updated.
122  * This can be done by calling render().
123  */
124  virtual void setData(FXColor *pix,FXuint opts=0);
125 
126  /**
127  * Populate the image with new pixel data of a new size; it will assume ownership
128  * of the pixel data if image IMAGE_OWNED option is passed. The size of the server-
129  * side representation of the image, if it exists, is adjusted but the contents are
130  * not updated yet. This can be done by calling render().
131  */
132  virtual void setData(FXColor *pix,FXuint opts,FXint w,FXint h);
133 
134  /// Return pointer to the pixel data of the image
135  FXColor* getData() const { return data; }
136 
137  /// Get pixel at x,y
138  FXColor getPixel(FXint x,FXint y) const { return data[y*width+x]; }
139 
140  /// Change pixel at x,y
141  void setPixel(FXint x,FXint y,FXColor color){ data[y*width+x]=color; }
142 
143  /// Scan the image and return false if fully opaque
144  bool hasAlpha() const;
145 
146  /**
147  * Create the server side pixmap, then call render() to fill it with the
148  * pixel data from the client-side buffer. After the server-side image has
149  * been created, the client-side pixel buffer will be deleted unless
150  * IMAGE_KEEP has been specified. If the pixel buffer is not owned, i.e.
151  * the flag IMAGE_OWNED is not set, the pixel buffer will not be deleted,
152  * however the pixel buffer will be set to NULL.
153  */
154  virtual void create();
155 
156  /**
157  * Detach the server side pixmap from the Image.
158  * Afterwards, the Image is left as if it never had a server-side resources.
159  */
160  virtual void detach();
161 
162  /**
163  * Destroy the server-side pixmap.
164  * The client-side pixel buffer is not affected.
165  */
166  virtual void destroy();
167 
168  /**
169  * Retrieves pixels from the server-side image. For example, to make
170  * screen snapshots, or to retrieve an image after it has been drawn
171  * into by various means.
172  */
173  virtual void restore();
174 
175  /**
176  * Render the server-side representation of the image from client-side
177  * pixels. Normally, IMAGE_DITHER is used which causes the server-side
178  * representation to be rendered using a 16x16 ordered dither if necessary;
179  * however if IMAGE_NEAREST is used a faster (but uglier-looking), nearest
180  * neighbor algorithm is used.
181  */
182  virtual void render();
183 
184  /**
185  * Release the client-side pixels buffer, free it if it was owned.
186  * If it is not owned, the image just forgets about the buffer.
187  */
188  virtual void release();
189 
190  /**
191  * Resize both client-side and server-side representations (if any) to the
192  * given width and height. The new representations typically contain garbage
193  * after this operation and need to be re-filled.
194  */
195  virtual void resize(FXint w,FXint h);
196 
197  /**
198  * Rescale pixels image to the specified width and height; this calls
199  * resize() to adjust the client and server side representations.
200  */
201  virtual void scale(FXint w,FXint h,FXint quality=0);
202 
203  /// Mirror image horizontally and/or vertically
204  virtual void mirror(bool horizontal,bool vertical);
205 
206  /**
207  * Rotate image by degrees ccw; this calls resize() to adjust the client
208  * and server side representations if necessary.
209  */
210  virtual void rotate(FXint degrees);
211 
212  /**
213  * Crop image to given rectangle; this calls resize() to adjust the client
214  * and server side representations. The new image may be smaller or larger
215  * than the old one; blank areas are filled with color. There must be at
216  * least one pixel of overlap between the old and the new image.
217  */
218  virtual void crop(FXint x,FXint y,FXint w,FXint h,FXColor color=0);
219 
220  /// Fill image with uniform color
221  virtual void fill(FXColor color);
222 
223  /// Fade image to uniform color
224  virtual void fade(FXColor color,FXint factor=255);
225 
226  /**
227  * Shear image horizontally; the number of pixels is equal to the
228  * shear parameter times 256. The area outside the image is filled
229  * with transparent black, unless another color is specified.
230  */
231  virtual void xshear(FXint shear,FXColor clr=0);
232 
233  /**
234  * Shear image vertically; the number of pixels is equal to the
235  * shear parameter times 256. The area outside the image is filled
236  * with transparent black, unless another color is specified.
237  */
238  virtual void yshear(FXint shear,FXColor clr=0);
239 
240  /// Fill horizontal gradient
241  virtual void hgradient(FXColor left,FXColor right);
242 
243  /// Fill vertical gradient
244  virtual void vgradient(FXColor top,FXColor bottom);
245 
246  /// Fill with gradient
247  virtual void gradient(FXColor topleft,FXColor topright,FXColor bottomleft,FXColor bottomright);
248 
249  /// Blend image over uniform color
250  virtual void blend(FXColor color);
251 
252  /// Save object to stream
253  virtual void save(FXStream& store) const;
254 
255  /// Load object from stream
256  virtual void load(FXStream& store);
257 
258  /// Save pixel data only
259  virtual bool savePixels(FXStream& store) const;
260 
261  /// Load pixel data only
262  virtual bool loadPixels(FXStream& store);
263 
264  /// Destructor
265  virtual ~FXImage();
266  };
267 
268 }
269 
270 #endif
unsigned long FXID
Definition: fxdefs.h:442
unsigned int FXuint
Definition: fxdefs.h:396
#define FXAPI
Definition: fxdefs.h:122
Turn off dithering and map to nearest color.
Definition: FXImage.h:42
Application Object.
Definition: FXApp.h:158
Pixel data is owned by image.
Definition: FXImage.h:40
#define NULL
Definition: fxdefs.h:41
FXuint FXColor
Definition: fxdefs.h:454
Using shared memory image.
Definition: FXImage.h:45
Dither image to look better.
Definition: FXImage.h:41
Keep pixel data in client.
Definition: FXImage.h:39
Abstract Device Context.
Definition: FXDC.h:191
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:397
Override transparancy color.
Definition: FXImage.h:44
Using shared memory pixmap.
Definition: FXImage.h:46
unsigned char FXuchar
Definition: fxdefs.h:392
Window Device Context.
Definition: FXDCWindow.h:52
An Image is a rectangular array of pixels.
Definition: FXImage.h:67
Guess transparency color from corners.
Definition: FXImage.h:47
Force opaque background.
Definition: FXImage.h:43
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Drawable is an abstract base class for any surface that can be drawn upon, such as a FXWindow...
Definition: FXDrawable.h:41

Copyright © 1997-2005 Jeroen van der Zijp