Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
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 "iutil/databuff.h" 00029 #include "iutil/job.h" 00030 #include "csutil/ref.h" 00031 #include "csgfx/memimage.h" 00032 00041 enum csLoaderDataType 00042 { 00044 rdtInvalid, 00046 rdtR8G8B8, 00048 rdtRGBpixel, 00050 rdtIndexed 00051 }; 00052 00053 class csCommonImageFile; 00054 00055 SCF_VERSION (iImageFileLoader, 0, 0, 2); 00056 00061 struct iImageFileLoader : public iBase 00062 { 00064 virtual bool LoadData () = 0; 00066 virtual csRef<iDataBuffer> GetRawData() = 0; 00068 virtual csLoaderDataType GetDataType() = 0; 00070 virtual int GetWidth() = 0; 00072 virtual int GetHeight() = 0; 00074 virtual int GetFormat() = 0; 00076 virtual void ApplyTo (csImageMemory* image) = 0; 00078 virtual bool HasKeyColor() const = 0; 00080 virtual void GetKeyColor (int &r, int &g, int &b) const = 0; 00081 }; 00082 00086 class CS_CRYSTALSPACE_EXPORT csCommonImageFileLoader : public iImageFileLoader 00087 { 00088 protected: 00090 int Format; 00092 csRef<iDataBuffer> rawData; 00094 csLoaderDataType dataType; 00096 csRGBpixel* rgbaData; 00098 uint8* indexData; 00100 csRGBpixel* palette; 00102 size_t paletteCount; 00104 uint8* alpha; 00106 bool hasKeycolor; 00108 csRGBcolor keycolor; 00110 int Width, Height; 00111 public: 00112 SCF_DECLARE_IBASE; 00113 00114 csCommonImageFileLoader (int format); 00115 virtual ~csCommonImageFileLoader(); 00116 00117 virtual csRef<iDataBuffer> GetRawData() 00118 { return rawData; } 00119 virtual csLoaderDataType GetDataType() 00120 { return dataType; } 00121 virtual int GetWidth() { return Width; } 00122 virtual int GetHeight() { return Height; } 00123 virtual int GetFormat() { return Format; } 00124 virtual void ApplyTo (csImageMemory* image); 00125 virtual bool HasKeyColor() const { return hasKeycolor; } 00126 virtual void GetKeyColor (int &r, int &g, int &b) const 00127 { 00128 r = keycolor.red; g = keycolor.green; b = keycolor.blue; 00129 } 00130 }; 00131 00132 #define THREADED_LOADING 00133 00137 class CS_CRYSTALSPACE_EXPORT csCommonImageFile : public csImageMemory 00138 { 00139 protected: 00140 friend class csCommonImageFileLoader; 00141 00142 class CS_CRYSTALSPACE_EXPORT LoaderJob : public iJob 00143 { 00144 public: 00146 csRef<iImageFileLoader> currentLoader; 00148 bool loadResult; 00149 SCF_DECLARE_IBASE; 00150 00152 LoaderJob (iImageFileLoader* loader); 00153 virtual ~LoaderJob(); 00154 00155 virtual void Run(); 00156 }; 00157 00158 #ifdef THREADED_LOADING 00159 00160 csRef<LoaderJob> loadJob; 00162 csRef<iJobQueue> jobQueue; 00163 #else 00164 csRef<iImageFileLoader> currentLoader; 00165 #endif 00166 iObjectRegistry* object_reg; 00167 00168 csCommonImageFile (iObjectRegistry* object_reg, int format); 00169 virtual ~csCommonImageFile(); 00170 00172 virtual bool Load (csRef<iDataBuffer> source); 00179 virtual csRef<iImageFileLoader> InitLoader (csRef<iDataBuffer> source) = 0; 00180 00182 void WaitForJob() const; 00184 void MakeImageData(); 00185 00186 virtual const void *GetImageData (); 00187 virtual const csRGBpixel* GetPalette (); 00188 virtual const uint8* GetAlpha (); 00189 00190 virtual bool HasKeyColor () const 00191 { 00192 #ifdef THREADED_LOADING 00193 if (loadJob) 00194 { 00195 return loadJob->currentLoader->HasKeyColor(); 00196 } 00197 #endif 00198 return has_keycolour; 00199 } 00200 00201 virtual void GetKeyColor (int &r, int &g, int &b) const 00202 { 00203 #ifdef THREADED_LOADING 00204 if (loadJob) 00205 { 00206 // Keycolor may only be available after loading... 00207 WaitForJob(); 00208 loadJob->currentLoader->GetKeyColor (r, g, b); 00209 return; 00210 } 00211 #endif 00212 r = keycolour.red; g = keycolour.green; b = keycolour.blue; 00213 } 00214 00219 static const char* DataTypeString (csLoaderDataType dataType); 00220 virtual const char* GetRawFormat() const; 00221 virtual csRef<iDataBuffer> GetRawData() const; 00222 }; 00223 00226 #endif // __CS_CSPLUGINCOMMON_IMAGELOADER_COMMONIMAGEFILE_H__
Generated for Crystal Space by doxygen 1.4.4