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