+bool wxPalette::TransferBitmap8(unsigned char *data, unsigned long sz,
+ void *dest, unsigned int bpp)
+{
+ int pix_array_n;
+ unsigned long *pix_array = GetXPixArray((Display*) wxGetDisplay(), &pix_array_n);
+ switch(bpp) {
+ case 8: {
+ unsigned char *dptr = (unsigned char *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n)
+ *dptr = (unsigned char)pix_array[*data];
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ case 16: {
+ unsigned short *dptr = (unsigned short *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n)
+ *dptr = (unsigned short)pix_array[*data];
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ case 24: {
+ struct rgb24 { unsigned char r, g, b; } *dptr = (struct rgb24 *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n) {
+ dptr->r = (unsigned char)(pix_array[*data] & 0xFF);
+ dptr->g = (unsigned char)((pix_array[*data] >> 8) & 0xFF);
+ dptr->b = (unsigned char)((pix_array[*data] >> 16) & 0xFF);
+ }
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ case 32: {
+ unsigned long *dptr = (unsigned long *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n)
+ *dptr = pix_array[*data];
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ default:
+ return false;
+ }
+ return true;
+}
+
+unsigned long *wxPalette::GetXPixArray(WXDisplay *display, int *n)
+{
+ if (!M_PALETTEDATA)
+ return (unsigned long*) 0;
+ wxList::compatibility_iterator node;
+
+ for (node = M_PALETTEDATA->m_palettes.GetFirst(); node;
+ node = node->GetNext())
+ {
+ wxXPalette *c = (wxXPalette *)node->GetData();
+ if (c->m_display == display)
+ {
+ if (n)
+ *n = c->m_pix_array_n;
+ return c->m_pix_array;
+ }
+ }
+
+ /* Not found; call GetXColormap, which will create it, then this again */
+ if (GetXColormap(display))
+ return GetXPixArray(display, n);
+ else
+ return (unsigned long*) 0;
+}
+
+void wxPalette::PutXColormap(WXDisplay* display, WXColormap cm, bool dp)
+{
+ UnRef();
+
+ m_refData = new wxPaletteRefData;
+
+ wxXPalette *c = new wxXPalette;
+
+ c->m_pix_array_n = 0;
+ c->m_pix_array = (unsigned long*) NULL;
+ c->m_display = display;
+ c->m_cmap = cm;
+ c->m_destroyable = dp;
+
+ M_PALETTEDATA->m_palettes.Append(c);
+}