]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/palette.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "palette.h" 
  16 #include "wx/palette.h" 
  18 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
) 
  25 wxPaletteRefData::wxPaletteRefData() 
  31 wxPaletteRefData::~wxPaletteRefData() 
  36 wxPalette::wxPalette() 
  40 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
) 
  42     Create(n
, red
, green
, blue
); 
  45 wxPalette::~wxPalette() 
  49 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
) 
  53   m_refData 
= new wxPaletteRefData
; 
  55   M_PALETTEDATA
->m_count 
= n 
; 
  56   M_PALETTEDATA
->m_palette 
= new wxColour
[n
] ; 
  58   for ( int i 
= 0 ; i 
< n 
; ++i
) 
  60         M_PALETTEDATA
->m_palette
[i
].Set( red
[i
] , green
[i
] , blue
[i
] ) ; 
  66 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const 
  71     long bestdiff 
= 3 * 256 ; 
  75     for ( int i 
= 0  ; i 
< M_PALETTEDATA
->m_count 
; ++i 
) 
  77         const wxColour
& col 
= &M_PALETTEDATA
->m_palette
[i
] ; 
  78         currentdiff 
= abs ( col
.Red() - red 
) + abs( col
.Green() - green 
) + abs ( col
.Blue() - blue 
)  ; 
  79         if ( currentdiff 
< bestdiff 
) 
  81                 bestdiff 
= currentdiff 
; 
  91 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const 
  96     if (index 
< 0 || index 
>= M_PALETTEDATA
->m_count
) 
  99     const wxColour
& col 
= &M_PALETTEDATA
->m_palette
[index
] ; 
 101     *green 
= col
.Green() ;