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 void* Image; 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. 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 public: 00113 CS_LEAKGUARD_DECLARE (csImageMemory); 00114 00122 csImageMemory (int width, int height, int format = CS_IMGFMT_TRUECOLOR); 00131 csImageMemory (int width, int height, int depth, int format); 00144 csImageMemory (int width, int height, void* buffer, bool destroy, 00145 int format = CS_IMGFMT_TRUECOLOR, csRGBpixel *palette = 0); 00156 csImageMemory (int width, int height, const void* buffer, 00157 int format = CS_IMGFMT_TRUECOLOR, const csRGBpixel *palette = 0); 00162 csImageMemory (iImage* source); 00167 csImageMemory (iImage* source, int newFormat); 00168 00169 virtual ~csImageMemory (); 00170 00172 void* GetImagePtr (); 00174 csRGBpixel* GetPalettePtr (); 00176 uint8* GetAlphaPtr (); 00177 00178 virtual const void *GetImageData () { return GetImagePtr(); } 00179 virtual int GetWidth () const { return Width; } 00180 virtual int GetHeight () const { return Height; } 00181 virtual int GetDepth () const { return Depth; } 00182 00183 virtual int GetFormat () const { return Format; } 00184 virtual const csRGBpixel* GetPalette () { return GetPalettePtr(); } 00185 virtual const uint8* GetAlpha () { return GetAlphaPtr(); } 00186 00187 virtual bool HasKeyColor () const { return has_keycolour; } 00188 00189 virtual void GetKeyColor (int &r, int &g, int &b) const 00190 { r = keycolour.red; g = keycolour.green; b = keycolour.blue; } 00191 00193 void Clear (const csRGBpixel &colour); 00194 00196 void CheckAlpha (); 00206 void SetFormat (int iFormat); 00207 00209 virtual void SetKeyColor (int r, int g, int b); 00210 virtual void SetKeycolor (int r, int g, int b) { SetKeyColor(r,g,b); } 00212 virtual void ClearKeyColor (); 00213 virtual void ClearKeycolor () { ClearKeyColor(); } 00214 00219 virtual void ApplyKeyColor (); 00220 virtual void ApplyKeycolor () { ApplyKeyColor(); } 00221 00222 virtual csImageType GetImageType() const { return imageType; } 00223 void SetImageType (csImageType type) { imageType = type; } 00224 00225 virtual uint HasMipmaps () const 00226 { 00227 size_t num = mipmaps.Length(); 00228 while ((num > 0) && (mipmaps[num-1] == 0)) num--; 00229 return (uint)num; 00230 } 00231 virtual csRef<iImage> GetMipmap (uint num) 00232 { 00233 if (num == 0) return this; 00234 if (num <= mipmaps.Length()) return mipmaps[num-1]; 00235 return 0; 00236 } 00245 bool SetMipmap (uint num, iImage* mip) 00246 { 00247 if (num == 0) return false; 00248 mipmaps.GetExtend (num-1) = mip; 00249 return true; 00250 } 00251 00253 bool Copy (iImage* srcImage, int x, int y, int width, int height); 00258 bool CopyScale (iImage* srcImage, int x, int y, int width, int height); 00263 bool CopyTile (iImage* srcImage, int x, int y, int width, int height); 00264 00276 void ConvertFromRGBA (csRGBpixel* iImage); 00287 void ConvertFromPal8 (uint8* iImage, uint8* alpha, csRGBpixel* iPalette, 00288 int nPalColors = 256); 00299 void ConvertFromPal8 (uint8* iImage, uint8* alpha, 00300 const csRGBcolor* iPalette, int nPalColors = 256); 00301 }; 00302 00305 #endif // __CS_CSGFX_MEMIMAGE_H__
Generated for Crystal Space by doxygen 1.4.7