]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagbmp.cpp
added xpmdecod.cpp
[wxWidgets.git] / src / common / imagbmp.cpp
index 600d800ff9dee6160d7cfd2ea430615a4b3a9b1c..9f92b3c8fc6505d6e8ea22194c6c6d8308af6529 100644 (file)
 #pragma hdrstop
 #endif
 
 #pragma hdrstop
 #endif
 
+#include "wx/defs.h"
+
+#if wxUSE_IMAGE
+
 #include "wx/imagbmp.h"
 #include "wx/bitmap.h"
 #include "wx/debug.h"
 #include "wx/imagbmp.h"
 #include "wx/bitmap.h"
 #include "wx/debug.h"
@@ -286,13 +290,26 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
      */
     if (bpp < 16 && ncolors != 0)
     {
      */
     if (bpp < 16 && ncolors != 0)
     {
+        unsigned char* r = new unsigned char[ncolors];
+        unsigned char* g = new unsigned char[ncolors];
+        unsigned char* b = new unsigned char[ncolors];
         for (int j = 0; j < ncolors; j++)
         {
             stream.Read( bbuf, 4 );
             cmap[j].b = bbuf[0];
             cmap[j].g = bbuf[1];
             cmap[j].r = bbuf[2];
         for (int j = 0; j < ncolors; j++)
         {
             stream.Read( bbuf, 4 );
             cmap[j].b = bbuf[0];
             cmap[j].g = bbuf[1];
             cmap[j].r = bbuf[2];
+
+            r[j] = cmap[j].r;
+            g[j] = cmap[j].g;
+            b[j] = cmap[j].b;
         }
         }
+        // Set the palette for the wxImage
+        image->SetPalette(wxPalette(ncolors, r, g, b));
+
+        delete[] r;
+        delete[] g;
+        delete[] b;
     }
     else if (bpp == 16 || bpp == 32)
     {
     }
     else if (bpp == 16 || bpp == 32)
     {
@@ -370,7 +387,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
                 if (bpp == 1)
                 {
                     int bit = 0;
                 if (bpp == 1)
                 {
                     int bit = 0;
-                    for (bit = 0; bit < 8; bit++)
+                    for (bit = 0; bit < 8 && column < width; bit++)
                     {
                         index = ((aByte & (0x80 >> bit)) ? 1 : 0);
                         ptr[poffset] = cmap[index].r;
                     {
                         index = ((aByte & (0x80 >> bit)) ? 1 : 0);
                         ptr[poffset] = cmap[index].r;
@@ -392,7 +409,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
                     else
                     {
                         int nibble = 0;
                     else
                     {
                         int nibble = 0;
-                        for (nibble = 0; nibble < 2; nibble++)
+                        for (nibble = 0; nibble < 2 && column < width; nibble++)
                         {
                             index = ((aByte & (0xF0 >> nibble * 4)) >> (!nibble * 4));
                             if (index >= 16)
                         {
                             index = ((aByte & (0xF0 >> nibble * 4)) >> (!nibble * 4));
                             if (index >= 16)
@@ -448,7 +465,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
                         }
                         else
                         {
                         }
                         else
                         {
-                            for (int l = 0; l < first; l++)
+                            for (int l = 0; l < first && column < width; l++)
                             {
                                 ptr[poffset    ] = cmap[aByte].r;
                                 ptr[poffset + 1] = cmap[aByte].g;
                             {
                                 ptr[poffset    ] = cmap[aByte].r;
                                 ptr[poffset + 1] = cmap[aByte].g;
@@ -533,4 +550,4 @@ bool wxBMPHandler::DoCanRead( wxInputStream& stream )
 
 #endif // wxUSE_STREAMS
 
 
 #endif // wxUSE_STREAMS
 
-
+#endif // wxUSE_IMAGE