]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/palette.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/palette.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
29 wxPaletteRefData::wxPaletteRefData()
35 wxPaletteRefData::~wxPaletteRefData()
37 if (m_palette
!= NULL
) {
43 wxPalette::wxPalette()
47 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
49 Create(n
, red
, green
, blue
);
52 wxPalette::~wxPalette()
56 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
60 m_refData
= new wxPaletteRefData
;
62 M_PALETTEDATA
->m_count
= n
;
63 M_PALETTEDATA
->m_palette
= new wxColour
[n
] ;
65 for ( int i
= 0 ; i
< n
; ++i
)
67 M_PALETTEDATA
->m_palette
[i
].Set( red
[i
] , green
[i
] , blue
[i
] ) ;
73 int wxPalette::GetPixel(unsigned char red
, unsigned char green
, unsigned char blue
) const
78 long bestdiff
= 3 * 256 ;
82 for ( int i
= 0 ; i
< M_PALETTEDATA
->m_count
; ++i
)
84 const wxColour
& col
= &M_PALETTEDATA
->m_palette
[i
] ;
85 currentdiff
= abs ( col
.Red() - red
) + abs( col
.Green() - green
) + abs ( col
.Blue() - blue
) ;
86 if ( currentdiff
< bestdiff
)
88 bestdiff
= currentdiff
;
98 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
103 if (index
< 0 || index
>= M_PALETTEDATA
->m_count
)
106 const wxColour
& col
= &M_PALETTEDATA
->m_palette
[index
] ;
108 *green
= col
.Green() ;