]> git.saurik.com Git - wxWidgets.git/blame - src/mac/palette.cpp
corrected path format for wxMac compiled with Apple DevTools
[wxWidgets.git] / src / mac / 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{
519cb848 39 delete[] m_palette ;
e9576ca5
SC
40}
41
42wxPalette::wxPalette()
43{
44}
45
46wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
47{
48 Create(n, red, green, blue);
49}
50
51wxPalette::~wxPalette()
52{
53}
54
55bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
56{
57 UnRef();
58
59 m_refData = new wxPaletteRefData;
60
519cb848
SC
61 M_PALETTEDATA->m_count = n ;
62 M_PALETTEDATA->m_palette = new wxColour[n] ;
63
64 for ( int i = 0 ; i < n ; ++i)
65 {
66 M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ;
67 }
e9576ca5
SC
68
69 return FALSE;
70}
71
72int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const
73{
74 if ( !m_refData )
519cb848
SC
75 return -1;
76
77 long bestdiff = 3 * 256 ;
78 long bestpos = 0 ;
79 long currentdiff ;
80
81 for ( int i = 0 ; i < M_PALETTEDATA->m_count ; ++i )
82 {
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 )
86 {
87 bestdiff = currentdiff ;
88 bestpos = i ;
89 if ( bestdiff == 0 )
90 break ;
91 }
92 }
93
94 return bestpos;
e9576ca5
SC
95}
96
97bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
98{
99 if ( !m_refData )
100 return FALSE;
101
519cb848 102 if (index < 0 || index >= M_PALETTEDATA->m_count)
e9576ca5
SC
103 return FALSE;
104
519cb848
SC
105 const wxColour& col = &M_PALETTEDATA->m_palette[index] ;
106 *red = col.Red() ;
107 *green = col.Green() ;
108 *blue = col.Blue() ;
109
110 return TRUE;
e9576ca5
SC
111}
112
fedad417
GD
113#endif
114 // wxUSE_PALETTE
e9576ca5 115