]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/xpmdecod.cpp
Applied patch [ 1701723 ] wxAUI: Added event for doubleclicks on the tabbar bg
[wxWidgets.git] / src / common / xpmdecod.cpp
index 04b25527e2789cc278305f2dc1390086120e49eb..b866d751aa5bd0c358a7b12640218a31d11ceeb2 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        xpmdecod.cpp
+// Name:        src/common/xpmdecod.cpp
 // Purpose:     wxXPMDecoder
 // Author:      John Cristy, Vaclav Slavik
 // RCS-ID:      $Id$
 // Purpose:     wxXPMDecoder
 // Author:      John Cristy, Vaclav Slavik
 // RCS-ID:      $Id$
@@ -94,27 +94,25 @@ license is as follows:
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#  pragma hdrstop
+    #pragma hdrstop
 #endif
 
 #endif
 
+#if wxUSE_IMAGE && wxUSE_XPM
+
+#include "wx/xpmdecod.h"
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-#  include "wx/defs.h"
+    #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
 
 #endif
 
-#if wxUSE_IMAGE && wxUSE_XPM
-
-#include "wx/stream.h"
-#include "wx/image.h"
-#include "wx/utils.h"
-#include "wx/log.h"
-#include "wx/hashmap.h"
-#include "wx/intl.h"
 #include <string.h>
 #include <string.h>
-
 #include <ctype.h>
 
 #include <ctype.h>
 
-#include "wx/xpmdecod.h"
-
 #if wxUSE_STREAMS
 bool wxXPMDecoder::CanRead(wxInputStream& stream)
 {
 #if wxUSE_STREAMS
 bool wxXPMDecoder::CanRead(wxInputStream& stream)
 {
@@ -653,11 +651,12 @@ static const char *ParseColor(const char *data)
 
 struct wxXPMColourMapData
 {
 
 struct wxXPMColourMapData
 {
+    wxXPMColourMapData() { R = G = B = 0; }
     unsigned char R,G,B;
 };
 WX_DECLARE_STRING_HASH_MAP(wxXPMColourMapData, wxXPMColourMap);
 
     unsigned char R,G,B;
 };
 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") );
 
 {
     wxCHECK_MSG(xpm_data, wxNullImage, wxT("NULL XPM data") );
 
@@ -699,6 +698,7 @@ wxImage wxXPMDecoder::ReadData(const char **xpm_data)
     /*
      *  Create colour map:
      */
     /*
      *  Create colour map:
      */
+    wxXPMColourMapData clr_data;
     for (i = 0; i < colors_cnt; i++)
     {
         const char *xmpColLine = xpm_data[1 + i];
     for (i = 0; i < colors_cnt; i++)
     {
         const char *xmpColLine = xpm_data[1 + i];
@@ -711,8 +711,6 @@ wxImage wxXPMDecoder::ReadData(const char **xpm_data)
             return wxNullImage;
         }
 
             return wxNullImage;
         }
 
-        wxXPMColourMapData clr_data;
-
         for (i_key = 0; i_key < chars_per_pixel; i_key++)
             key[i_key] = (wxChar)xmpColLine[i_key];
         clr_def = ParseColor(xmpColLine + chars_per_pixel);
         for (i_key = 0; i_key < chars_per_pixel; i_key++)
             key[i_key] = (wxChar)xmpColLine[i_key];
         clr_def = ParseColor(xmpColLine + chars_per_pixel);
@@ -735,11 +733,6 @@ wxImage wxXPMDecoder::ReadData(const char **xpm_data)
 
         if ( isNone )
         {
 
         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;
         }
             hasMask = true;
             maskKey = key;
         }
@@ -747,22 +740,23 @@ wxImage wxXPMDecoder::ReadData(const char **xpm_data)
         clr_tbl[key] = clr_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)
     {
     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);
     }
 
     /*
     }
 
     /*