]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
76e68ed2f06487679f32e3dd5107f47309b24eb0
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/palette.cpp
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/string.h"
19 #include "wx/os2/private.h"
20 #include "wx/palette.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
36 wxPaletteRefData::wxPaletteRefData()
38 m_hPalette
= NULLHANDLE
;
40 } // end of wxPaletteRefData::wxPaletteRefData
42 wxPaletteRefData::~wxPaletteRefData()
46 } // end of wxPaletteRefData::~wxPaletteRefData
48 wxPalette::wxPalette()
50 } // end of wxPalette::wxPalette
54 , const unsigned char* pRed
55 , const unsigned char* pGreen
56 , const unsigned char* pBlue
64 } // end of wxPalette::wxPalette
66 wxPalette::~wxPalette()
68 } // end of wxPalette::~wxPalette
70 bool wxPalette::FreeResource( bool WXUNUSED(bForce
) )
72 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
74 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
);
75 ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
);
78 } // end of wxPalette::FreeResource
80 bool wxPalette::Create( int n
,
81 const unsigned char* pRed
,
82 const unsigned char* pGreen
,
83 const unsigned char* pBlue
)
89 m_refData
= new wxPaletteRefData
;
90 pualTable
= new ULONG
[n
];
94 for (int i
= 0; i
< n
; i
++)
96 pualTable
[i
] = (PC_RESERVED
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
];
98 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
106 } // end of wxPalette::Create
108 int wxPalette::GetPixel( unsigned char cRed
,
109 unsigned char cGreen
,
110 unsigned char cBlue
) const
113 PULONG pualTable
= NULL
;
115 ULONG ulRGB
= (PC_RESERVED
* 16777216) +
116 ((int)cRed
* 65536) +
117 ((int)cGreen
* 256) +
124 // Get number of entries first
126 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
127 ,M_PALETTEDATA
->m_hPS
130 ,0 // Force return of number entries
134 pualTable
= new ULONG
[ulNumEntries
];
137 // Now get the entries
139 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
140 ,M_PALETTEDATA
->m_hPS
143 ,ulNumEntries
// Force return of number entries
144 ,pualTable
// Palette entry array with RGB values
147 // Now loop through and find the matching entry
150 for (i
= 0; i
< ulNumEntries
; i
++)
152 if (pualTable
[i
] == ulRGB
)
161 } // end of wxPalette::GetPixel
163 bool wxPalette::GetRGB( int nIndex
,
165 unsigned char* pGreen
,
166 unsigned char* pBlue
) const
168 PULONG pualTable
= NULL
;
175 if (nIndex
< 0 || nIndex
> 255)
178 // Get number of entries first
180 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
181 ,M_PALETTEDATA
->m_hPS
184 ,0 // Force return of number entries
188 pualTable
= new ULONG
[ulNumEntries
];
191 // Now get the entries
193 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
194 ,M_PALETTEDATA
->m_hPS
197 ,ulNumEntries
// Force return of number entries
198 ,pualTable
// Palette entry array with RGB values
201 memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
));
203 *pGreen
= vRGB
.bGreen
;
206 } // end of wxPalette::GetRGB
208 void wxPalette::SetHPALETTE(
213 m_refData
= new wxPaletteRefData
;
215 M_PALETTEDATA
->m_hPalette
= hPal
;
216 } // end of wxPalette::SetHPALETTE
218 void wxPalette::SetPS(
223 m_refData
= new wxPaletteRefData
;
225 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
);
226 M_PALETTEDATA
->m_hPS
= hPS
;
227 } // end of wxPalette::SetHPALETTE