X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8898456df4728afe7d100011e0e23b0ffb9a6341..d94de683a60b20153591cc3f8f52a97cf9ce9453:/src/common/xpmdecod.cpp diff --git a/src/common/xpmdecod.cpp b/src/common/xpmdecod.cpp index 6fd4fb11aa..b866d751aa 100644 --- a/src/common/xpmdecod.cpp +++ b/src/common/xpmdecod.cpp @@ -99,21 +99,20 @@ license is as follows: #if wxUSE_IMAGE && wxUSE_XPM +#include "wx/xpmdecod.h" + #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" + #include "wx/utils.h" + #include "wx/hashmap.h" + #include "wx/stream.h" + #include "wx/image.h" #endif -#include "wx/stream.h" -#include "wx/image.h" -#include "wx/utils.h" -#include "wx/hashmap.h" #include - #include -#include "wx/xpmdecod.h" - #if wxUSE_STREAMS bool wxXPMDecoder::CanRead(wxInputStream& stream) { @@ -657,7 +656,7 @@ struct wxXPMColourMapData }; WX_DECLARE_STRING_HASH_MAP(wxXPMColourMapData, wxXPMColourMap); -wxImage wxXPMDecoder::ReadData(const char **xpm_data) +wxImage wxXPMDecoder::ReadData(const char* const* xpm_data) { wxCHECK_MSG(xpm_data, wxNullImage, wxT("NULL XPM data") ); @@ -734,11 +733,6 @@ wxImage wxXPMDecoder::ReadData(const char **xpm_data) if ( isNone ) { - img.SetMask(true); - img.SetMaskColour(255, 0, 255); - clr_data.R = - clr_data.B = 255; - clr_data.G = 0; hasMask = true; maskKey = key; } @@ -746,22 +740,23 @@ wxImage wxXPMDecoder::ReadData(const char **xpm_data) clr_tbl[key] = clr_data; } - /* - * Modify colour entries with RGB = (255,0,255) to (255,0,254) if - * mask colour is present (so that existing pixels with (255,0,255) - * magenta colour are not incorrectly made transparent): - */ + // 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 (hasMask) { - for (it = clr_tbl.begin(); it != clr_tbl.end(); ++it) + unsigned char r, g, b; + if ( !img.FindFirstUnusedColour(&r, &g, &b) ) { - if (it->second.R == 255 && it->second.G == 0 && - it->second.B == 255 && - it->first != maskKey) - { - it->second.B = 254; - } + wxLogError(_("XPM: no colors left to use for mask!")); + return wxNullImage; } + + clr_tbl[maskKey].R = r; + clr_tbl[maskKey].G = g; + clr_tbl[maskKey].B = b; + + img.SetMask(true); + img.SetMaskColour(r, g, b); } /*