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 csRef<iImageFileLoader> currentLoader; 00172 #endif 00173 iObjectRegistry* object_reg; 00174 00175 csCommonImageFile (iObjectRegistry* object_reg, int format); 00176 virtual ~csCommonImageFile(); 00177 00179 virtual bool Load (csRef<iDataBuffer> source); 00186 virtual csRef<iImageFileLoader> InitLoader (csRef<iDataBuffer> source) = 0; 00187 00189 void WaitForJob() const; 00191 // const so it can be called from GetRaw*(). 00192 void MakeImageData() const; 00193 00194 virtual const void *GetImageData (); 00195 virtual const csRGBpixel* GetPalette (); 00196 virtual const uint8* GetAlpha (); 00197 00198 virtual bool HasKeyColor () const 00199 { 00200 #ifdef THREADED_LOADING 00201 if (loadJob) 00202 { 00203 return loadJob->currentLoader->HasKeyColor(); 00204 } 00205 #endif 00206 return has_keycolour; 00207 } 00208 00209 virtual void GetKeyColor (int &r, int &g, int &b) const 00210 { 00211 #ifdef THREADED_LOADING 00212 if (loadJob) 00213 { 00214 // Keycolor may only be available after loading... 00215 WaitForJob(); 00216 loadJob->currentLoader->GetKeyColor (r, g, b); 00217 return; 00218 } 00219 #endif 00220 r = keycolour.red; g = keycolour.green; b = keycolour.blue; 00221 } 00222 00227 static const char* DataTypeString (csLoaderDataType dataType); 00228 virtual const char* GetRawFormat() const; 00229 virtual csRef<iDataBuffer> GetRawData() const; 00230 }; 00231 00234 #endif // __CS_CSPLUGINCOMMON_IMAGELOADER_COMMONIMAGEFILE_H__
Generated for Crystal Space 1.2 by doxygen 1.4.7