SIBCPixMap.h

Go to the documentation of this file.
00001 //***************************************************************************************
00002 // File supervisor: Crosswalk team
00012 //***************************************************************************************
00013 
00014 //***************************************************************************************
00015 // Defines
00016 //***************************************************************************************
00017 #ifndef __CSIBCPixMap_H__
00018 #define __CSIBCPixMap_H__
00019 
00020 //***************************************************************************************
00021 // Includes
00022 //***************************************************************************************
00023 #include <SIBCUtil.h>
00024 #include <SIBCNode.h>
00025 #include <SIBCString.h>
00026 #include <SIBCSearchPath.h>
00027 
00028 
00029 class CSIBCPixMap;
00030 
00033 class XSICOREEXPORT CSIBCPixMapDriver
00034 {
00035     private:
00036         SI_Void         *m_pUnused;
00037 
00038     public:
00039 
00042         CSIBCPixMapDriver();
00043 
00046         virtual ~CSIBCPixMapDriver();
00047 
00053         virtual SI_Bool Supported( CSIBCString &in_Filename ) = 0;
00054 
00062         virtual SI_Error Load( CSIBCString &in_filename, CSIBCPixMap &in_PixMap ) = 0;
00063 
00072         virtual SI_Error LoadFromMemory( void *in_pMemoryBlock, SI_Int in_lCount, CSIBCPixMap &in_PixMap ) { return SI_FILE_NOT_FOUND; }
00073 };
00074 
00075 
00076 // Pixel map class
00077 class XSICOREEXPORT CSIBCPixMap : public CSIBCNode
00078 {
00079 public:
00080 
00083     enum
00084     {
00085         RED,        
00086         GREEN,      
00087         BLUE,       
00088         ALPHA       
00089     };
00090 
00093     enum
00094     {
00095         //Types
00096         RGB,        
00097         RGBA,       
00098         PALETIZED   
00099     };
00100 
00103     enum
00104     {
00105         INVALID_TEXTURE_ID = 0xffffffff 
00106     };
00107 
00110     enum
00111     {
00112         RESIZE_LOWER,       
00113         RESIZE_HIGHER,      
00114         RESIZE_NEAREST      
00115     };
00116 
00119     CSIBCPixMap();
00120 
00123     virtual ~CSIBCPixMap();
00124 
00125     //Info Retrieval
00129     SI_Int GetCLUTSize(){return (1<<m_ClutWidth);};
00130 
00134     SI_Int GetWidth();
00135 
00139     SI_Int GetHeight();
00140 
00146     SI_Int GetType();
00147 
00148     //
00152     SI_Int GetDepth();
00153 
00158     SI_Int GetDepth( SI_Int in_lComponent);
00159 
00164     SI_Error SetDepth( SI_Int *i_pDepth);
00165 
00169     SI_Int GetTotalPixelDepthByte();
00170 
00174     SI_UByte *GetMap();
00175 
00183     SI_Error GetPixel( SI_Int x, SI_Int y, SI_UByte *pVal );
00194     SI_Error GetPixel( SI_Int x, SI_Int y, SI_Int &r, SI_Int &g, SI_Int &b, SI_Int &a );
00195 
00202     SI_Error SetPixel( SI_Int x, SI_Int y, SI_UByte *pVal );
00203 
00213     SI_Error SetPixel( SI_Int x, SI_Int y, SI_Int r, SI_Int g, SI_Int b, SI_Int a );
00214 
00221     SI_Error SetPixel( SI_Int x, SI_Int y, SI_Int index );
00222 
00229     SI_Error GetPixelColourIndex( SI_Int x, SI_Int y, SI_UByte *pVal );
00230 
00236     SI_Error GetColour( SI_UByte i, SI_UByte *out_pRGBA );
00237 
00246     SI_Error GetColour( SI_UByte i, SI_Int *r, SI_Int *g, SI_Int *b, SI_Int *a );
00247 
00253     SI_Error SetColour( SI_UByte i, SI_UByte *in_pRGBA );
00254 
00263     SI_Error SetColour( SI_UByte i, SI_Int r, SI_Int g, SI_Int b, SI_Int a = 255 );
00264 
00265 
00269     SI_Int ComputeCRC();
00270 
00278     void PackPixel( SI_Int r, SI_Int g, SI_Int b, SI_Int a, SI_UByte *pVal ); // Turns RGBA into a packed pixel value
00279 
00287     void UnPackPixel( SI_Int &r, SI_Int &g, SI_Int &b, SI_Int &a, SI_UByte *pVal );
00288 
00294     SI_Int Index( SI_Int x, SI_Int y );
00295 
00296     // Deprecated -- do not use
00297     SI_UInt &TextureID() { return m_TextureID; }
00298 
00306     SI_Error CreateNew( SI_Int i_Width, SI_Int i_Height,
00307                         SI_Int i_Type, SI_Int *i_pDepth );
00308 
00309 
00314     SI_Error ResizeToPowerOfTwo( SI_Int method);
00315 
00319     SI_Error DisposeData();
00320 
00325     SI_Error ConvertToRGB( CSIBCPixMap & );
00326 
00327 
00328     // Memory estimation overridden from CSIBCNode
00332     virtual SI_UInt UsedMemory();
00333 
00337     virtual SI_UInt AllocatedMemory();
00338 
00342     virtual SI_UInt LocalSize();
00343 
00344     //Static members
00345 
00350     static CSIBCSearchPath *GetSearchPath();                                                        // Search path for textures
00351 
00357     static SI_Error AddDriver( CSIBCPixMapDriver * );
00358 
00366     static SI_Error Load( CSIBCString &in_Filename, CSIBCPixMap &in_PixMap, SI_Bool in_ResizeToPowerOfTwo = TRUE  );
00367 
00375     static SI_Error Load( const SI_Char *in_Filename, CSIBCPixMap &in_PixMap, SI_Bool in_ResizeToPowerOfTwo = TRUE );
00376 
00385     static SI_Error Load( CSIBCString &, void *pMemoryBlock, SI_Int nSize, CSIBCPixMap &i_OutMap);
00386 
00395     static SI_Error Load( const SI_Char *, void *pMemoryBlock, SI_Int nSize, CSIBCPixMap &i_OutMap);
00396 
00401     static SI_Error Cleanup();
00402 
00403 protected:
00404 
00405 
00406 private:
00407     SI_Int m_Width;
00408     SI_Int m_Height;
00409     SI_Int m_Type;
00410     SI_Int m_Depth[4];                                                      // Total bit depth of each component
00411     SI_Int m_TotalDepth;                                                    // Total byte depth of a pixel
00412     SI_UInt m_TextureID;
00413     SI_Int m_ClutDepth;                                                     // Total byte depth of a CLUT entry;
00414     SI_Int m_ClutWidth;                                                     // bits in CLUT index (ie 2 colour = 1, 256 colour = 8);
00415 
00416     SI_UByte *m_pMap;                                                       // pixel map
00417     SI_UByte *m_pCLUT;                                                      // Colour Lookup Table
00418     CSIBCString m_Filename;                                                 // Filename
00419 
00420     //Static members
00421     static CSIBCSearchPath s_Path;                                          // the paths to search for an image
00422     static CSIBCArray< CSIBCPixMapDriver * > s_Drivers;                     // the drivers to try when asked to load an image
00423 
00424     SI_Void *m_pUnused;
00425 };
00426 
00427 
00428 
00429 #endif
00430 // CSIBCPixMap