CrystalSpace

Public API Reference

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;
00096   csRef<iDataBuffer> rawData;
00098   csLoaderDataType dataType;
00100   csRGBpixel* rgbaData;
00102   uint8* indexData;
00104   csRGBpixel* palette;
00106   size_t paletteCount;
00108   uint8* alpha;
00110   bool hasKeycolor;
00112   csRGBcolor keycolor;
00114   int Width, Height;
00115 public:
00116   csCommonImageFileLoader (int format);
00117   virtual ~csCommonImageFileLoader();
00118 
00119   virtual csRef<iDataBuffer> GetRawData() 
00120   { return rawData; }
00121   virtual csLoaderDataType GetDataType() 
00122   { return dataType; }
00123   virtual int GetWidth() { return Width; }
00124   virtual int GetHeight() { return Height; }
00125   virtual int GetFormat() { return Format; }
00126   virtual void ApplyTo (csImageMemory* image);
00127   virtual bool HasKeyColor() const { return hasKeycolor; }
00128   virtual void GetKeyColor (int &r, int &g, int &b) const
00129   { 
00130     r = keycolor.red; g = keycolor.green; b = keycolor.blue; 
00131   }
00132 };
00133 
00134 #define THREADED_LOADING
00135 
00139 class CS_CRYSTALSPACE_EXPORT csCommonImageFile : 
00140   public scfImplementationExt0<csCommonImageFile, csImageMemory>
00141 {
00142 protected:
00143   friend class csCommonImageFileLoader;
00144   
00145   class CS_CRYSTALSPACE_EXPORT LoaderJob : 
00146     public scfImplementation1<LoaderJob, iJob>
00147   {
00148   public:
00150     csRef<iImageFileLoader> currentLoader;
00152     bool loadResult;
00154     LoaderJob (iImageFileLoader* loader);
00155     virtual ~LoaderJob();
00156 
00157     virtual void Run();
00158   };
00159 
00160 #ifdef THREADED_LOADING
00162   csRef<LoaderJob> loadJob;
00164   csRef<iJobQueue> jobQueue;
00165 #else
00166   csRef<iImageFileLoader> currentLoader;
00167 #endif
00168   iObjectRegistry* object_reg;
00169 
00170   csCommonImageFile (iObjectRegistry* object_reg, int format);
00171   virtual ~csCommonImageFile();
00172 
00174   virtual bool Load (csRef<iDataBuffer> source);
00181   virtual csRef<iImageFileLoader> InitLoader (csRef<iDataBuffer> source) = 0;
00182 
00184   void WaitForJob() const;
00186   void MakeImageData();
00187 
00188   virtual const void *GetImageData ();
00189   virtual const csRGBpixel* GetPalette ();
00190   virtual const uint8* GetAlpha ();
00191 
00192   virtual bool HasKeyColor () const 
00193   { 
00194 #ifdef THREADED_LOADING
00195     if (loadJob)
00196     {
00197       return loadJob->currentLoader->HasKeyColor();
00198     }
00199 #endif
00200     return has_keycolour; 
00201   }
00202 
00203   virtual void GetKeyColor (int &r, int &g, int &b) const
00204   { 
00205 #ifdef THREADED_LOADING
00206     if (loadJob)
00207     {
00208       // Keycolor may only be available after loading...
00209       WaitForJob();
00210       loadJob->currentLoader->GetKeyColor (r, g, b);
00211       return;
00212     }
00213 #endif
00214     r = keycolour.red; g = keycolour.green; b = keycolour.blue; 
00215   }
00216 
00221   static const char* DataTypeString (csLoaderDataType dataType);
00222   virtual const char* GetRawFormat() const;
00223   virtual csRef<iDataBuffer> GetRawData() const;
00224 };
00225 
00228 #endif // __CS_CSPLUGINCOMMON_IMAGELOADER_COMMONIMAGEFILE_H__

Generated for Crystal Space by doxygen 1.4.7