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 return "a8b8g8r8"; 00190 } 00191 virtual csRef<iDataBuffer> GetRawData () const 00192 { 00193 // Should this also call EnsureImage()? 00194 if ((Format & CS_IMGFMT_MASK) == CS_IMGFMT_TRUECOLOR) 00195 return databuf; 00196 CS_ASSERT_MSG ("Not implemented yet: get RGB data from palette", false); 00197 return 0; 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); 00227 virtual void ClearKeyColor (); 00228 00233 virtual void ApplyKeyColor (); 00234 00235 virtual csImageType GetImageType () const { return imageType; } 00236 void SetImageType (csImageType type) { imageType = type; } 00237 00238 virtual uint HasMipmaps () const 00239 { 00240 size_t num = mipmaps.GetSize (); 00241 while ((num > 0) && (mipmaps[num-1] == 0)) num--; 00242 return (uint)num; 00243 } 00244 virtual csRef<iImage> GetMipmap (uint num) 00245 { 00246 if (num == 0) return this; 00247 if (num <= mipmaps.GetSize ()) return mipmaps[num-1]; 00248 return 0; 00249 } 00258 bool SetMipmap (uint num, iImage* mip) 00259 { 00260 if (num == 0) return false; 00261 mipmaps.GetExtend (num-1) = mip; 00262 return true; 00263 } 00264 00266 bool Copy (iImage* srcImage, int x, int y, int width, int height); 00271 bool CopyScale (iImage* srcImage, int x, int y, int width, int height); 00276 bool CopyTile (iImage* srcImage, int x, int y, int width, int height); 00277 00289 void ConvertFromRGBA (csRGBpixel* iImage); 00300 void ConvertFromPal8 (uint8* iImage, uint8* alpha, csRGBpixel* iPalette, 00301 int nPalColors = 256); 00312 void ConvertFromPal8 (uint8* iImage, uint8* alpha, 00313 const csRGBcolor* iPalette, int nPalColors = 256); 00314 }; 00315 00318 #endif // __CS_CSGFX_MEMIMAGE_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1