csplugincommon/imageloader/commonimagefile.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2005 by Jorrit Tyberghein 00003 2005 by Frank Richter 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_CSPLUGINCOMMON_IMAGELOADER_COMMONIMAGEFILE_H__ 00021 #define __CS_CSPLUGINCOMMON_IMAGELOADER_COMMONIMAGEFILE_H__ 00022 00027 #include "csextern.h" 00028 #include "csgfx/imagememory.h" 00029 #include "csutil/ref.h" 00030 #include "csutil/scf_interface.h" 00031 #include "csutil/scf_implementation.h" 00032 #include "iutil/databuff.h" 00033 #include "iutil/job.h" 00034 00035 struct iObjectRegistry; 00036 00045 enum csLoaderDataType 00046 { 00048 rdtInvalid, 00050 rdtR8G8B8, 00052 rdtRGBpixel, 00054 rdtIndexed 00055 }; 00056 00057 class csCommonImageFile; 00058 00063 struct iImageFileLoader : public virtual iBase 00064 { 00065 SCF_INTERFACE(iImageFileLoader, 2,0,0); 00067 virtual bool LoadData () = 0; 00069 virtual csRef<iDataBuffer> GetRawData() = 0; 00071 virtual csLoaderDataType GetDataType() = 0; 00073 virtual int GetWidth() = 0; 00075 virtual int GetHeight() = 0; 00077 virtual int GetFormat() = 0; 00079 virtual void ApplyTo (csImageMemory* image) = 0; 00081 virtual bool HasKeyColor() const = 0; 00083 virtual void GetKeyColor (int &r, int &g, int &b) const = 0; 00084 }; 00085 00089 class CS_CRYSTALSPACE_EXPORT csCommonImageFileLoader : 00090 public scfImplementation1<csCommonImageFileLoader, iImageFileLoader> 00091 { 00092 protected: 00094 int Format; 00099 csRef<iDataBuffer> rawData; 00101 csLoaderDataType dataType; 00102 /* rgbaData and indexData are sent to the image when it needs to be filled. */ 00104 csRGBpixel* rgbaData; 00106 uint8* indexData; 00108 csRGBpixel* palette; 00110 size_t paletteCount; 00112 uint8* alpha; 00114 bool hasKeycolor; 00116 csRGBcolor keycolor; 00118 int Width, Height; 00119 public: 00120 csCommonImageFileLoader (int format); 00121 virtual ~csCommonImageFileLoader(); 00122 00123 virtual csRef<iDataBuffer> GetRawData() 00124 { return rawData; } 00125 virtual csLoaderDataType GetDataType() 00126 { return dataType; } 00127 virtual int GetWidth() { return Width; } 00128 virtual int GetHeight() { return Height; } 00129 virtual int GetFormat() { return Format; } 00130 virtual void ApplyTo (csImageMemory* image); 00131 virtual bool HasKeyColor() const { return hasKeycolor; } 00132 virtual void GetKeyColor (int &r, int &g, int &b) const 00133 { 00134 r = keycolor.red; g = keycolor.green; b = keycolor.blue; 00135 } 00136 }; 00137 00138 #define THREADED_LOADING 00139 00143 class CS_CRYSTALSPACE_EXPORT csCommonImageFile : 00144 public scfImplementationExt0<csCommonImageFile, csImageMemory> 00145 { 00146 protected: 00147 friend class csCommonImageFileLoader; 00148 00149 class CS_CRYSTALSPACE_EXPORT LoaderJob : 00150 public scfImplementation1<LoaderJob, iJob> 00151 { 00152 public: 00154 csRef<iImageFileLoader> currentLoader; 00156 bool loadResult; 00158 LoaderJob (iImageFileLoader* loader); 00159 virtual ~LoaderJob(); 00160 00161 virtual void Run(); 00162 }; 00163 00164 #ifdef THREADED_LOADING 00166 // This and jobQueue are mutable so MakeImageData() can be called. 00167 mutable csRef<LoaderJob> loadJob; 00169 mutable csRef<iJobQueue> jobQueue; 00170 #else 00171 // This is mutable so MakeImageData() can be called. 00172 mutable csRef<iImageFileLoader> currentLoader; 00173 #endif 00174 iObjectRegistry* object_reg; 00175 00176 csCommonImageFile (iObjectRegistry* object_reg, int format); 00177 virtual ~csCommonImageFile(); 00178 00180 virtual bool Load (csRef<iDataBuffer> source); 00187 virtual csRef<iImageFileLoader> InitLoader (csRef<iDataBuffer> source) = 0; 00188 00190 void WaitForJob() const; 00192 // const so it can be called from GetRaw*(). 00193 void MakeImageData() const; 00194 00195 virtual const void *GetImageData (); 00196 virtual const csRGBpixel* GetPalette (); 00197 virtual const uint8* GetAlpha (); 00198 00199 virtual bool HasKeyColor () const 00200 { 00201 #ifdef THREADED_LOADING 00202 if (loadJob) 00203 { 00204 return loadJob->currentLoader->HasKeyColor(); 00205 } 00206 #endif 00207 return has_keycolour; 00208 } 00209 00210 virtual void GetKeyColor (int &r, int &g, int &b) const 00211 { 00212 #ifdef THREADED_LOADING 00213 if (loadJob) 00214 { 00215 // Keycolor may only be available after loading... 00216 WaitForJob(); 00217 loadJob->currentLoader->GetKeyColor (r, g, b); 00218 return; 00219 } 00220 #endif 00221 r = keycolour.red; g = keycolour.green; b = keycolour.blue; 00222 } 00223 00228 static const char* DataTypeString (csLoaderDataType dataType); 00229 virtual const char* GetRawFormat() const; 00230 virtual csRef<iDataBuffer> GetRawData() const; 00231 }; 00232 00235 #endif // __CS_CSPLUGINCOMMON_IMAGELOADER_COMMONIMAGEFILE_H__
Generated for Crystal Space 1.2.1 by doxygen 1.5.3