SIBCPixMap.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 //***************************************************************************************
00013 // Defines
00014 //***************************************************************************************
00015 #ifndef __CSIBCPixMap_H__
00016 #define __CSIBCPixMap_H__
00017 
00018 //***************************************************************************************
00019 // Includes
00020 //***************************************************************************************
00021 #include <SIBCUtil.h>
00022 #include <SIBCNode.h>
00023 #include <SIBCString.h>
00024 #include <SIBCSearchPath.h>
00025 
00026 
00027 class CSIBCPixMap;
00028 
00030 class XSICOREEXPORT CSIBCPixMapDriver
00031 {
00032     private:
00033         SI_Void         *m_pUnused;
00034 
00035     public:
00036 
00040         CSIBCPixMapDriver();
00041 
00044         virtual ~CSIBCPixMapDriver();
00045 
00052         virtual SI_Bool Supported( CSIBCString &in_Filename ) = 0;
00053 
00062         virtual SI_Error Load( CSIBCString &in_filename, CSIBCPixMap &in_PixMap ) = 0;      
00063 
00073         virtual SI_Error LoadFromMemory( void *in_pMemoryBlock, SI_Int in_lCount, CSIBCPixMap &in_PixMap ) { return SI_FILE_NOT_FOUND; }
00074 };
00075 
00076 
00077 // Pixel map class
00078 class XSICOREEXPORT CSIBCPixMap : public CSIBCNode
00079 {
00080 public:
00081 
00083     enum
00084     {
00085         RED,        
00086         GREEN,      
00087         BLUE,       
00088         ALPHA       
00089     };
00090 
00092     enum
00093     {
00094         //Types
00095         RGB,        
00096         RGBA,       
00097         PALETIZED   
00098     };
00099 
00101     enum
00102     {
00103         INVALID_TEXTURE_ID = 0xffffffff 
00104     };
00105 
00107     enum
00108     {
00109         RESIZE_LOWER,       
00110         RESIZE_HIGHER,      
00111         RESIZE_NEAREST      
00112     };
00113 
00117     CSIBCPixMap();                                                          
00118 
00121     virtual ~CSIBCPixMap();                                         
00122 
00123     //Info Retrieval
00127     SI_Int GetCLUTSize(){return (1<<m_ClutWidth);}; 
00128 
00132     SI_Int GetWidth();
00133 
00137     SI_Int GetHeight();
00138 
00145     SI_Int GetType();   
00146 
00147     // 
00151     SI_Int GetDepth();
00152 
00157     SI_Int GetDepth( SI_Int in_lComponent);                     
00158 
00164     SI_Error SetDepth( SI_Int *i_pDepth);
00165 
00169     SI_Int GetTotalPixelDepthByte();    
00170 
00174     SI_UByte *GetMap();
00175     
00184     SI_Error GetPixel( SI_Int x, SI_Int y, SI_UByte *pVal );
00196     SI_Error GetPixel( SI_Int x, SI_Int y, SI_Int &r, SI_Int &g, SI_Int &b, SI_Int &a );
00197 
00205     SI_Error SetPixel( SI_Int x, SI_Int y, SI_UByte *pVal );                
00206 
00217     SI_Error SetPixel( SI_Int x, SI_Int y, SI_Int r, SI_Int g, SI_Int b, SI_Int a );
00218 
00226     SI_Error SetPixel( SI_Int x, SI_Int y, SI_Int index );
00227 
00235     SI_Error GetPixelColourIndex( SI_Int x, SI_Int y, SI_UByte *pVal );
00236 
00243     SI_Error GetColour( SI_UByte i, SI_UByte *out_pRGBA ); 
00244 
00254     SI_Error GetColour( SI_UByte i, SI_Int *r, SI_Int *g, SI_Int *b, SI_Int *a );
00255 
00262     SI_Error SetColour( SI_UByte i, SI_UByte *in_pRGBA );
00263 
00273     SI_Error SetColour( SI_UByte i, SI_Int r, SI_Int g, SI_Int b, SI_Int a = 255 );
00274 
00275 
00279     SI_Int ComputeCRC();
00280 
00289     void PackPixel( SI_Int r, SI_Int g, SI_Int b, SI_Int a, SI_UByte *pVal ); // Turns RGBA into a packed pixel value
00290 
00299     void UnPackPixel( SI_Int &r, SI_Int &g, SI_Int &b, SI_Int &a, SI_UByte *pVal );
00300 
00306     SI_Int Index( SI_Int x, SI_Int y ); 
00307 
00308     // don't comment this, it should no longer be used
00309     SI_UInt &TextureID() { return m_TextureID; }    
00310 
00319     SI_Error CreateNew( SI_Int i_Width, SI_Int i_Height,
00320                         SI_Int i_Type, SI_Int *i_pDepth );
00321 
00322 
00328     SI_Error ResizeToPowerOfTwo( SI_Int method);    
00329 
00334     SI_Error DisposeData();
00335 
00341     SI_Error ConvertToRGB( CSIBCPixMap & ); 
00342 
00343 
00344     // Memory estimation over-riden from CSIBCNode
00348     virtual SI_UInt UsedMemory();
00349 
00353     virtual SI_UInt AllocatedMemory();
00354 
00358     virtual SI_UInt LocalSize();
00359 
00360     //Static members
00361 
00366     static CSIBCSearchPath *GetSearchPath();                                                        // Search path for textures
00367 
00374     static SI_Error AddDriver( CSIBCPixMapDriver * );                                               
00375 
00384     static SI_Error Load( CSIBCString &in_Filename, CSIBCPixMap &in_PixMap, SI_Bool in_ResizeToPowerOfTwo = TRUE  );
00385 
00394     static SI_Error Load( const SI_Char *in_Filename, CSIBCPixMap &in_PixMap, SI_Bool in_ResizeToPowerOfTwo = TRUE );
00395 
00405     static SI_Error Load( CSIBCString &, void *pMemoryBlock, SI_Int nSize, CSIBCPixMap &i_OutMap);
00406 
00416     static SI_Error Load( const SI_Char *, void *pMemoryBlock, SI_Int nSize, CSIBCPixMap &i_OutMap);
00417 
00423     static SI_Error Cleanup();
00424 
00425 protected:
00426     
00427 
00428 private:
00429     SI_Int m_Width;
00430     SI_Int m_Height;
00431     SI_Int m_Type;
00432     SI_Int m_Depth[4];                                                      // Total bit depth of each component
00433     SI_Int m_TotalDepth;                                                    // Total byte depth of a pixel
00434     SI_UInt m_TextureID;
00435     SI_Int m_ClutDepth;                                                     // Total byte depth of a CLUT entry;
00436     SI_Int m_ClutWidth;                                                     // bits in CLUT index (ie 2 colour = 1, 256 colour = 8);
00437 
00438     SI_UByte *m_pMap;                                                       // pixel map
00439     SI_UByte *m_pCLUT;                                                      // Colour Lookup Table
00440     CSIBCString m_Filename;                                                 // Filename
00441 
00442     //Static members
00443     static CSIBCSearchPath s_Path;                                          // the paths to search for an image
00444     static CSIBCArray< CSIBCPixMapDriver * > s_Drivers;                     // the drivers to try when asked to load an image
00445 
00446     SI_Void *m_pUnused;
00447 };
00448 
00449 
00450 
00451 #endif 
00452 // CSIBCPixMap