]>
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"
16 #include "wx/palette.h"
18 #if !USE_SHARED_LIBRARIES
19 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
27 wxPaletteRefData::wxPaletteRefData()
33 wxPaletteRefData::~wxPaletteRefData()
38 wxPalette::wxPalette()
42 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
44 Create(n
, red
, green
, blue
);
47 wxPalette::~wxPalette()
51 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
55 m_refData
= new wxPaletteRefData
;
57 M_PALETTEDATA
->m_count
= n
;
58 M_PALETTEDATA
->m_palette
= new wxColour
[n
] ;
60 for ( int i
= 0 ; i
< n
; ++i
)
62 M_PALETTEDATA
->m_palette
[i
].Set( red
[i
] , green
[i
] , blue
[i
] ) ;
68 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
73 long bestdiff
= 3 * 256 ;
77 for ( int i
= 0 ; i
< M_PALETTEDATA
->m_count
; ++i
)
79 const wxColour
& col
= &M_PALETTEDATA
->m_palette
[i
] ;
80 currentdiff
= abs ( col
.Red() - red
) + abs( col
.Green() - green
) + abs ( col
.Blue() - blue
) ;
81 if ( currentdiff
< bestdiff
)
83 bestdiff
= currentdiff
;
93 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
98 if (index
< 0 || index
>= M_PALETTEDATA
->m_count
)
101 const wxColour
& col
= &M_PALETTEDATA
->m_palette
[index
] ;
103 *green
= col
.Green() ;