CrystalSpace

Public API Reference

csgfx/imagememory.h

Go to the documentation of this file.
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 #include "csutil/scf_implementation.h"
00026 
00027 #include "csgfx/imagebase.h"
00028 #include "csgfx/imagetools.h"
00029 #include "csgfx/rgbpixel.h"
00030 
00040 class CS_CRYSTALSPACE_EXPORT csImageMemory :
00041   public scfImplementationExt0<csImageMemory, csImageBase>
00042 {
00043 private:
00045   void ConstructCommon();
00047   void ConstructWHDF (int width, int height, int depth, int format);
00049   void ConstructSource (iImage* source);
00051   void ConstructBuffers (int width, int height, void* buffer, 
00052     bool destroy, int format, csRGBpixel *palette);
00053 protected:
00055   int Width;
00057   int Height;
00059   int Depth;
00066   csRef<iDataBuffer> databuf;
00068   csRGBpixel *Palette;
00070   uint8 *Alpha;
00072   int Format;
00074   bool has_keycolour;
00076   csRGBpixel keycolour;
00078   bool destroy_image;
00080   csImageType imageType;
00082   /* @@@ This is not csRefArray<iImage> as this does not return csRef<iImage>&
00083    * from GetExtend() or operator[], which is needed here. (See trac #71)
00084    */
00085   csArray<csRef<iImage> > mipmaps;
00086 
00091   csImageMemory (int iFormat);
00101   void SetDimensions (int newWidth, int newHeight);
00102   void SetDimensions (int newWidth, int newHeight, int newDepth);
00103 
00105   void AllocImage();
00107   void EnsureImage();
00111   void FreeImage ();
00112 
00113   void InternalConvertFromRGBA (iDataBuffer* imageData);
00114   void InternalConvertFromPal8 (iDataBuffer* imageData, uint8* alpha, 
00115     csRGBpixel* iPalette, int nPalColors = 256);
00116 public:
00117   CS_LEAKGUARD_DECLARE (csImageMemory);
00118 
00126   csImageMemory (int width, int height, int format = CS_IMGFMT_TRUECOLOR);
00135   csImageMemory (int width, int height, int depth, int format);
00148   csImageMemory (int width, int height, void* buffer, bool destroy,
00149     int format = CS_IMGFMT_TRUECOLOR, csRGBpixel *palette = 0);
00160   csImageMemory (int width, int height, const void* buffer, 
00161     int format = CS_IMGFMT_TRUECOLOR, const csRGBpixel *palette = 0);
00166   csImageMemory (iImage* source);
00171   csImageMemory (iImage* source, int newFormat);
00172 
00173   virtual ~csImageMemory ();
00174 
00176   void* GetImagePtr ();
00178   csRGBpixel* GetPalettePtr ();
00180   uint8* GetAlphaPtr ();
00181 
00182   virtual const void *GetImageData () { return GetImagePtr(); }
00183   virtual int GetWidth () const { return Width; }
00184   virtual int GetHeight () const { return Height; }
00185   virtual int GetDepth () const { return Depth; }
00186 
00187   virtual const char* GetRawFormat() const 
00188   { 
00189     if ((Format & CS_IMGFMT_MASK) == CS_IMGFMT_TRUECOLOR)
00190       return "a8b8g8r8"; 
00191     else
00192       return 0;
00193   }
00194   virtual csRef<iDataBuffer> GetRawData() const 
00195   { 
00196     // Should this also call EnsureImage()?
00197     return databuf; 
00198   }
00199   virtual int GetFormat () const { return Format; }
00200   virtual const csRGBpixel* GetPalette () { return GetPalettePtr(); }
00201   virtual const uint8* GetAlpha () { return GetAlphaPtr(); }
00202 
00203   virtual bool HasKeyColor () const { return has_keycolour; }
00204 
00205   virtual void GetKeyColor (int &r, int &g, int &b) const
00206   { r = keycolour.red; g = keycolour.green; b = keycolour.blue; }
00207 
00209   void Clear (const csRGBpixel &colour);
00210 
00212   void CheckAlpha ();
00222   void SetFormat (int iFormat);
00223 
00225   virtual void SetKeyColor (int r, int g, int b);
00226   virtual void SetKeycolor (int r, int g, int b) { SetKeyColor(r,g,b); }
00228   virtual void ClearKeyColor ();
00229   virtual void ClearKeycolor () { ClearKeyColor(); }
00230 
00235   virtual void ApplyKeyColor ();
00236   virtual void ApplyKeycolor () { ApplyKeyColor(); }
00237 
00238   virtual csImageType GetImageType() const { return imageType; }
00239   void SetImageType (csImageType type) { imageType = type; }
00240 
00241   virtual uint HasMipmaps () const 
00242   { 
00243     size_t num = mipmaps.GetSize ();
00244     while ((num > 0) && (mipmaps[num-1] == 0)) num--;
00245     return (uint)num; 
00246   }
00247   virtual csRef<iImage> GetMipmap (uint num) 
00248   { 
00249     if (num == 0) return this;
00250     if (num <= mipmaps.GetSize ()) return mipmaps[num-1];
00251     return 0; 
00252   }
00261   bool SetMipmap (uint num, iImage* mip)
00262   {
00263     if (num == 0) return false;
00264     mipmaps.GetExtend (num-1) = mip;
00265     return true;
00266   }
00267 
00269   bool Copy (iImage* srcImage, int x, int y, int width, int height);
00274   bool CopyScale (iImage* srcImage, int x, int y, int width, int height);
00279   bool CopyTile (iImage* srcImage, int x, int y, int width, int height);
00280 
00292   void ConvertFromRGBA (csRGBpixel* iImage);
00303   void ConvertFromPal8 (uint8* iImage, uint8* alpha, csRGBpixel* iPalette,
00304     int nPalColors = 256);
00315   void ConvertFromPal8 (uint8* iImage, uint8* alpha, 
00316     const csRGBcolor* iPalette, int nPalColors = 256);
00317 };
00318 
00321 #endif // __CS_CSGFX_MEMIMAGE_H__

Generated for Crystal Space 1.2.1 by doxygen 1.5.3