]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagpnm.cpp
implement button support for pre-XP systems (or with themes disabled); using only...
[wxWidgets.git] / src / common / imagpnm.cpp
index 4c1a6205c9fc967041cd44d17c69c7960af090e3..2b3e75f979aa7196b205d3396700e6c2a4acd074 100644 (file)
@@ -96,6 +96,8 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
         for (wxUint32 i=0; i<size; ++i)
         {
             value=text_stream.Read32();
+            if ( maxval != 255 )
+                value = (255 * value)/maxval;
             *ptr++=(unsigned char)value; // R
             *ptr++=(unsigned char)value; // G
             *ptr++=(unsigned char)value; // B
@@ -114,6 +116,8 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
             //this is very slow !!!
             //I wonder how we can make any better ?
             value=text_stream.Read32();
+            if ( maxval != 255 )
+                value = (255 * value)/maxval;
             *ptr++=(unsigned char)value;
 
             if ( !buf_stream )
@@ -130,6 +134,8 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
         for (wxUint32 i=0; i<size; ++i)
         {
             buf_stream.Read(&value,1);
+            if ( maxval != 255 )
+                value = (255 * value)/maxval;
             *ptr++=value; // R
             *ptr++=value; // G
             *ptr++=value; // B
@@ -140,8 +146,16 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose
             }
         }
     }
-    if (c=='6') // Raw RGB
-      buf_stream.Read( ptr, 3*width*height );
+
+    if ( c=='6' ) // Raw RGB
+    {
+        buf_stream.Read(ptr, 3*width*height);
+        if ( maxval != 255 )
+        {
+            for ( unsigned i = 0; i < 3*width*height; i++ )
+                ptr[i] = (255 * ptr[i])/maxval;
+        }
+    }
 
     image->SetMask( false );
 
@@ -166,6 +180,7 @@ bool wxPNMHandler::DoCanRead( wxInputStream& stream )
 {
     Skip_Comment(stream);
 
+    // it's ok to modify the stream position here
     if ( stream.GetC() == 'P' )
     {
         switch ( stream.GetC() )