]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagbmp.cpp
Fix hangups when using sockets under OS X.
[wxWidgets.git] / src / common / imagbmp.cpp
index 9693a0d85e03d972882eb8fbf0e61b5d9d40edab..bf232cd51adbd34b74d252fb13e0052e2dc9a248 100644 (file)
@@ -79,12 +79,14 @@ bool wxBMPHandler::SaveDib(wxImage *image,
                            bool IsMask)
 
 {
-    wxCHECK_MSG( image, false, _T("invalid pointer in wxBMPHandler::SaveFile") );
+    wxCHECK_MSG( image, false, wxT("invalid pointer in wxBMPHandler::SaveFile") );
 
     if ( !image->Ok() )
     {
         if ( verbose )
+        {
             wxLogError(_("BMP: Couldn't save invalid image."));
+        }
         return false;
     }
 
@@ -118,7 +120,9 @@ bool wxBMPHandler::SaveDib(wxImage *image,
             )
         {
             if ( verbose )
+            {
                 wxLogError(_("BMP: wxImage doesn't have own wxPalette."));
+            }
             return false;
         }
         bpp = 8;
@@ -184,7 +188,7 @@ bool wxBMPHandler::SaveDib(wxImage *image,
     switch ( GetResolutionFromOptions(*image, &hres, &vres) )
     {
         default:
-            wxFAIL_MSG( _T("unexpected image resolution units") );
+            wxFAIL_MSG( wxT("unexpected image resolution units") );
             // fall through
 
         case wxIMAGE_RESOLUTION_NONE:
@@ -222,7 +226,9 @@ bool wxBMPHandler::SaveDib(wxImage *image,
            )
         {
             if (verbose)
+            {
                 wxLogError(_("BMP: Couldn't write the file (Bitmap) header."));
+                }
             return false;
         }
     }
@@ -243,7 +249,9 @@ bool wxBMPHandler::SaveDib(wxImage *image,
            )
         {
             if (verbose)
+            {
                 wxLogError(_("BMP: Couldn't write the file (BitmapInfo) header."));
+            }
             return false;
         }
     }
@@ -317,7 +325,9 @@ bool wxBMPHandler::SaveDib(wxImage *image,
             if ( !stream.Write(rgbquad, palette_size*4) )
             {
                 if (verbose)
+                {
                     wxLogError(_("BMP: Couldn't write RGB color map."));
+                }
                 delete[] rgbquad;
 #if wxUSE_PALETTE
                 delete palette;
@@ -450,7 +460,9 @@ bool wxBMPHandler::SaveDib(wxImage *image,
         if ( !stream.Write(buffer, row_width) )
         {
             if (verbose)
+            {
                 wxLogError(_("BMP: Couldn't write data."));
+            }
             delete[] buffer;
 #if wxUSE_PALETTE
             delete palette;
@@ -498,7 +510,9 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
         if ( !cmap )
         {
             if (verbose)
+            {
                 wxLogError(_("BMP: Couldn't allocate memory."));
+            }
             return false;
         }
     }
@@ -518,7 +532,9 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
     if ( !ptr )
     {
         if ( verbose )
+        {
             wxLogError( _("BMP: Couldn't allocate memory.") );
+        }
         return false;
     }
 
@@ -531,7 +547,9 @@ bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
         if ( !alpha )
         {
             if ( verbose )
+            {
                 wxLogError(_("BMP: Couldn't allocate memory."));
+            }
             return false;
         }
     }
@@ -924,13 +942,17 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream,
     if ( width > 32767 )
     {
         if (verbose)
+        {
             wxLogError( _("DIB Header: Image width > 32767 pixels for file.") );
+        }
         return false;
     }
     if ( height > 32767 )
     {
         if (verbose)
+        {
             wxLogError( _("DIB Header: Image height > 32767 pixels for file.") );
+        }
         return false;
     }
 
@@ -944,7 +966,9 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream,
     if ( bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32 )
     {
         if (verbose)
+        {
             wxLogError( _("DIB Header: Unknown bitdepth in file.") );
+        }
         return false;
     }
 
@@ -954,7 +978,9 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream,
          comp != BI_BITFIELDS )
     {
         if (verbose)
+        {
             wxLogError( _("DIB Header: Unknown encoding in file.") );
+        }
         return false;
     }
 
@@ -969,7 +995,9 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream,
         ((comp == BI_BITFIELDS) && (bpp != 16 && bpp != 32)))
     {
         if (verbose)
+        {
             wxLogError( _("DIB Header: Encoding doesn't match bitdepth.") );
+        }
         return false;
     }
 
@@ -978,7 +1006,9 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream,
                     verbose, IsBmp, true) )
     {
         if (verbose)
+        {
             wxLogError( _("Error in reading image DIB.") );
+        }
         return false;
     }
 
