X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6fbf4a60fe7d1b293fabb200d43f4b8945fb522b..225dfbc51713da154f0bdc03f3ce06b9cba97970:/src/common/imagbmp.cpp diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index 99e6a5fb28..5f45ba9207 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: imagbmp.cpp +// Name: src/common/imagbmp.cpp // Purpose: wxImage BMP,ICO and CUR handlers // Author: Robert Roebling, Chris Elliott // RCS-ID: $Id$ @@ -7,31 +7,32 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "imagbmp.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#include "wx/defs.h" - #if wxUSE_IMAGE #include "wx/imagbmp.h" -#include "wx/bitmap.h" -#include "wx/debug.h" -#include "wx/log.h" -#include "wx/app.h" + +#ifndef WX_PRECOMP + #ifdef __WXMSW__ + #include "wx/msw/wrapwin.h" + #endif + #include "wx/log.h" + #include "wx/app.h" + #include "wx/bitmap.h" + #include "wx/palette.h" + #include "wx/intl.h" +#endif + #include "wx/filefn.h" #include "wx/wfstream.h" -#include "wx/intl.h" -#include "wx/module.h" #include "wx/quantize.h" +#include "wx/anidecod.h" // For memcpy #include @@ -42,10 +43,6 @@ #endif #endif -#ifdef __WXMSW__ -#include "wx/msw/wrapwin.h" -#endif - //----------------------------------------------------------------------------- // wxBMPHandler //----------------------------------------------------------------------------- @@ -927,7 +924,7 @@ bool wxBMPHandler::LoadDib(wxImage *image, wxInputStream& stream, verbose, IsBmp, true) ) { if (verbose) - wxLogError( _("Error in reading image DIB .") ); + wxLogError( _("Error in reading image DIB.") ); return false; } @@ -1023,7 +1020,7 @@ bool wxICOHandler::SaveFile(wxImage *image, return false; } - int images = 1; // only generate one image + const int images = 1; // only generate one image // VS: This is a hack of sort - since ICO and CUR files are almost // identical, we have all the meat in wxICOHandler and check for @@ -1051,7 +1048,7 @@ bool wxICOHandler::SaveFile(wxImage *image, // for each iamage write a description ICONDIRENTRY: ICONDIRENTRY icondirentry; - for (int i = 0; i < images; i++) + for (int img = 0; img < images; img++) { wxImage mask; @@ -1084,10 +1081,10 @@ bool wxICOHandler::SaveFile(wxImage *image, { // just make a black mask all over: mask = image->Copy(); - int k, j; - for (k = 0; k < mask.GetWidth(); k++) + int i, j; + for (i = 0; i < mask.GetWidth(); i++) for (j = 0; j < mask.GetHeight(); j++) - mask.SetRGB(k, j, 0, 0, 0 ); + mask.SetRGB(i, j, 0, 0, 0 ); } // Set the formats for image and mask // (Windows never saves with more than 8 colors): @@ -1118,7 +1115,7 @@ bool wxICOHandler::SaveFile(wxImage *image, } wxUint32 Size = cStream.GetSize(); - // wxCountingOutputStream::Ok() always returns true for now and this + // wxCountingOutputStream::IsOk() always returns true for now and this // "if" provokes VC++ warnings in optimized build #if 0 if ( !cStream.Ok() ) @@ -1328,160 +1325,28 @@ IMPLEMENT_DYNAMIC_CLASS(wxANIHandler, wxCURHandler) #if wxUSE_STREAMS bool wxANIHandler::LoadFile(wxImage *image, wxInputStream& stream, - bool verbose, int index) + bool WXUNUSED(verbose), int index) { - wxInt32 FCC1, FCC2; - wxUint32 datalen; - - wxInt32 riff32; - memcpy( &riff32, "RIFF", 4 ); - wxInt32 list32; - memcpy( &list32, "LIST", 4 ); - wxInt32 ico32; - memcpy( &ico32, "icon", 4 ); - int iIcon = 0; - - stream.SeekI(0); - stream.Read(&FCC1, 4); - if ( FCC1 != riff32 ) + wxANIDecoder decoder; + if (!decoder.Load(stream)) return false; - // we have a riff file: - while (stream.IsOk()) - { - // we always have a data size - stream.Read(&datalen, 4); - datalen = wxINT32_SWAP_ON_BE(datalen) ; - //data should be padded to make even number of bytes - if (datalen % 2 == 1) datalen ++ ; - //now either data or a FCC - if ( (FCC1 == riff32) || (FCC1 == list32) ) - { - stream.Read(&FCC2, 4); - } - else - { - if (FCC1 == ico32 && iIcon >= index) - { - return DoLoadFile(image, stream, verbose, -1); - } - else - { - stream.SeekI(stream.TellI() + datalen); - if ( FCC1 == ico32 ) - iIcon ++; - } - } - - // try to read next data chunk: - stream.Read(&FCC1, 4); - } - return false; + return decoder.ConvertToImage(index != -1 ? (size_t)index : 0, image); } bool wxANIHandler::DoCanRead(wxInputStream& stream) { - wxInt32 FCC1, FCC2; - wxUint32 datalen ; - - wxInt32 riff32; - memcpy( &riff32, "RIFF", 4 ); - wxInt32 list32; - memcpy( &list32, "LIST", 4 ); - wxInt32 ico32; - memcpy( &ico32, "icon", 4 ); - wxInt32 anih32; - memcpy( &anih32, "anih", 4 ); - - stream.SeekI(0); - if ( !stream.Read(&FCC1, 4) ) - return false; - - if ( FCC1 != riff32 ) - return false; - - // we have a riff file: - while ( stream.IsOk() ) - { - if ( FCC1 == anih32 ) - return true; - // we always have a data size: - stream.Read(&datalen, 4); - datalen = wxINT32_SWAP_ON_BE(datalen) ; - //data should be padded to make even number of bytes - if (datalen % 2 == 1) datalen ++ ; - // now either data or a FCC: - if ( (FCC1 == riff32) || (FCC1 == list32) ) - { - stream.Read(&FCC2, 4); - } - else - { - stream.SeekI(stream.TellI() + datalen); - } - - // try to read next data chunk: - if ( !stream.Read(&FCC1, 4) ) - { - // reading failed -- either EOF or IO error, bail out anyhow - return false; - } - } - - return false; + wxANIDecoder decod; + return decod.CanRead(stream); } int wxANIHandler::GetImageCount(wxInputStream& stream) { - wxInt32 FCC1, FCC2; - wxUint32 datalen ; - - wxInt32 riff32; - memcpy( &riff32, "RIFF", 4 ); - wxInt32 list32; - memcpy( &list32, "LIST", 4 ); - wxInt32 ico32; - memcpy( &ico32, "icon", 4 ); - wxInt32 anih32; - memcpy( &anih32, "anih", 4 ); - - stream.SeekI(0); - stream.Read(&FCC1, 4); - if ( FCC1 != riff32 ) + wxANIDecoder decoder; + if (!decoder.Load(stream)) return wxNOT_FOUND; - // we have a riff file: - while ( stream.IsOk() ) - { - // we always have a data size: - stream.Read(&datalen, 4); - datalen = wxINT32_SWAP_ON_BE(datalen) ; - //data should be padded to make even number of bytes - if (datalen % 2 == 1) datalen ++ ; - // now either data or a FCC: - if ( (FCC1 == riff32) || (FCC1 == list32) ) - { - stream.Read(&FCC2, 4); - } - else - { - if ( FCC1 == anih32 ) - { - wxUint32 *pData = new wxUint32[datalen/4]; - stream.Read(pData, datalen); - int nIcons = wxINT32_SWAP_ON_BE(*(pData + 1)); - delete[] pData; - return nIcons; - } - else - stream.SeekI(stream.TellI() + datalen); - } - - // try to read next data chunk: - stream.Read(&FCC1, 4); - } - - return wxNOT_FOUND; + return decoder.GetFrameCount(); } #endif // wxUSE_STREAMS