]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/palette.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/palette.cpp 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  16 #include "wx/palette.h" 
  18 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
) 
  25 wxPaletteRefData::wxPaletteRefData() 
  31 wxPaletteRefData::~wxPaletteRefData() 
  33     if (m_palette 
!= NULL
) { 
  39 wxPalette::wxPalette() 
  43 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
) 
  45     Create(n
, red
, green
, blue
); 
  48 wxPalette::~wxPalette() 
  52 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
) 
  56     m_refData 
= new wxPaletteRefData
; 
  58     M_PALETTEDATA
->m_count 
= n 
; 
  59     M_PALETTEDATA
->m_palette 
= new wxColour
[n
] ; 
  61     for ( int i 
= 0 ; i 
< n 
; ++i
) 
  63         M_PALETTEDATA
->m_palette
[i
].Set( red
[i
] , green
[i
] , blue
[i
] ) ; 
  69 int wxPalette::GetPixel(unsigned char red
, unsigned char green
, unsigned char blue
) const 
  74     long bestdiff 
= 3 * 256 ; 
  78     for ( int i 
= 0  ; i 
< M_PALETTEDATA
->m_count 
; ++i 
) 
  80         const wxColour
& col 
= M_PALETTEDATA
->m_palette
[i
] ; 
  81         currentdiff 
= abs ( col
.Red() - red 
) + abs( col
.Green() - green 
) + abs ( col
.Blue() - blue 
)  ; 
  82         if ( currentdiff 
< bestdiff 
) 
  84             bestdiff 
= currentdiff 
; 
  94 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const 
  99     if (index 
< 0 || index 
>= M_PALETTEDATA
->m_count
) 
 102     const wxColour
& col 
= M_PALETTEDATA
->m_palette
[index
] ; 
 104     *green 
= col
.Green() ; 
 110 int wxPalette::GetColoursCount() const 
 113         return M_PALETTEDATA
->m_count
;