+ // For 8 bit images, we read the palette, and then do a second
+ // pass replacing indexes with their RGB values;
+
+ if (format == wxPCX_8BIT)
+ {
+ unsigned char index;
+
+ if (stream.GetC() != 12)
+ return wxPCX_INVFORMAT;
+
+ stream.Read(pal, 768);
+
+ p = image->GetData();
+ for (unsigned long k = height * width; k; k--)
+ {
+ index = *p;
+ *(p++) = pal[3 * index];
+ *(p++) = pal[3 * index + 1];
+ *(p++) = pal[3 * index + 2];
+ }
+
+ unsigned char* r = new unsigned char[256];
+ unsigned char* g = new unsigned char[256];
+ unsigned char* b = new unsigned char[256];
+ for (i = 0; i < 256; i++)
+ {
+ r[i] = pal[3*i + 0];
+ g[i] = pal[3*i + 1];
+ b[i] = pal[3*i + 2];
+ }
+ image->SetPalette(wxPalette(256, r, g, b));
+ delete[] r; delete[] g; delete[] b;
+ }
+