]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/xpmdecod.cpp
Fixed wxPropertyGridManager::CreatePropertyGrid(), corrected documentation about...
[wxWidgets.git] / src / common / xpmdecod.cpp
index a752ead86f44ad8e758bd29c00b9c33b258639ce..54e54c5221e5aeabe90011754f6e19d01793b815 100644 (file)
@@ -108,6 +108,7 @@ license is as follows:
     #include "wx/hashmap.h"
     #include "wx/stream.h"
     #include "wx/image.h"
+    #include "wx/palette.h"
 #endif
 
 #include <string.h>
@@ -121,7 +122,8 @@ bool wxXPMDecoder::CanRead(wxInputStream& stream)
     if ( !stream.Read(buf, WXSIZEOF(buf)) )
         return false;
 
-    stream.SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent);
+    if (stream.SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent) == wxInvalidOffset)
+        return false;
 
     return memcmp(buf, "/* XPM */", WXSIZEOF(buf)) == 0;
 }
@@ -809,7 +811,23 @@ wxImage wxXPMDecoder::ReadData(const char* const* xpm_data)
             img_data[2] = entry->second.B;
         }
     }
+#if wxUSE_PALETTE
+    unsigned char* r = new unsigned char[colors_cnt];
+    unsigned char* g = new unsigned char[colors_cnt];
+    unsigned char* b = new unsigned char[colors_cnt];
 
+    for (it = clr_tbl.begin(), i = 0; it != clr_tbl.end(); it++, i++)
+    {
+        r[i] = it->second.R;
+        g[i] = it->second.G;
+        b[i] = it->second.B;
+    }
+    wxASSERT(i == colors_cnt);
+    img.SetPalette(wxPalette(colors_cnt, r, g, b));
+    delete[] r;
+    delete[] g;
+    delete[] b;
+#endif // wxUSE_PALETTE
     return img;
 }