]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagpcx.cpp
Don't complain under MicroWindows if a wxDC's HDC is NULL - it happens
[wxWidgets.git] / src / common / imagpcx.cpp
index 3b806c35f487a521ecb391236ac3625bcb64cb44..846130b6877f5c0f064a74e6a7b45f914e1e1105 100644 (file)
@@ -23,7 +23,7 @@
 #  include "wx/defs.h"
 #endif
 
-#if wxUSE_STREAMS && wxUSE_PCX
+#if wxUSE_IMAGE && wxUSE_STREAMS && wxUSE_PCX
 
 #include "wx/imagpcx.h"
 #include "wx/wfstream.h"
@@ -102,7 +102,7 @@ void RLEdecode(unsigned char *p, unsigned int size, wxInputStream& s)
                  //
         if ((data & 0xC0) != 0xC0)
         {
-            *(p++) = data;
+            *(p++) = (unsigned char)data;
             size--;
         }
         else
@@ -110,7 +110,7 @@ void RLEdecode(unsigned char *p, unsigned int size, wxInputStream& s)
             cont = data & 0x3F;
             data = (unsigned char)s.GetC();
             for (i = 1; i <= cont; i++)
-                *(p++) = data;
+                *(p++) = (unsigned char)data;
             size -= cont;
         }
     }
@@ -276,6 +276,18 @@ int ReadPCX(wxImage *image, wxInputStream& stream)
             *(p++) = pal[3 * index + 1];
             *(p++) = pal[3 * index + 2];
         }
+
+        unsigned char* r = new unsigned char[256];
+        unsigned char* g = new unsigned char[256];
+        unsigned char* b = new unsigned char[256];
+        for (i = 0; i < 256; i++)
+        {
+            r[i] = pal[3*i + 0];
+            g[i] = pal[3*i + 1];
+            b[i] = pal[3*i + 2];
+        }
+        image->SetPalette(wxPalette(256, r, g, b));
+        delete[] r; delete[] g; delete[] b;
     }
 
     return wxPCX_OK;
@@ -337,12 +349,12 @@ int SavePCX(wxImage *image, wxOutputStream& stream)
     hdr[HDR_ENCODING]         = 1;
     hdr[HDR_NPLANES]          = nplanes;
     hdr[HDR_BITSPERPIXEL]     = 8;
-    hdr[HDR_BYTESPERLINE]     = bytesperline % 256;
-    hdr[HDR_BYTESPERLINE + 1] = bytesperline / 256;
-    hdr[HDR_XMAX]             = (width - 1)  % 256;
-    hdr[HDR_XMAX + 1]         = (width - 1)  / 256;
-    hdr[HDR_YMAX]             = (height - 1) % 256;
-    hdr[HDR_YMAX + 1]         = (height - 1) / 256;
+    hdr[HDR_BYTESPERLINE]     = (unsigned char)(bytesperline % 256);
+    hdr[HDR_BYTESPERLINE + 1] = (unsigned char)(bytesperline / 256);
+    hdr[HDR_XMAX]             = (unsigned char)((width - 1)  % 256);
+    hdr[HDR_XMAX + 1]         = (unsigned char)((width - 1)  / 256);
+    hdr[HDR_YMAX]             = (unsigned char)((height - 1) % 256);
+    hdr[HDR_YMAX + 1]         = (unsigned char)((height - 1) / 256);
     hdr[HDR_PALETTEINFO]      = 1;
 
     stream.Write(hdr, 128);
@@ -444,10 +456,10 @@ bool wxPCXHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
         {
             switch (error)
             {
-                case wxPCX_INVFORMAT: wxLogError(_("wxPCXHandler: image format unsupported")); break;
-                case wxPCX_MEMERR:    wxLogError(_("wxPCXHandler: couldn't allocate memory")); break;
-                case wxPCX_VERERR:    wxLogError(_("wxPCXHandler: version number too low")); break;
-                default:              wxLogError(_("wxPCXHandler: unknown error !!!"));
+                case wxPCX_INVFORMAT: wxLogError(_("PCX: image format unsupported")); break;
+                case wxPCX_MEMERR:    wxLogError(_("PCX: couldn't allocate memory")); break;
+                case wxPCX_VERERR:    wxLogError(_("PCX: version number too low")); break;
+                default:              wxLogError(_("PCX: unknown error !!!"));
             }
         }
         image->Destroy();
@@ -467,9 +479,9 @@ bool wxPCXHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
         {
             switch (error)
             {
-                case wxPCX_INVFORMAT: wxLogError(_("wxPCXHandler: invalid image")); break;
-                case wxPCX_MEMERR:    wxLogError(_("wxPCXHandler: couldn't allocate memory")); break;
-                default:              wxLogError(_("wxPCXHandler: unknown error !!!"));
+                case wxPCX_INVFORMAT: wxLogError(_("PCX: invalid image")); break;
+                case wxPCX_MEMERR:    wxLogError(_("PCX: couldn't allocate memory")); break;
+                default:              wxLogError(_("PCX: unknown error !!!"));
             }
         }
     }