CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

memimage.h

00001 /*
00002     Copyright (C) 2000 by Jorrit Tyberghein
00003     Written by Samuel Humphreys
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSGFX_MEMIMAGE_H__
00021 #define __CS_CSGFX_MEMIMAGE_H__
00022 
00023 #include "csextern.h"
00024 #include "csutil/leakguard.h"
00025 
00026 #include "csgfx/imagebase.h"
00027 #include "csgfx/imagetools.h"
00028 #include "csgfx/rgbpixel.h"
00029 
00033 class CS_CRYSTALSPACE_EXPORT csImageMemory : public csImageBase
00034 {
00035 private:
00037   void ConstructCommon();
00039   void ConstructWHDF (int width, int height, int depth, int format);
00041   void ConstructSource (iImage* source);
00043   void ConstructBuffers (int width, int height, void* buffer, 
00044     bool destroy, int format, csRGBpixel *palette);
00045 protected:
00047   int Width;
00049   int Height;
00051   int Depth;
00058   void* Image;
00060   csRGBpixel *Palette;
00062   uint8 *Alpha;
00064   int Format;
00066   bool has_keycolour;
00068   csRGBpixel keycolour;
00070   bool destroy_image;
00072   csImageType imageType;
00074   /* @@@ This is not csRefArray<iImage> as this does not return csRef<iImage>&
00075    * from GetExtend() or operator[], which is needed here.
00076    */
00077   csArray<csRef<iImage> > mipmaps;
00078 
00083   csImageMemory (int iFormat);
00093   void SetDimensions (int newWidth, int newHeight);
00094   void SetDimensions (int newWidth, int newHeight, int newDepth);
00095 
00097   void AllocImage();
00099   void EnsureImage();
00103   void FreeImage ();
00104 public:
00105   SCF_DECLARE_IBASE;
00106   CS_LEAKGUARD_DECLARE (csImageMemory);
00107 
00115   csImageMemory (int width, int height, int format = CS_IMGFMT_TRUECOLOR);
00124   csImageMemory (int width, int height, int depth, int format);
00137   csImageMemory (int width, int height, void* buffer, bool destroy,
00138     int format = CS_IMGFMT_TRUECOLOR, csRGBpixel *palette = 0);
00149   csImageMemory (int width, int height, const void* buffer, 
00150     int format = CS_IMGFMT_TRUECOLOR, const csRGBpixel *palette = 0);
00155   csImageMemory (iImage* source);
00160   csImageMemory (iImage* source, int newFormat);
00161 
00162   virtual ~csImageMemory ();
00163 
00165   void* GetImagePtr ();
00167   csRGBpixel* GetPalettePtr ();
00169   uint8* GetAlphaPtr ();
00170 
00171   virtual const void *GetImageData () { return GetImagePtr(); }
00172   virtual int GetWidth () const { return Width; }
00173   virtual int GetHeight () const { return Height; }
00174   virtual int GetDepth () const { return Depth; }
00175 
00176   virtual int GetFormat () const { return Format; }
00177   virtual const csRGBpixel* GetPalette () { return GetPalettePtr(); }
00178   virtual const uint8* GetAlpha () { return GetAlphaPtr(); }
00179 
00180   virtual bool HasKeyColor () const { return has_keycolour; }
00181 
00182   virtual void GetKeyColor (int &r, int &g, int &b) const
00183   { r = keycolour.red; g = keycolour.green; b = keycolour.blue; }
00184 
00186   void Clear (const csRGBpixel &colour);
00187 
00189   void CheckAlpha ();
00199   void SetFormat (int iFormat);
00200 
00202   virtual void SetKeyColor (int r, int g, int b);
00203   virtual void SetKeycolor (int r, int g, int b) { SetKeyColor(r,g,b); }
00205   virtual void ClearKeyColor ();
00206   virtual void ClearKeycolor () { ClearKeyColor(); }
00207 
00212   virtual void ApplyKeyColor ();
00213   virtual void ApplyKeycolor () { ApplyKeyColor(); }
00214 
00215   virtual csImageType GetImageType() const { return imageType; }
00216   void SetImageType (csImageType type) { imageType = type; }
00217 
00218   virtual uint HasMipmaps () const 
00219   { 
00220     size_t num = mipmaps.Length();
00221     while ((num > 0) && (mipmaps[num-1] == 0)) num--;
00222     return (uint)num; 
00223   }
00224   virtual csRef<iImage> GetMipmap (uint num) 
00225   { 
00226     if (num == 0) return this;
00227     if (num <= mipmaps.Length()) return mipmaps[num-1];
00228     return 0; 
00229   }
00238   bool SetMipmap (uint num, iImage* mip)
00239   {
00240     if (num == 0) return false;
00241     mipmaps.GetExtend (num-1) = mip;
00242     return true;
00243   }
00244 
00246   bool Copy (iImage* srcImage, int x, int y, int width, int height);
00251   bool CopyScale (iImage* srcImage, int x, int y, int width, int height);
00256   bool CopyTile (iImage* srcImage, int x, int y, int width, int height);
00257 
00269   void ConvertFromRGBA (csRGBpixel* iImage);
00280   void ConvertFromPal8 (uint8* iImage, uint8* alpha, csRGBpixel* iPalette,
00281     int nPalColors = 256);
00292   void ConvertFromPal8 (uint8* iImage, uint8* alpha, 
00293     const csRGBcolor* iPalette, int nPalColors = 256);
00294 };
00295 
00296 #endif // __CS_CSGFX_MEMIMAGE_H__

Generated for Crystal Space by doxygen 1.4.4