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,2002 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.32 2002/01/18 22:42:53 jeroen Exp $                        *
00023 ********************************************************************************/
00024 #ifndef FXIMAGE_H
00025 #define FXIMAGE_H
00026 
00027 #ifndef FXDRAWABLE_H
00028 #include "FXDrawable.h"
00029 #endif
00030 
00031 
00032 
00033 /// Image rendering hints
00034 enum {
00035   IMAGE_KEEP       = 0x00000001,      /// Keep pixel data in client
00036   IMAGE_OWNED      = 0x00000002,      /// Pixel data is owned by image
00037   IMAGE_DITHER     = 0,               /// Dither image to look better
00038   IMAGE_NEAREST    = 0x00000004,      /// Turn off dithering and map to nearest color
00039   IMAGE_ALPHA      = 0x00000008,      /// Data has alpha channel
00040   IMAGE_OPAQUE     = 0x00000010,      /// Force opaque background
00041   IMAGE_ALPHACOLOR = 0x00000020,      /// Override transparancy color
00042   IMAGE_SHMI       = 0x00000040,      /// Using shared memory image
00043   IMAGE_SHMP       = 0x00000080,      /// Using shared memory pixmap
00044   IMAGE_ALPHAGUESS = 0x00000100       /// Guess transparency color from corners
00045   };
00046 
00047 
00048 class FXDC;
00049 class FXDCWindow;
00050 class FXDrawable;
00051 class FXTopWindow;
00052 
00053 
00054 /// Image class
00055 class FXAPI FXImage : public FXDrawable {
00056   FXDECLARE(FXImage)
00057   friend class FXDC;
00058   friend class FXDCWindow;
00059   friend class FXDrawable;
00060   friend class FXTopWindow;
00061 private:
00062 #ifdef WIN32
00063   virtual FXID GetDC() const;
00064   virtual int ReleaseDC(FXID) const;
00065 #endif
00066 protected:
00067   FXuchar *data;                // Pixel data
00068   FXuint   options;             // Options
00069   FXuint   channels;            // Number of channels 3 or 4
00070 protected:
00071   FXImage();
00072 #ifndef WIN32
00073   void render_true_32(void *xim,FXuchar *img);
00074   void render_true_24(void *xim,FXuchar *img);
00075   void render_true_16_fast(void *xim,FXuchar *img);
00076   void render_true_16_dither(void *xim,FXuchar *img);
00077   void render_true_8_fast(void *xim,FXuchar *img);
00078   void render_true_8_dither(void *xim,FXuchar *img);
00079   void render_true_N_fast(void *xim,FXuchar *img);
00080   void render_true_N_dither(void *xim,FXuchar *img);
00081   void render_index_4_fast(void *xim,FXuchar *img);
00082   void render_index_4_dither(void *xim,FXuchar *img);
00083   void render_index_8_fast(void *xim,FXuchar *img);
00084   void render_index_8_dither(void *xim,FXuchar *img);
00085   void render_index_N_fast(void *xim,FXuchar *img);
00086   void render_index_N_dither(void *xim,FXuchar *img);
00087   void render_gray_8_fast(void *xim,FXuchar *img);
00088   void render_gray_8_dither(void *xim,FXuchar *img);
00089   void render_gray_N_fast(void *xim,FXuchar *img);
00090   void render_gray_N_dither(void *xim,FXuchar *img);
00091   void render_mono_1_fast(void *xim,FXuchar *img);
00092   void render_mono_1_dither(void *xim,FXuchar *img);
00093 #endif
00094 private:
00095   FXImage(const FXImage&);
00096   FXImage &operator=(const FXImage&);
00097 public:
00098 
00099   /// Create an image
00100   FXImage(FXApp* a,const void *pix=NULL,FXuint opts=0,FXint w=1,FXint h=1);
00101 
00102   /// To get to the pixel data
00103   FXuchar* getData() const { return data; }
00104 
00105   /// To get to the option flags
00106   FXuint getOptions() const { return options; }
00107 
00108   /// Change options
00109   void setOptions(FXuint opts);
00110 
00111   /// Return number of channels, RGB or RGBA
00112   FXint getChannels() const { return channels; }
00113 
00114   /// Get pixel at x,y
00115   FXColor getPixel(FXint x,FXint y) const;
00116 
00117   /// Change pixel at x,y
00118   void setPixel(FXint x,FXint y,FXColor color);
00119 
00120   /// Create image resource
00121   virtual void create();
00122 
00123   /// Detach image resource
00124   virtual void detach();
00125 
00126   /// Destroy image resource
00127   virtual void destroy();
00128 
00129   /// Restore client-side pixel buffer from image
00130   virtual void restore();
00131 
00132   /// Render the image from client-side pixel buffer
00133   virtual void render();
00134 
00135   /// Resize pixmap to the specified width and height
00136   virtual void resize(FXint w,FXint h);
00137 
00138   /// Rescale pixels image to the specified width and height
00139   virtual void scale(FXint w,FXint h);
00140 
00141   /// Mirror image horizontally and/or vertically
00142   virtual void mirror(FXbool horizontal,FXbool vertical);
00143 
00144   /// Rotate image by degrees ccw
00145   virtual void rotate(FXint degrees);
00146 
00147   /// Crop image to given rectangle
00148   virtual void crop(FXint x,FXint y,FXint w,FXint h);
00149 
00150   /// Save object to stream
00151   virtual void save(FXStream& store) const;
00152 
00153   /// Load object from stream
00154   virtual void load(FXStream& store);
00155 
00156   /// Save pixel data only
00157   virtual void savePixels(FXStream& store) const;
00158 
00159   /// Load pixel data only
00160   virtual void loadPixels(FXStream& store);
00161 
00162   /// Destructor
00163   virtual ~FXImage();
00164   };
00165 
00166 
00167 #endif