/***********************************************************************
 * FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
 * Copyright (c) 2001-2003 by J. Lyle Johnson. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For further information please contact the author by e-mail
 * at "lyle@users.sourceforge.net".
 ***********************************************************************/

/// Image rendering hints
enum {
  IMAGE_KEEP       = 0x00000001,      /// Keep pixel data in client
  IMAGE_OWNED      = 0x00000002,      /// Pixel data is owned by image
  IMAGE_DITHER     = 0,               /// Dither image to look better
  IMAGE_NEAREST    = 0x00000004,      /// Turn off dithering and map to nearest color
  IMAGE_ALPHA      = 0x00000008,      /// Data has alpha channel
  IMAGE_OPAQUE     = 0x00000010,      /// Force opaque background
  IMAGE_ALPHACOLOR = 0x00000020,      /// Override transparancy color
  IMAGE_SHMI       = 0x00000040,      /// Using shared memory image
  IMAGE_SHMP       = 0x00000080,      /// Using shared memory pixmap
  IMAGE_ALPHAGUESS = 0x00000100       /// Guess transparency color from corners
  };


/// Image class
class FXImage : public FXDrawable {
protected:
  FXuchar *data;                // Pixel data
  FXuint   options;             // Options
  FXuint   channels;            // Number of channels 3 or 4
protected:
  FXImage();
#ifndef WIN32
  void render_true_32(void *xim,FXuchar *img);
  void render_true_24(void *xim,FXuchar *img);
  void render_true_16_fast(void *xim,FXuchar *img);
  void render_true_16_dither(void *xim,FXuchar *img);
  void render_true_8_fast(void *xim,FXuchar *img);
  void render_true_8_dither(void *xim,FXuchar *img);
  void render_true_N_fast(void *xim,FXuchar *img);
  void render_true_N_dither(void *xim,FXuchar *img);
  void render_index_4_fast(void *xim,FXuchar *img);
  void render_index_4_dither(void *xim,FXuchar *img);
  void render_index_8_fast(void *xim,FXuchar *img);
  void render_index_8_dither(void *xim,FXuchar *img);
  void render_index_N_fast(void *xim,FXuchar *img);
  void render_index_N_dither(void *xim,FXuchar *img);
  void render_gray_8_fast(void *xim,FXuchar *img);
  void render_gray_8_dither(void *xim,FXuchar *img);
  void render_gray_N_fast(void *xim,FXuchar *img);
  void render_gray_N_dither(void *xim,FXuchar *img);
  void render_mono_1_fast(void *xim,FXuchar *img);
  void render_mono_1_dither(void *xim,FXuchar *img);
#endif
public:
  %extend {
    /// Create an image
    FXImage(FXApp* a,const void *IMGPIXELS=NULL,FXuint opts=0,FXint w=1,FXint h=1){
      return new FXRbImage(a,IMGPIXELS,opts,w,h);
      }
    }

  /// To get to the pixel data
  %extend {
    FXMemoryBuffer *getData() const {
      return new FXMemoryBuffer(self->getData(),self->getChannels()*self->getWidth()*self->getHeight());
      }
  }
  
  /// To get to the option flags
  FXuint getOptions() const;

  /// Change options
  void setOptions(FXuint opts);

  /// Return number of channels, RGB or RGBA
  FXint getChannels() const;

  /// Get pixel at x,y
  FXColor getPixel(FXint x,FXint y) const;

  /// Change pixel at x,y
  void setPixel(FXint x,FXint y,FXColor color);

  /// Destructor
  virtual ~FXImage();
  };


DECLARE_FXOBJECT_VIRTUALS(FXImage)
DECLARE_FXID_VIRTUALS(FXImage)
DECLARE_FXDRAWABLE_VIRTUALS(FXImage)
DECLARE_FXIMAGE_VIRTUALS(FXImage)

%{
static swig_type_info *FXImage_dynamic_cast(void **ptr) {
    FXImage **ppImage = reinterpret_cast<FXImage **>(ptr);
    FXBMPImage *pBMPImage=dynamic_cast<FXBMPImage*>(*ppImage);
    if(pBMPImage){
      *ptr=reinterpret_cast<void*>(pBMPImage);
      return SWIG_TypeQuery("FXBMPImage *");
      }
    FXGIFImage *pGIFImage=dynamic_cast<FXGIFImage*>(*ppImage);
    if(pGIFImage){
      *ptr=reinterpret_cast<void*>(pGIFImage);
      return SWIG_TypeQuery("FXGIFImage *");
      }
    FXICOImage *pICOImage=dynamic_cast<FXICOImage*>(*ppImage);
    if(pICOImage){
      *ptr=reinterpret_cast<void*>(pICOImage);
      return SWIG_TypeQuery("FXICOImage *");
      }
    FXIcon *pIcon=dynamic_cast<FXIcon*>(*ppImage);
    if(pIcon){
      *ptr=reinterpret_cast<void*>(pIcon);
      return SWIG_TypeQuery("FXIcon *");
      }
    FXJPGImage *pJPGImage=dynamic_cast<FXJPGImage*>(*ppImage);
    if(pJPGImage){
      *ptr=reinterpret_cast<void*>(pJPGImage);
      return SWIG_TypeQuery("FXJPGImage *");
      }
    FXPCXImage *pPCXImage=dynamic_cast<FXPCXImage*>(*ppImage);
    if(pPCXImage){
      *ptr=reinterpret_cast<void*>(pPCXImage);
      return SWIG_TypeQuery("FXPCXImage *");
      }
    FXPNGImage *pPNGImage=dynamic_cast<FXPNGImage*>(*ppImage);
    if(pPNGImage){
      *ptr=reinterpret_cast<void*>(pPNGImage);
      return SWIG_TypeQuery("FXPNGImage *");
      }
    FXRGBImage *pRGBImage=dynamic_cast<FXRGBImage*>(*ppImage);
    if(pRGBImage){
      *ptr=reinterpret_cast<void*>(pRGBImage);
      return SWIG_TypeQuery("FXRGBImage *");
      }
    FXTGAImage *pTGAImage=dynamic_cast<FXTGAImage*>(*ppImage);
    if(pTGAImage){
      *ptr=reinterpret_cast<void*>(pTGAImage);
      return SWIG_TypeQuery("FXTGAImage *");
      }
    FXTIFImage *pTIFImage=dynamic_cast<FXTIFImage*>(*ppImage);
    if(pTIFImage){
      *ptr=reinterpret_cast<void*>(pTIFImage);
      return SWIG_TypeQuery("FXTIFImage *");
      }
    FXXPMImage *pXPMImage=dynamic_cast<FXXPMImage*>(*ppImage);
    if(pXPMImage){
      *ptr=reinterpret_cast<void*>(pXPMImage);
      return SWIG_TypeQuery("FXXPMImage *");
      }
    return 0;
}
%}

DYNAMIC_CAST(SWIGTYPE_p_FXImage, FXImage_dynamic_cast);

