SIBCPixMap.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Softimage 3D Games & 3D Bridge team
00004 //
00005 // (c) Copyright 2001-2002 Avid Technology, Inc. . All rights reserved.
00006 //
00007 //***************************************************************************************
00008 
00009 /****************************************************************************************
00010 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00011 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00012 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00013 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00014 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00015 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00016 
00017 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00018 
00019 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00020 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00021 trademarks contained herein are the property of their respective owners. 
00022 ****************************************************************************************/
00023 
00024 //***************************************************************************************
00025 // Defines
00026 //***************************************************************************************
00027 #ifndef __CSIBCPixMap_H__
00028 #define __CSIBCPixMap_H__
00029 
00030 //***************************************************************************************
00031 // Includes
00032 //***************************************************************************************
00033 #include <SIBCUtil.h>
00034 #include <SIBCNode.h>
00035 #include <SIBCString.h>
00036 #include <SIBCSearchPath.h>
00037 
00038 
00039 class CSIBCPixMap;
00040 
00042 class XSICOREEXPORT CSIBCPixMapDriver
00043 {
00044     private:
00045         SI_Void         *m_pUnused;
00046 
00047     public:
00048 
00052         CSIBCPixMapDriver();
00053 
00056         virtual ~CSIBCPixMapDriver();
00057 
00064         virtual SI_Bool Supported( CSIBCString &in_Filename ) = 0;
00065 
00074         virtual SI_Error Load( CSIBCString &in_filename, CSIBCPixMap &in_PixMap ) = 0;      
00075 
00085         virtual SI_Error LoadFromMemory( void *in_pMemoryBlock, SI_Int in_lCount, CSIBCPixMap &in_PixMap ) { return SI_FILE_NOT_FOUND; }
00086 };
00087 
00088 
00089 // Pixel map class
00090 class XSICOREEXPORT CSIBCPixMap : public CSIBCNode
00091 {
00092 public:
00093 
00095     enum
00096     {
00097         RED,        
00098         GREEN,      
00099         BLUE,       
00100         ALPHA       
00101     };
00102 
00104     enum
00105     {
00106         //Types
00107         RGB,        
00108         RGBA,       
00109         PALETIZED   
00110     };
00111 
00113     enum
00114     {
00115         INVALID_TEXTURE_ID = 0xffffffff 
00116     };
00117 
00119     enum
00120     {
00121         RESIZE_LOWER,       
00122         RESIZE_HIGHER,      
00123         RESIZE_NEAREST      
00124     };
00125 
00129     CSIBCPixMap();                                                          
00130 
00133     virtual ~CSIBCPixMap();                                         
00134 
00135     //Info Retrieval
00139     SI_Int GetCLUTSize(){return (1<<m_ClutWidth);}; 
00140 
00144     SI_Int GetWidth();
00145 
00149     SI_Int GetHeight();
00150 
00157     SI_Int GetType();   
00158 
00159     // 
00163     SI_Int GetDepth();
00164 
00169     SI_Int GetDepth( SI_Int in_lComponent);                     
00170 
00176     SI_Error SetDepth( SI_Int *i_pDepth);
00177 
00181     SI_Int GetTotalPixelDepthByte();    
00182 
00186     SI_UByte *GetMap();
00187     
00196     SI_Error GetPixel( SI_Int x, SI_Int y, SI_UByte *pVal );
00208     SI_Error GetPixel( SI_Int x, SI_Int y, SI_Int &r, SI_Int &g, SI_Int &b, SI_Int &a );
00209 
00217     SI_Error SetPixel( SI_Int x, SI_Int y, SI_UByte *pVal );                
00218 
00229     SI_Error SetPixel( SI_Int x, SI_Int y, SI_Int r, SI_Int g, SI_Int b, SI_Int a );
00230 
00238     SI_Error SetPixel( SI_Int x, SI_Int y, SI_Int index );
00239 
00247     SI_Error GetPixelColourIndex( SI_Int x, SI_Int y, SI_UByte *pVal );
00248 
00255     SI_Error GetColour( SI_UByte i, SI_UByte *out_pRGBA ); 
00256 
00266     SI_Error GetColour( SI_UByte i, SI_Int *r, SI_Int *g, SI_Int *b, SI_Int *a );
00267 
00274     SI_Error SetColour( SI_UByte i, SI_UByte *in_pRGBA );
00275 
00285     SI_Error SetColour( SI_UByte i, SI_Int r, SI_Int g, SI_Int b, SI_Int a = 255 );
00286 
00287 
00291     SI_Int ComputeCRC();
00292 
00301     void PackPixel( SI_Int r, SI_Int g, SI_Int b, SI_Int a, SI_UByte *pVal ); // Turns RGBA into a packed pixel value
00302 
00311     void UnPackPixel( SI_Int &r, SI_Int &g, SI_Int &b, SI_Int &a, SI_UByte *pVal );
00312 
00318     SI_Int Index( SI_Int x, SI_Int y ); 
00319 
00320     // don't comment this, it should no longer be used
00321     SI_UInt &TextureID() { return m_TextureID; }    
00322 
00331     SI_Error CreateNew( SI_Int i_Width, SI_Int i_Height,
00332                         SI_Int i_Type, SI_Int *i_pDepth );
00333 
00334 
00340     SI_Error ResizeToPowerOfTwo( SI_Int method);    
00341 
00346     SI_Error DisposeData();
00347 
00353     SI_Error ConvertToRGB( CSIBCPixMap & ); 
00354 
00355 
00356     // Memory estimation over-riden from CSIBCNode
00360     virtual SI_UInt UsedMemory();
00361 
00365     virtual SI_UInt AllocatedMemory();
00366 
00370     virtual SI_UInt LocalSize();
00371 
00372     //Static members
00373 
00378     static CSIBCSearchPath *GetSearchPath();                                                        // Search path for textures
00379 
00386     static SI_Error AddDriver( CSIBCPixMapDriver * );                                               
00387 
00396     static SI_Error Load( CSIBCString &in_Filename, CSIBCPixMap &in_PixMap, SI_Bool in_ResizeToPowerOfTwo = TRUE  );
00397 
00406     static SI_Error Load( const SI_Char *in_Filename, CSIBCPixMap &in_PixMap, SI_Bool in_ResizeToPowerOfTwo = TRUE );
00407 
00417     static SI_Error Load( CSIBCString &, void *pMemoryBlock, SI_Int nSize, CSIBCPixMap &i_OutMap);
00418 
00428     static SI_Error Load( const SI_Char *, void *pMemoryBlock, SI_Int nSize, CSIBCPixMap &i_OutMap);
00429 
00435     static SI_Error Cleanup();
00436 
00437 protected:
00438     
00439 
00440 private:
00441     SI_Int m_Width;
00442     SI_Int m_Height;
00443     SI_Int m_Type;
00444     SI_Int m_Depth[4];                                                      // Total bit depth of each component
00445     SI_Int m_TotalDepth;                                                    // Total byte depth of a pixel
00446     SI_UInt m_TextureID;
00447     SI_Int m_ClutDepth;                                                     // Total byte depth of a CLUT entry;
00448     SI_Int m_ClutWidth;                                                     // bits in CLUT index (ie 2 colour = 1, 256 colour = 8);
00449 
00450     SI_UByte *m_pMap;                                                       // pixel map
00451     SI_UByte *m_pCLUT;                                                      // Colour Lookup Table
00452     CSIBCString m_Filename;                                                 // Filename
00453 
00454     //Static members
00455     static CSIBCSearchPath s_Path;                                          // the paths to search for an image
00456     static CSIBCArray< CSIBCPixMapDriver * > s_Drivers;                     // the drivers to try when asked to load an image
00457 
00458     SI_Void *m_pUnused;
00459 };
00460 
00461 
00462 
00463 #endif 
00464 // CSIBCPixMap