document that CanRead() and GetImageCount() functions of wxImageHandlers do NOT modify the current stream position and that they require seekable streams; rename current GetImageCount() functions to DoGetImageCount() and put save-and-restore stream position logic in GetImageCount(); add comments in the various DoCanRead() and in DoGetImageCount() where the stream position is modified; remove unneeded SeekI(0) calls from DoCanRead() and DoGetImageCount() functions: they didn't allow to load images from non-seekable streams; implement forward-seeking in wxInputStream::SeekI() also for non-seekable streams
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -44,7 +44,7 @@ public:
|
||||
virtual wxColour GetTransparentColour(unsigned int frame) const;
|
||||
|
||||
// implementation of wxAnimationDecoder's pure virtuals
|
||||
virtual bool CanRead( wxInputStream& stream ) const;
|
||||
|
||||
virtual bool Load( wxInputStream& stream );
|
||||
|
||||
bool ConvertToImage(unsigned int frame, wxImage *image) const;
|
||||
@@ -55,6 +55,10 @@ public:
|
||||
{ return wxANIMATION_TYPE_ANI; }
|
||||
|
||||
private:
|
||||
// wxAnimationDecoder pure virtual:
|
||||
virtual bool DoCanRead( wxInputStream& stream ) const;
|
||||
// modifies current stream position (see wxAnimationDecoder::CanRead)
|
||||
|
||||
// frames stored as wxImage(s): ANI files are meant to be used mostly for animated
|
||||
// cursors and thus they do not use any optimization to encode differences between
|
||||
// two frames: they are just a list of images to display sequentially.
|
||||
|
@@ -93,7 +93,28 @@ public:
|
||||
}
|
||||
|
||||
virtual bool Load( wxInputStream& stream ) = 0;
|
||||
virtual bool CanRead( wxInputStream& stream ) const = 0;
|
||||
|
||||
bool CanRead( wxInputStream& stream ) const
|
||||
{
|
||||
// NOTE: this code is the same of wxImageHandler::CallDoCanRead
|
||||
|
||||
if ( !stream.IsSeekable() )
|
||||
return false; // can't test unseekable stream
|
||||
|
||||
wxFileOffset posOld = stream.TellI();
|
||||
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 wxAnimationDecoder!"));
|
||||
|
||||
// reading would fail anyhow as we're not at the right position
|
||||
return false;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
virtual wxAnimationDecoder *Clone() const = 0;
|
||||
virtual wxAnimationType GetType() const = 0;
|
||||
@@ -129,6 +150,12 @@ public:
|
||||
unsigned int GetFrameCount() const { return m_nFrames; }
|
||||
|
||||
protected:
|
||||
// checks the signature of the data in the given stream and returns true if it
|
||||
// appears to be a valid animation format recognized by the animation decoder;
|
||||
// this function should modify the stream current position without taking care
|
||||
// of restoring it since CanRead() will do it.
|
||||
virtual bool DoCanRead(wxInputStream& stream) const = 0;
|
||||
|
||||
wxSize m_szAnimation;
|
||||
unsigned int m_nFrames;
|
||||
|
||||
|
@@ -76,7 +76,6 @@ public:
|
||||
void Destroy();
|
||||
|
||||
// implementation of wxAnimationDecoder's pure virtuals
|
||||
virtual bool CanRead( wxInputStream& stream ) const;
|
||||
virtual bool Load( wxInputStream& stream )
|
||||
{ return LoadGIF(stream) == wxGIF_OK; }
|
||||
|
||||
@@ -88,6 +87,15 @@ public:
|
||||
{ return wxANIMATION_TYPE_GIF; }
|
||||
|
||||
private:
|
||||
// wxAnimationDecoder pure virtual
|
||||
virtual bool DoCanRead( wxInputStream& stream ) const;
|
||||
// modifies current stream position (see wxAnimationDecoder::CanRead)
|
||||
|
||||
int getcode(wxInputStream& stream, int bits, int abfin);
|
||||
wxGIFErrorCode dgif(wxInputStream& stream,
|
||||
GIFImage *img, int interl, int bits);
|
||||
|
||||
|
||||
// array of all frames
|
||||
wxArrayPtrVoid m_frames;
|
||||
|
||||
@@ -98,10 +106,6 @@ private:
|
||||
unsigned char m_buffer[256]; // buffer for reading
|
||||
unsigned char *m_bufp; // pointer to next byte in buffer
|
||||
|
||||
int getcode(wxInputStream& stream, int bits, int abfin);
|
||||
wxGIFErrorCode dgif(wxInputStream& stream,
|
||||
GIFImage *img, int interl, int bits);
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxGIFDecoder);
|
||||
};
|
||||
|
||||
|
@@ -89,8 +89,9 @@ public:
|
||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
|
||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
|
||||
virtual bool DoLoadFile( wxImage *image, wxInputStream& stream, bool verbose, int index );
|
||||
virtual int GetImageCount( wxInputStream& stream );
|
||||
|
||||
protected:
|
||||
virtual int DoGetImageCount( wxInputStream& stream );
|
||||
virtual bool DoCanRead( wxInputStream& stream );
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
@@ -145,8 +146,9 @@ public:
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose=true) ){return false ;}
|
||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
|
||||
virtual int GetImageCount( wxInputStream& stream );
|
||||
|
||||
protected:
|
||||
virtual int DoGetImageCount( wxInputStream& stream );
|
||||
virtual bool DoCanRead( wxInputStream& stream );
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
|
@@ -97,10 +97,17 @@ public:
|
||||
{ }
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
|
||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
|
||||
// NOTE: LoadFile and SaveFile are not pure virtuals to allow derived classes
|
||||
// to implement only one of the two
|
||||
virtual bool LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream),
|
||||
bool WXUNUSED(verbose)=true, int WXUNUSED(index)=-1 )
|
||||
{ return false; }
|
||||
virtual bool SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream),
|
||||
bool WXUNUSED(verbose)=true )
|
||||
{ return false; }
|
||||
|
||||
virtual int GetImageCount( wxInputStream& stream );
|
||||
int GetImageCount( wxInputStream& stream );
|
||||
// save the stream position, call DoGetImageCount() and restore the position
|
||||
|
||||
bool CanRead( wxInputStream& stream ) { return CallDoCanRead(stream); }
|
||||
bool CanRead( const wxString& name );
|
||||
@@ -125,6 +132,13 @@ public:
|
||||
|
||||
protected:
|
||||
#if wxUSE_STREAMS
|
||||
// NOTE: this function is allowed to change the current stream position
|
||||
// since GetImageCount() will take care of restoring it later
|
||||
virtual int DoGetImageCount( wxInputStream& WXUNUSED(stream) )
|
||||
{ return 1; } // default return value is 1 image
|
||||
|
||||
// NOTE: this function is allowed to change the current stream position
|
||||
// since CallDoCanRead() will take care of restoring it later
|
||||
virtual bool DoCanRead( wxInputStream& stream ) = 0;
|
||||
|
||||
// save the stream position, call DoCanRead() and restore the position
|
||||
|
@@ -35,8 +35,9 @@ public:
|
||||
bool verbose = true, int index = -1);
|
||||
virtual bool SaveFile(wxImage *image, wxOutputStream& stream,
|
||||
bool verbose=true);
|
||||
virtual int GetImageCount(wxInputStream& stream);
|
||||
|
||||
protected:
|
||||
virtual int DoGetImageCount(wxInputStream& stream);
|
||||
virtual bool DoCanRead(wxInputStream& stream);
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
|
@@ -34,8 +34,9 @@ public:
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
|
||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
|
||||
virtual int GetImageCount( wxInputStream& stream );
|
||||
|
||||
protected:
|
||||
virtual int DoGetImageCount( wxInputStream& stream );
|
||||
virtual bool DoCanRead( wxInputStream& stream );
|
||||
#endif
|
||||
|
||||
|
@@ -30,15 +30,20 @@ public:
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
// Is the stream XPM file?
|
||||
// NOTE: this function modifies the current stream position
|
||||
bool CanRead(wxInputStream& stream);
|
||||
|
||||
// Read XPM file from the stream, parse it and create image from it
|
||||
wxImage ReadFile(wxInputStream& stream);
|
||||
#endif
|
||||
|
||||
// Read directly from XPM data (as passed to wxBitmap ctor):
|
||||
wxImage ReadData(const char* const* xpm_data);
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
// needed for Borland 5.5
|
||||
wxImage ReadData(char** xpm_data) { return ReadData(const_cast<const char* const*>(xpm_data)); }
|
||||
wxImage ReadData(char** xpm_data)
|
||||
{ return ReadData(const_cast<const char* const*>(xpm_data)); }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user