- bool isNone;
- if ( !GetRGBFromName(clr_def, &isNone,
- &clr_data.R, &clr_data.G, &clr_data.B) )
- {
- wxLogError(_("XPM: malformed colour definition '%s'!"), xpm_data[1+i]);
- clr_data.R = 255, clr_data.G = 0, clr_data.B = 255;
- }
- else
- {
- if ( isNone )
- {
- img.SetMask(TRUE);
- img.SetMaskColour(255, 0, 255);
- hasMask = TRUE;
- clr_data.R = 255, clr_data.G = 0, clr_data.B = 255;
- }
- else
- {
- if ( hasMask && clr_data.R == 255 &&
- clr_data.G == 0 && clr_data.B == 255 )
- clr_data.B = 254;
- }
- }
+ wxLogError(_("XPM: malformed colour definition '%s' at line %d!"),
+ xmpColLine, (int)(1 + i));
+ return wxNullImage;
+ }
+
+ keyString = key;
+ if ( isNone )
+ maskKey = keyString;
+
+ clr_tbl[keyString] = clr_data;
+ }
+
+ // deal with the mask: we must replace pseudo-colour "None" with the mask
+ // colour (which can be any colour not otherwise used in the image)
+ if (!maskKey.empty())
+ {
+ wxLongToLongHashMap rgb_table;
+ long rgb;
+ const size_t n = clr_tbl.size();
+ wxXPMColourMap::const_iterator iter = clr_tbl.begin();
+ for (i = 0; i < n; ++i, ++iter)
+ {
+ const wxXPMColourMapData& data = iter->second;
+ rgb = (data.R << 16) + (data.G << 8) + data.B;
+ rgb_table[rgb];
+ }
+ for (rgb = 0; rgb <= 0xffffff && rgb_table.count(rgb); ++rgb)
+ ;
+ if (rgb > 0xffffff)
+ {
+ wxLogError(_("XPM: no colors left to use for mask!"));
+ return wxNullImage;