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

FXImage.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                             I m a g e    O b j e c t                          *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2004 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXImage.h,v 1.54 2004/01/14 06:26:10 fox Exp $                           *
00023 ********************************************************************************/
00024 #ifndef FXIMAGE_H
00025 #define FXIMAGE_H
00026 
00027 #ifndef FXDRAWABLE_H
00028 #include "FXDrawable.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// Image rendering hints
00035 enum {
00036   IMAGE_KEEP       = 0x00000001,      /// Keep pixel data in client
00037   IMAGE_OWNED      = 0x00000002,      /// Pixel data is owned by image
00038   IMAGE_DITHER     = 0,               /// Dither image to look better
00039   IMAGE_NEAREST    = 0x00000004,      /// Turn off dithering and map to nearest color
00040   IMAGE_OPAQUE     = 0x00000008,      /// Force opaque background
00041   IMAGE_ALPHACOLOR = 0x00000010,      /// Override transparancy color
00042   IMAGE_SHMI       = 0x00000020,      /// Using shared memory image
00043   IMAGE_SHMP       = 0x00000040,      /// Using shared memory pixmap
00044   IMAGE_ALPHAGUESS = 0x00000080       /// Guess transparency color from corners
00045   };
00046 
00047 
00048 class FXDC;
00049 class FXDCWindow;
00050 class FXDrawable;
00051 class FXTopWindow;
00052 
00053 
00054 /**
00055 * An Image is a rectangular array of pixels.  It supports two representations
00056 * of these pixels: a client-side pixel buffer which is stored as an array of
00057 * FXColor, and a server-side pixmap which is stored in an organization directly
00058 * compatible with the screen, for fast drawing onto the device.
00059 * The server-side representation is not directly accessible from the current
00060 * process as it lives in the process of the X Server or GDI.
00061 */
00062 class FXAPI FXImage : public FXDrawable {
00063   FXDECLARE(FXImage)
00064   friend class FXDC;
00065   friend class FXDCWindow;
00066   friend class FXDrawable;
00067   friend class FXTopWindow;
00068 protected:
00069   FXColor *data;                // Pixel data
00070   FXuint   options;             // Options
00071 private:
00072 #ifdef WIN32
00073   virtual FXID GetDC() const;
00074   virtual int ReleaseDC(FXID) const;
00075 #endif
00076 #ifndef WIN32
00077   void render_true_32(void *xim,FXuchar *img);
00078   void render_true_24(void *xim,FXuchar *img);
00079   void render_true_16_fast(void *xim,FXuchar *img);
00080   void render_true_16_dither(void *xim,FXuchar *img);
00081   void render_true_8_fast(void *xim,FXuchar *img);
00082   void render_true_8_dither(void *xim,FXuchar *img);
00083   void render_true_N_fast(void *xim,FXuchar *img);
00084   void render_true_N_dither(void *xim,FXuchar *img);
00085   void render_index_4_fast(void *xim,FXuchar *img);
00086   void render_index_4_dither(void *xim,FXuchar *img);
00087   void render_index_8_fast(void *xim,FXuchar *img);
00088   void render_index_8_dither(void *xim,FXuchar *img);
00089   void render_index_N_fast(void *xim,FXuchar *img);
00090   void render_index_N_dither(void *xim,FXuchar *img);
00091   void render_gray_8_fast(void *xim,FXuchar *img);
00092   void render_gray_8_dither(void *xim,FXuchar *img);
00093   void render_gray_N_fast(void *xim,FXuchar *img);
00094   void render_gray_N_dither(void *xim,FXuchar *img);
00095   void render_mono_1_fast(void *xim,FXuchar *img);
00096   void render_mono_1_dither(void *xim,FXuchar *img);
00097 #endif
00098 protected:
00099   FXImage();
00100 private:
00101   FXImage(const FXImage&);
00102   FXImage &operator=(const FXImage&);
00103 public:
00104 
00105   /**
00106   * Create an image.  If a client-side pixel buffer has been specified,
00107   * the image does not own the pixel buffer unless the IMAGE_OWNED flag is
00108   * set.  If the IMAGE_OWNED flag is set but a NULL pixel buffer is
00109   * passed, a pixel buffer will be automatically created and will be owned
00110   * by the image. The flags IMAGE_SHMI and IMAGE_SHMP may be specified for
00111   * large images to instruct render() to use shared memory to communicate
00112   * with the server.
00113   */
00114   FXImage(FXApp* a,const FXColor *pix=NULL,FXuint opts=0,FXint w=1,FXint h=1);
00115 
00116   /// To get to the pixel data
00117   FXColor* getData() const { return data; }
00118 
00119   /// To get to the option flags
00120   FXuint getOptions() const { return options; }
00121 
00122   /// Change options
00123   void setOptions(FXuint opts);
00124 
00125   /// Get pixel at x,y
00126   FXColor getPixel(FXint x,FXint y) const { return data[y*width+x]; }
00127 
00128   /// Change pixel at x,y
00129   void setPixel(FXint x,FXint y,FXColor color){ data[y*width+x]=color; }
00130 
00131   /**
00132   * Create the server side pixmap, then call render() to fill it with the
00133   * pixel data from the client-side buffer.  After the server-side image has
00134   * been created, the client-side pixel buffer will be deleted unless
00135   * IMAGE_KEEP has been specified.  If the pixel buffer is not owned, i.e.
00136   * the flag IMAGE_OWNED is not set, the pixel buffer will not be deleted.
00137   */
00138   virtual void create();
00139 
00140   /**
00141   * Detach the server side pixmap from the Image.
00142   * Afterwards, the Image is left as if it never had a server-side resources.
00143   */
00144   virtual void detach();
00145 
00146   /**
00147   * Destroy the server-side pixmap.
00148   * The client-side pixel buffer is not affected.
00149   */
00150   virtual void destroy();
00151 
00152   /**
00153   * Retrieves pixels from the server-side image.  For example, to make
00154   * screen snapshots, or to retrieve an image after it has been drawin
00155   * into by various means.
00156   */
00157   virtual void restore();
00158 
00159   /**
00160   * Render the server-side representation of the image from client-side
00161   * pixels.  Normally, IMAGE_DITHER is used which causes the server-side
00162   * representation to be rendered using a 16x16 ordered dither if necessary;
00163   * however if IMAGE_NEAREST is used a faster (but uglier-looking), nearest
00164   * neighbor algorithm is used.
00165   */
00166   virtual void render();
00167 
00168   /**
00169   * Release the client-side pixels buffer, free it if it was owned.
00170   * If it is not owned, the image just forgets about the buffer.
00171   */
00172   virtual void release();
00173 
00174   /**
00175   * Resize both client-side and server-side representations (if any) to the
00176   * given width and height.  The new representations typically contain garbage
00177   * after this operation and need to be re-filled.
00178   */
00179   virtual void resize(FXint w,FXint h);
00180 
00181   /**
00182   * Rescale pixels image to the specified width and height; this calls
00183   * resize() to adjust the client and server side representations.
00184   */
00185   virtual void scale(FXint w,FXint h,FXint quality=0);
00186 
00187   /// Mirror image horizontally and/or vertically
00188   virtual void mirror(FXbool horizontal,FXbool vertical);
00189 
00190   /**
00191   * Rotate image by degrees ccw; this calls resize() to adjust the client
00192   * and server side representations if necessary.
00193   */
00194   virtual void rotate(FXint degrees);
00195 
00196   /**
00197   * Crop image to given rectangle; this calls resize() to adjust the client
00198   * and server side representations.
00199   */
00200   virtual void crop(FXint x,FXint y,FXint w,FXint h);
00201 
00202   /// Fill image with uniform color
00203   virtual void fill(FXColor color);
00204 
00205   /// Fade image to uniform color
00206   virtual void fade(FXColor color,FXint factor=255);
00207 
00208   /**
00209   * Shear image horizontally; the number of pixels is equal to the
00210   * shear parameter times 256.  The area outside the image is filled
00211   * with transparent black, unless another color is specified.
00212   */
00213   virtual void xshear(FXint shear,FXColor clr=0);
00214 
00215   /**
00216   * Shear image vertically; the number of pixels is equal to the
00217   * shear parameter times 256.  The area outside the image is filled
00218   * with transparent black, unless another color is specified.
00219   */
00220   virtual void yshear(FXint shear,FXColor clr=0);
00221 
00222   /// Fill horizontal gradient
00223   virtual void hgradient(FXColor left,FXColor right);
00224 
00225   /// Fill vertical gradient
00226   virtual void vgradient(FXColor top,FXColor bottom);
00227 
00228   /// Fill with gradient
00229   virtual void gradient(FXColor topleft,FXColor topright,FXColor bottomleft,FXColor bottomright);
00230 
00231   /// Blend image over uniform color
00232   virtual void blend(FXColor color);
00233 
00234   /// Save object to stream
00235   virtual void save(FXStream& store) const;
00236 
00237   /// Load object from stream
00238   virtual void load(FXStream& store);
00239 
00240   /// Save pixel data only
00241   virtual FXbool savePixels(FXStream& store) const;
00242 
00243   /// Load pixel data only
00244   virtual FXbool loadPixels(FXStream& store);
00245 
00246   /// Destructor
00247   virtual ~FXImage();
00248   };
00249 
00250 }
00251 
00252 #endif

Copyright © 1997-2004 Jeroen van der Zijp