]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
18 #include "wx/palette.h"
33 wxPaletteRefData::wxPaletteRefData()
38 wxPaletteRefData::~wxPaletteRefData()
42 // TODO: ::DeleteObject((HPALETTE) m_hPalette);
45 wxPalette::wxPalette()
49 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
51 Create(n
, red
, green
, blue
);
54 wxPalette::~wxPalette()
58 bool wxPalette::FreeResource(bool force
)
60 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
62 // TODO: DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette);
67 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
71 m_refData
= new wxPaletteRefData
;
75 NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
76 (WORD)n * sizeof(PALETTEENTRY));
80 npPal->palVersion = 0x300;
81 npPal->palNumEntries = n;
84 for (i = 0; i < n; i ++)
86 npPal->palPalEntry[i].peRed = red[i];
87 npPal->palPalEntry[i].peGreen = green[i];
88 npPal->palPalEntry[i].peBlue = blue[i];
89 npPal->palPalEntry[i].peFlags = 0;
91 M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal);
92 LocalFree((HANDLE)npPal);
97 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
106 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
111 if (index
< 0 || index
> 255)
116 if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry))
119 *green = entry.peGreen;
120 *blue = entry.peBlue;
128 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
131 m_refData
= new wxPaletteRefData
;
133 M_PALETTEDATA
->m_hPalette
= pal
;