00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef OSDL_PALETTE_H_
00028 #define OSDL_PALETTE_H_
00029 
00030         
00031 #include "OSDLPixel.h"       
00032 
00033 #include "Ceylan.h"          
00034 
00035 
00036 
00037 
00038 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL 
00039 
00040 
00041 struct SDL_Palette ;
00042 
00043 #endif //  ! defined(OSDL_USES_SDL) || OSDL_USES_SDL 
00044 
00045 
00046 
00047 
00048 #include <string>
00049 
00050 
00051 
00052 
00053 namespace OSDL
00054 {
00055 
00056 
00057     
00058     namespace Video
00059     {
00060     
00061 
00062 
00070         typedef Ceylan::Uint16 ColorCount ;
00071         
00072 
00073 
00078         typedef Ceylan::Uint8 ColorIndex ;
00079         
00080         
00081         
00083         typedef Ceylan::SignedLongInteger ColorDistance ;
00084         
00085         
00086         
00094         typedef Ceylan::Uint16 PaletteIdentifier ;
00095         
00096         
00097         
00098         
00099 #if ! defined(OSDL_USES_SDL) || OSDL_USES_SDL 
00100 
00102         typedef ::SDL_Palette LowLevelPalette ;
00103         
00104 #else // OSDL_USES_SDL  
00105 
00107         struct LowLevelPalette
00108         {
00109         
00110             
00111             ColorCount ncolors ;
00112             
00113             
00114             Pixels::ColorDefinition *colors ;
00115             
00116         } ;
00117 
00118 #endif // OSDL_USES_SDL
00119         
00120         
00121         
00122         
00123         
00125         class OSDL_DLL PaletteException: public VideoException
00126         {
00127         
00128             public:
00129                 explicit PaletteException( const std::string & message ) ;
00130                 
00131                 virtual ~PaletteException() throw() ;
00132                             
00133         } ;
00134         
00135     
00136     
00137     
00164         class OSDL_DLL Palette: public Ceylan::TextDisplayable
00165         {
00166         
00167             public:
00168             
00169             
00170             
00172                 static const Ceylan::Flags Logical ;
00173                 
00174                                 
00176                 static const Ceylan::Flags Physical ;
00177             
00178             
00179             
00201                 explicit Palette( ColorCount numberOfColors, 
00202                     Pixels::ColorDefinition * colors = 0,
00203                     Pixels::PixelFormat * format = 0 ) ;
00204 
00205                 
00206                 
00227                 explicit Palette( const std::string & paletteFilename ) ;
00228                     
00229                     
00230                     
00240                 explicit Palette( const LowLevelPalette & palette ) ;
00241                 
00242                 
00243                 
00245                 virtual ~Palette() throw() ;
00246             
00247             
00248             
00264                 virtual void load( ColorCount numberOfColors, 
00265                     Pixels::ColorDefinition * colors ) ;
00266             
00267             
00268             
00274                 virtual ColorCount getNumberOfColors() const ;
00275                 
00276                 
00277                 
00288                 virtual const Pixels::PixelColor & getPixelColorAt( 
00289                     ColorCount index ) const ;
00290                     
00291                     
00292                     
00300                 virtual Pixels::PixelColor * getPixelColors() const ;
00301                 
00302                 
00303                 
00315                 virtual const Pixels::ColorDefinition & getColorDefinitionAt(
00316                     ColorCount index ) const ;
00317                 
00318                     
00319                     
00333                 virtual void setColorDefinitionAt(
00334                     ColorCount targetIndex, 
00335                     const Pixels::ColorDefinition & newColorDefinition ) ;
00336                     
00337                     
00338                     
00350                 virtual void setColorDefinitionAt(
00351                     ColorCount targetIndex, 
00352                     Pixels::ColorElement red,
00353                     Pixels::ColorElement green,
00354                     Pixels::ColorElement blue,
00355                     Pixels::ColorElement alpha = Pixels::AlphaOpaque ) ;
00356                     
00357                     
00358                     
00366                 virtual Pixels::ColorDefinition * getColorDefinitions() const ;
00367 
00368 
00369                 
00374                 virtual bool hasColorKey() const ;
00375                 
00376                 
00377                 
00386                 virtual ColorCount getColorKeyIndex() const ;
00387                 
00388                 
00389                 
00394                 virtual void setColorKeyIndex( ColorCount colorkeyIndex ) ;
00395                 
00396                     
00397                     
00403                 virtual void updatePixelColorsFrom( 
00404                     const Pixels::PixelFormat & format ) ;
00405 
00406 
00407 
00429                 virtual void quantize( 
00430                     Pixels::ColorElement quantizeMaxCoordinate,
00431                     bool scaleUp = false ) ;
00432 
00433 
00434 
00450                 virtual void correctGamma( Pixels::GammaFactor gamma ) ;
00451 
00452 
00453 
00467                 virtual ColorCount getClosestColorIndexTo(
00468                     const Pixels::ColorDefinition & color ) const ;
00469                     
00470                     
00471 
00489                 virtual bool draw( Surface & targetSurface, 
00490                     const Pixels::ColorDefinition & backgroundColor 
00491                         = Pixels::White ) ;
00492                 
00493                 
00494                 
00508                 virtual bool hasDuplicates( bool useAlpha = false ) const ;
00509                 
00510                 
00511                 
00556                 virtual void save( const std::string & filename,
00557                     bool encoded = false ) const ;
00558                     
00559                     
00560                     
00572                 virtual const std::string toString( 
00573                     Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00574 
00575 
00576 
00577 
00578                 
00579                 
00580                     
00581                         
00582                         
00589                 static Palette & CreateGreyScalePalette( 
00590                     ColorCount numberOfColors = 256 ) ; 
00591             
00592             
00593             
00602                 static Palette & CreateGradationPalette( 
00603                     const Pixels::ColorDefinition & colorStart,
00604                     const Pixels::ColorDefinition & colorEnd, 
00605                     ColorCount numberOfColors = 256 ) ; 
00606             
00607             
00608             
00626                 static Palette & CreateMasterPalette( 
00627                     bool addColorkey = true ) ; 
00628             
00629             
00630             
00631             
00632             protected:
00633                 
00634                 
00635                 
00640                 virtual void invalidatePixelColors() ;
00641                 
00642                 
00643                      
00644                 
00645                 
00646                 
00647                 
00648                 
00663                 static Pixels::ColorElement QuantizeComponent( 
00664                     Pixels::ColorElement component, 
00665                     Pixels::ColorElement newMaxCoordinate = 31 ) ;
00666                     
00667                     
00668                     
00677                 static Pixels::ColorElement CorrectGammaComponent( 
00678                     Pixels::ColorElement component, 
00679                     Pixels::GammaFactor gamma ) ;
00680                     
00681                 
00682                 
00695                 static ColorDistance GetDistance( 
00696                     const Pixels::ColorDefinition & firstColor,
00697                     const Pixels::ColorDefinition & secondColor ) ;
00698                                 
00699                                         
00700             
00702                 ColorCount _numberOfColors ;
00703                 
00704                 
00705                 
00711                 Pixels::ColorDefinition * _colorDefs ;
00712             
00713             
00714             
00720                 Pixels::PixelColor * _pixelColors ;
00721 
00722 
00723 
00729                 bool _converted ;
00730                 
00731                 
00732 
00738                 bool _ownsColorDefinition ;
00739                 
00740                     
00741                     
00742                             
00743             private:
00744             
00745             
00746                     
00748                 bool _hasColorkey ;
00749                 
00750                 
00751                 
00753                 ColorCount _colorKeyIndex ;
00754 
00755         
00756         
00765                 explicit Palette( const Palette & source ) ;
00766             
00767             
00768             
00777                 Palette & operator = ( const Palette & source ) ;
00778         
00779         
00780         } ;
00781         
00782     
00783     }
00784 
00785 }
00786 
00787 
00788 
00789 #endif // OSDL_PALETTE_H_
00790