]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
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()
42 wxPalette::wxPalette()
46 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
48 Create(n
, red
, green
, blue
);
51 wxPalette::~wxPalette()
55 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
59 m_refData
= new wxPaletteRefData
;
61 M_PALETTEDATA
->m_count
= n
;
62 M_PALETTEDATA
->m_palette
= new wxColour
[n
] ;
64 for ( int i
= 0 ; i
< n
; ++i
)
66 M_PALETTEDATA
->m_palette
[i
].Set( red
[i
] , green
[i
] , blue
[i
] ) ;
72 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
77 long bestdiff
= 3 * 256 ;
81 for ( int i
= 0 ; i
< M_PALETTEDATA
->m_count
; ++i
)
83 const wxColour
& col
= &M_PALETTEDATA
->m_palette
[i
] ;
84 currentdiff
= abs ( col
.Red() - red
) + abs( col
.Green() - green
) + abs ( col
.Blue() - blue
) ;
85 if ( currentdiff
< bestdiff
)
87 bestdiff
= currentdiff
;
97 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
102 if (index
< 0 || index
>= M_PALETTEDATA
->m_count
)
105 const wxColour
& col
= &M_PALETTEDATA
->m_palette
[index
] ;
107 *green
= col
.Green() ;