]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/palette.cpp
compilation warning fix
[wxWidgets.git] / src / mac / carbon / palette.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: palette.cpp
3// Purpose: wxPalette
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "palette.h"
14#endif
15
fedad417
GD
16#include "wx/defs.h"
17
18#if wxUSE_PALETTE
19
e9576ca5
SC
20#include "wx/palette.h"
21
2f1ae414 22#if !USE_SHARED_LIBRARIES
e9576ca5 23IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
2f1ae414 24#endif
e9576ca5
SC
25
26/*
27 * Palette
28 *
29 */
30
31wxPaletteRefData::wxPaletteRefData()
32{
519cb848
SC
33 m_palette = NULL ;
34 m_count = 0 ;
e9576ca5
SC
35}
36
37wxPaletteRefData::~wxPaletteRefData()
38{
f5bb2251
GD
39 if (m_palette != NULL) {
40 delete[] m_palette ;
41 m_palette = NULL;
42 }
e9576ca5
SC
43}
44
45wxPalette::wxPalette()
46{
47}
48
49wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
50{
51 Create(n, red, green, blue);
52}
53
54wxPalette::~wxPalette()
55{
56}
57
58bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
59{
60 UnRef();
61
62 m_refData = new wxPaletteRefData;
63
519cb848
SC
64 M_PALETTEDATA->m_count = n ;
65 M_PALETTEDATA->m_palette = new wxColour[n] ;
66
67 for ( int i = 0 ; i < n ; ++i)
68 {
69 M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ;
70 }
e9576ca5
SC
71
72 return FALSE;
73}
74
75int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const
76{
77 if ( !m_refData )
519cb848
SC
78 return -1;
79
80 long bestdiff = 3 * 256 ;
81 long bestpos = 0 ;
82 long currentdiff ;
83
84 for ( int i = 0 ; i < M_PALETTEDATA->m_count ; ++i )
85 {
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 )
89 {
90 bestdiff = currentdiff ;
91 bestpos = i ;
92 if ( bestdiff == 0 )
93 break ;
94 }
95 }
96
97 return bestpos;
e9576ca5
SC
98}
99
100bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
101{
102 if ( !m_refData )
103 return FALSE;
104
519cb848 105 if (index < 0 || index >= M_PALETTEDATA->m_count)
e9576ca5
SC
106 return FALSE;
107
519cb848
SC
108 const wxColour& col = &M_PALETTEDATA->m_palette[index] ;
109 *red = col.Red() ;
110 *green = col.Green() ;
111 *blue = col.Blue() ;
112
113 return TRUE;
e9576ca5
SC
114}
115
fedad417
GD
116#endif
117 // wxUSE_PALETTE
e9576ca5 118