]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/palette.cpp
60a0de6a8a57792b32270aa48ef3b1c3f21f9748
   1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "palette.h" 
  20 #include "wx/palette.h" 
  22 #if !USE_SHARED_LIBRARIES 
  23 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
) 
  31 wxPaletteRefData::wxPaletteRefData() 
  37 wxPaletteRefData::~wxPaletteRefData() 
  39     if (m_palette 
!= NULL
) { 
  45 wxPalette::wxPalette() 
  49 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
) 
  51     Create(n
, red
, green
, blue
); 
  54 wxPalette::~wxPalette() 
  58 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
) 
  62     m_refData 
= new wxPaletteRefData
; 
  64     M_PALETTEDATA
->m_count 
= n 
; 
  65     M_PALETTEDATA
->m_palette 
= new wxColour
[n
] ; 
  67     for ( int i 
= 0 ; i 
< n 
; ++i
) 
  69         M_PALETTEDATA
->m_palette
[i
].Set( red
[i
] , green
[i
] , blue
[i
] ) ; 
  75 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const 
  80     long bestdiff 
= 3 * 256 ; 
  84     for ( int i 
= 0  ; i 
< M_PALETTEDATA
->m_count 
; ++i 
) 
  86         const wxColour
& col 
= &M_PALETTEDATA
->m_palette
[i
] ; 
  87         currentdiff 
= abs ( col
.Red() - red 
) + abs( col
.Green() - green 
) + abs ( col
.Blue() - blue 
)  ; 
  88         if ( currentdiff 
< bestdiff 
) 
  90             bestdiff 
= currentdiff 
; 
 100 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const 
 105     if (index 
< 0 || index 
>= M_PALETTEDATA
->m_count
) 
 108     const wxColour
& col 
= &M_PALETTEDATA
->m_palette
[index
] ; 
 110     *green 
= col
.Green() ;