@@ -991,7 +1021,9 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream,
                         verbose, IsBmp, false) )
         {
             if (verbose)
+            {
                 wxLogError( _("ICO: Error in reading mask DIB.") );
+            }
             return false;
         }
         image->SetMaskFromImage(mask, 255, 255, 255);
@@ -1069,13 +1101,17 @@ bool wxICOHandler::SaveFile(wxImage *image,
     if ( image->GetHeight () > 127 )
     {
         if ( verbose )
+        {
             wxLogError(_("ICO: Image too tall for an icon."));
+        }
         return false;
     }
     if ( image->GetWidth () > 255 )
     {
         if ( verbose )
+        {
             wxLogError(_("ICO: Image too wide for an icon."));
+        }
         return false;
     }
 
@@ -1101,7 +1137,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
     if ( !stream.IsOk() )
     {
         if ( verbose )
+        {
             wxLogError(_("ICO: Error writing the image file!"));
+        }
         return false;
     }
 
@@ -1160,7 +1198,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
         if ( !bResult )
         {
             if ( verbose )
+            {
                 wxLogError(_("ICO: Error writing the image file!"));
+            }
             return false;
         }
         IsMask = true;
@@ -1169,7 +1209,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
         if ( !bResult )
         {
             if ( verbose )
+            {
                 wxLogError(_("ICO: Error writing the image file!"));
+            }
             return false;
         }
         wxUint32 Size = cStream.GetSize();
@@ -1180,7 +1222,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
         if ( !cStream.Ok() )
         {
             if ( verbose )
+            {
                 wxLogError(_("ICO: Error writing the image file!"));
+            }
             return false;
         }
 #endif // 0
@@ -1224,7 +1268,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
         if ( !stream.IsOk() )
         {
             if ( verbose )
+            {
                 wxLogError(_("ICO: Error writing the image file!"));
+            }
             return false;
         }
 
@@ -1234,7 +1280,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
         if ( !bResult )
         {
             if ( verbose )
+            {
                 wxLogError(_("ICO: Error writing the image file!"));
+            }
             return false;
         }
         IsMask = true;
@@ -1243,7 +1291,9 @@ bool wxICOHandler::SaveFile(wxImage *image,
         if ( !bResult )
         {
             if ( verbose )
+            {
                 wxLogError(_("ICO: Error writing the image file!"));
+            }
             return false;
         }
 
@@ -1280,11 +1330,11 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
     int iSel = wxNOT_FOUND;
 
     // remember how many bytes we read from the stream:
-    wxFileOffset offset = sizeof(IconDir);
+    wxFileOffset alreadySeeked = sizeof(IconDir);
     
     for (unsigned int i = 0; i < nIcons; i++ )
     {
-        offset += stream.Read(pCurrentEntry, sizeof(ICONDIRENTRY)).LastRead();
+        alreadySeeked += stream.Read(pCurrentEntry, sizeof(ICONDIRENTRY)).LastRead();
         
         // bHeight and bColorCount are wxUint8
         if ( pCurrentEntry->bWidth >= wMax )
@@ -1322,8 +1372,8 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
         
         // NOTE: seeking a positive amount in wxFromCurrent mode allows us to
         //       load even non-seekable streams (see wxInputStream::SeekI docs)!
-        if (stream.SeekI(wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset) - offset, 
-                         wxFromCurrent) == wxInvalidOffset)
+        wxFileOffset offset = wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset) - alreadySeeked;
+        if (offset != 0 && stream.SeekI(offset, wxFromCurrent) == wxInvalidOffset)
             return false;
         
         bResult = LoadDib(image, stream, true, IsBmp);