restore the stream position in wxImageHandler itself instead of forcing all
derived classes to do it themselves git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15642 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
6307da56b8
commit
39d16996b7
@ -53,7 +53,7 @@ public:
|
||||
|
||||
virtual int GetImageCount( wxInputStream& stream );
|
||||
|
||||
bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); }
|
||||
bool CanRead( wxInputStream& stream ) { return CallDoCanRead(stream); }
|
||||
bool CanRead( const wxString& name );
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
@ -71,6 +71,9 @@ protected:
|
||||
virtual bool DoCanRead( wxInputStream& stream ) = 0;
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
// save the stream position, call DoCanRead() and restore the position
|
||||
bool CallDoCanRead(wxInputStream& stream);
|
||||
|
||||
wxString m_name;
|
||||
wxString m_extension;
|
||||
wxString m_mime;
|
||||
|
@ -620,7 +620,7 @@ bool wxGIFDecoder::CanRead()
|
||||
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
|
||||
return FALSE;
|
||||
|
||||
m_f->SeekI(-WXSIZEOF(buf), wxFromCurrent);
|
||||
m_f->SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
|
||||
|
||||
return memcmp(buf, "GIF", WXSIZEOF(buf)) == 0;
|
||||
}
|
||||
|
@ -879,8 +879,6 @@ bool wxBMPHandler::DoCanRead(wxInputStream& stream)
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return FALSE;
|
||||
|
||||
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
|
||||
|
||||
// do we have the BMP file signature?
|
||||
return hdr[0] == 'B' && hdr[1] == 'M';
|
||||
}
|
||||
@ -1201,12 +1199,11 @@ int wxICOHandler::GetImageCount(wxInputStream& stream)
|
||||
bool wxICOHandler::DoCanRead(wxInputStream& stream)
|
||||
{
|
||||
unsigned char hdr[4];
|
||||
off_t iPos = stream.TellI();
|
||||
stream.SeekI (0);
|
||||
stream.Read(hdr, 4);
|
||||
stream.SeekI(iPos);
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return FALSE;
|
||||
|
||||
// hdr[2] is one for an icon and two for a cursor
|
||||
return (hdr[0] == '\0' && hdr[1] == '\0' && hdr[2] == '\1' && hdr[3] == '\0');
|
||||
return hdr[0] == '\0' && hdr[1] == '\0' && hdr[2] == '\1' && hdr[3] == '\0';
|
||||
}
|
||||
|
||||
|
||||
@ -1220,12 +1217,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxCURHandler, wxICOHandler)
|
||||
bool wxCURHandler::DoCanRead(wxInputStream& stream)
|
||||
{
|
||||
unsigned char hdr[4];
|
||||
off_t iPos = stream.TellI();
|
||||
stream.SeekI (0);
|
||||
stream.Read(hdr, 4);
|
||||
stream.SeekI(iPos);
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return FALSE;
|
||||
|
||||
// hdr[2] is one for an icon and two for a cursor
|
||||
return (hdr[0] == '\0' && hdr[1] == '\0' && hdr[2] == '\2' && hdr[3] == '\0');
|
||||
return hdr[0] == '\0' && hdr[1] == '\0' && hdr[2] == '\2' && hdr[3] == '\0';
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1297,8 +1293,9 @@ bool wxANIHandler::DoCanRead(wxInputStream& stream)
|
||||
wxInt32 *list32 = (wxInt32 *) listtxt;
|
||||
wxInt32 *anih32 = (wxInt32 *) anihtxt;
|
||||
|
||||
stream.SeekI(0);
|
||||
stream.Read(&FCC1, 4);
|
||||
if ( !stream.Read(&FCC1, 4) )
|
||||
return FALSE;
|
||||
|
||||
if ( FCC1 != *riff32 )
|
||||
return FALSE;
|
||||
|
||||
|
@ -1286,12 +1286,32 @@ bool wxImageHandler::CanRead( const wxString& name )
|
||||
return CanRead(stream);
|
||||
}
|
||||
|
||||
else {
|
||||
wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
// return FALSE;
|
||||
|
||||
bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
|
||||
{
|
||||
off_t posOld = stream.TellI();
|
||||
if ( posOld == wxInvalidOffset )
|
||||
{
|
||||
// can't test unseekable stream
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool ok = DoCanRead(stream);
|
||||
|
||||
// restore the old position to be able to test other formats and so on
|
||||
if ( stream.SeekI(posOld) == wxInvalidOffset )
|
||||
{
|
||||
wxLogDebug(_T("Failed to rewind the stream in wxImageHandler!"));
|
||||
|
||||
// reading would fail anyhow as we're not at the right position
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
@ -116,14 +116,8 @@ bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
|
||||
|
||||
bool wxGIFHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
wxGIFDecoder *decod;
|
||||
bool ok;
|
||||
|
||||
decod = new wxGIFDecoder(&stream);
|
||||
ok = decod->CanRead();
|
||||
delete decod;
|
||||
|
||||
return ok;
|
||||
wxGIFDecoder decod(&stream);
|
||||
return decod.CanRead();
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
@ -235,7 +235,7 @@ bool wxIFFDecoder::CanRead()
|
||||
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
|
||||
return FALSE;
|
||||
|
||||
m_f->SeekI(-WXSIZEOF(buf), wxFromCurrent);
|
||||
m_f->SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
|
||||
|
||||
return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0);
|
||||
}
|
||||
@ -785,14 +785,9 @@ bool wxIFFHandler::SaveFile(wxImage * WXUNUSED(image),
|
||||
|
||||
bool wxIFFHandler::DoCanRead(wxInputStream& stream)
|
||||
{
|
||||
wxIFFDecoder *decod;
|
||||
bool ok;
|
||||
wxIFFDecoder decod(&stream);
|
||||
|
||||
decod = new wxIFFDecoder(&stream);
|
||||
ok = decod->CanRead();
|
||||
delete decod;
|
||||
|
||||
return ok;
|
||||
return decod.CanRead();
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
@ -381,7 +381,6 @@ bool wxJPEGHandler::DoCanRead( wxInputStream& stream )
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return FALSE;
|
||||
|
||||
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
|
||||
return hdr[0] == 0xFF && hdr[1] == 0xD8;
|
||||
}
|
||||
|
||||
|
@ -490,8 +490,6 @@ bool wxPCXHandler::DoCanRead( wxInputStream& stream )
|
||||
if ( !stream )
|
||||
return FALSE;
|
||||
|
||||
stream.SeekI(-1, wxFromCurrent);
|
||||
|
||||
// not very safe, but this is all we can get from PCX header :-(
|
||||
return c == 10;
|
||||
}
|
||||
|
@ -421,8 +421,6 @@ bool wxPNGHandler::DoCanRead( wxInputStream& stream )
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return FALSE;
|
||||
|
||||
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
|
||||
|
||||
return memcmp(hdr, "\211PNG", WXSIZEOF(hdr)) == 0;
|
||||
}
|
||||
|
||||
|
@ -137,8 +137,6 @@ bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUS
|
||||
|
||||
bool wxPNMHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
off_t pos = stream.TellI();
|
||||
|
||||
Skip_Comment(stream);
|
||||
|
||||
if ( stream.GetC() == 'P' )
|
||||
@ -147,12 +145,10 @@ bool wxPNMHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
case '3':
|
||||
case '6':
|
||||
stream.SeekI(pos);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
stream.SeekI(pos);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -373,8 +373,6 @@ bool wxTIFFHandler::DoCanRead( wxInputStream& stream )
|
||||
if ( !stream.Read(&hdr, WXSIZEOF(hdr)) )
|
||||
return FALSE;
|
||||
|
||||
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
|
||||
|
||||
return (hdr[0] == 'I' && hdr[1] == 'I') ||
|
||||
(hdr[0] == 'M' && hdr[1] == 'M');
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ bool wxXPMDecoder::CanRead(wxInputStream& stream)
|
||||
if ( !stream.Read(buf, WXSIZEOF(buf)) )
|
||||
return FALSE;
|
||||
|
||||
stream.SeekI(-WXSIZEOF(buf), wxFromCurrent);
|
||||
stream.SeekI(-(off_t)WXSIZEOF(buf), wxFromCurrent);
|
||||
|
||||
return memcmp(buf, "/* XPM */", WXSIZEOF(buf)) == 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user