implement GetImageCount() for GIF handler (closes #10663); added test for it to the sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -519,6 +519,7 @@ All (GUI):
|
|||||||
- Check whether document fits into page horizontally in wxHtmlPrintout, see the
|
- Check whether document fits into page horizontally in wxHtmlPrintout, see the
|
||||||
new CheckFit() method for more information.
|
new CheckFit() method for more information.
|
||||||
- Allow reading GIFs with incorrectly specified animation size.
|
- Allow reading GIFs with incorrectly specified animation size.
|
||||||
|
- Return number of frames in animated GIF from wxGIFHandler::GetImageCount().
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: imaggif.h
|
// Name: wx/imaggif.h
|
||||||
// Purpose: wxImage GIF handler
|
// Purpose: wxImage GIF handler
|
||||||
// Author: Vaclav Slavik & Guillermo Rodriguez Garcia
|
// Author: Vaclav Slavik & Guillermo Rodriguez Garcia
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
@@ -31,18 +31,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
|
virtual bool LoadFile(wxImage *image, wxInputStream& stream,
|
||||||
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
|
bool verbose = true, int index = -1);
|
||||||
|
virtual bool SaveFile(wxImage *image, wxOutputStream& stream,
|
||||||
|
bool verbose=true);
|
||||||
|
virtual int GetImageCount(wxInputStream& stream);
|
||||||
protected:
|
protected:
|
||||||
virtual bool DoCanRead( wxInputStream& stream );
|
virtual bool DoCanRead(wxInputStream& stream);
|
||||||
#endif
|
#endif // wxUSE_STREAMS
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxGIFHandler)
|
DECLARE_DYNAMIC_CLASS(wxGIFHandler)
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // wxUSE_GIF
|
||||||
|
|
||||||
#endif
|
#endif // _WX_IMAGGIF_H_
|
||||||
// _WX_IMAGGIF_H_
|
|
||||||
|
|
||||||
|
@@ -109,7 +109,9 @@ public:
|
|||||||
Currently, the stream must support seeking.
|
Currently, the stream must support seeking.
|
||||||
|
|
||||||
@return Number of available images. For most image handlers, this is 1
|
@return Number of available images. For most image handlers, this is 1
|
||||||
(exceptions are TIFF and ICO formats).
|
(exceptions are TIFF and ICO formats as well as animated GIFs
|
||||||
|
for which this function returns the number of frames in the
|
||||||
|
animation).
|
||||||
*/
|
*/
|
||||||
virtual int GetImageCount(wxInputStream& stream);
|
virtual int GetImageCount(wxInputStream& stream);
|
||||||
|
|
||||||
@@ -1603,7 +1605,9 @@ public:
|
|||||||
@li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
|
@li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
|
||||||
|
|
||||||
@return Number of available images. For most image handlers, this is 1
|
@return Number of available images. For most image handlers, this is 1
|
||||||
(exceptions are TIFF and ICO formats).
|
(exceptions are TIFF and ICO formats as well as animated GIFs
|
||||||
|
for which this function returns the number of frames in the
|
||||||
|
animation).
|
||||||
*/
|
*/
|
||||||
static int GetImageCount(const wxString& filename,
|
static int GetImageCount(const wxString& filename,
|
||||||
wxBitmapType type = wxBITMAP_TYPE_ANY);
|
wxBitmapType type = wxBITMAP_TYPE_ANY);
|
||||||
|
@@ -117,13 +117,29 @@ enum
|
|||||||
class MyImageFrame : public wxFrame
|
class MyImageFrame : public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyImageFrame(wxFrame *parent, const wxString& desc, const wxBitmap& bitmap)
|
MyImageFrame(wxFrame *parent, const wxString& desc, const wxImage& image)
|
||||||
: wxFrame(parent, wxID_ANY,
|
|
||||||
wxString::Format(_T("Image from %s"), desc.c_str()),
|
|
||||||
wxDefaultPosition, wxDefaultSize,
|
|
||||||
wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE),
|
|
||||||
m_bitmap(bitmap)
|
|
||||||
{
|
{
|
||||||
|
Create(parent, desc, wxBitmap(image), image.GetImageCount(desc));
|
||||||
|
}
|
||||||
|
|
||||||
|
MyImageFrame(wxFrame *parent, const wxString& desc, const wxBitmap& bitmap)
|
||||||
|
{
|
||||||
|
Create(parent, desc, bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Create(wxFrame *parent,
|
||||||
|
const wxString& desc,
|
||||||
|
const wxBitmap& bitmap,
|
||||||
|
int numImages = 1)
|
||||||
|
{
|
||||||
|
if ( !wxFrame::Create(parent, wxID_ANY,
|
||||||
|
wxString::Format(_T("Image from %s"), desc),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_bitmap = bitmap;
|
||||||
|
|
||||||
wxMenu *menu = new wxMenu;
|
wxMenu *menu = new wxMenu;
|
||||||
menu->Append(wxID_SAVE);
|
menu->Append(wxID_SAVE);
|
||||||
menu->AppendSeparator();
|
menu->AppendSeparator();
|
||||||
@@ -138,13 +154,17 @@ public:
|
|||||||
mbar->Append(menu, _T("&Image"));
|
mbar->Append(menu, _T("&Image"));
|
||||||
SetMenuBar(mbar);
|
SetMenuBar(mbar);
|
||||||
|
|
||||||
CreateStatusBar();
|
CreateStatusBar(2);
|
||||||
|
if ( numImages != 1 )
|
||||||
|
SetStatusText(wxString::Format("%d images", numImages), 1);
|
||||||
|
|
||||||
SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
|
SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
|
||||||
|
|
||||||
UpdateStatusBar();
|
UpdateStatusBar();
|
||||||
|
|
||||||
// SetBackgroundColour(*wxWHITE);
|
Show();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEraseBackground(wxEraseEvent& WXUNUSED(event))
|
void OnEraseBackground(wxEraseEvent& WXUNUSED(event))
|
||||||
@@ -656,7 +676,7 @@ void MyFrame::OnNewFrame( wxCommandEvent &WXUNUSED(event) )
|
|||||||
wxImage image;
|
wxImage image;
|
||||||
wxString filename = LoadUserImage(image);
|
wxString filename = LoadUserImage(image);
|
||||||
if ( !filename.empty() )
|
if ( !filename.empty() )
|
||||||
(new MyImageFrame(this, filename, wxBitmap(image)))->Show();
|
new MyImageFrame(this, filename, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnImageInfo( wxCommandEvent &WXUNUSED(event) )
|
void MyFrame::OnImageInfo( wxCommandEvent &WXUNUSED(event) )
|
||||||
@@ -735,7 +755,7 @@ void MyFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(new MyImageFrame(this, _T("Clipboard"), dobjBmp.GetBitmap()))->Show();
|
new MyImageFrame(this, _T("Clipboard"), dobjBmp.GetBitmap());
|
||||||
}
|
}
|
||||||
wxTheClipboard->Close();
|
wxTheClipboard->Close();
|
||||||
}
|
}
|
||||||
@@ -765,9 +785,7 @@ void MyFrame::OnThumbnail( wxCommandEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
const long loadTime = sw.Time();
|
const long loadTime = sw.Time();
|
||||||
|
|
||||||
MyImageFrame * const
|
MyImageFrame * const frame = new MyImageFrame(this, filename, image);
|
||||||
frame = new MyImageFrame(this, filename, wxBitmap(image));
|
|
||||||
frame->Show();
|
|
||||||
wxLogStatus(frame, "Loaded \"%s\" in %ldms", filename, loadTime);
|
wxLogStatus(frame, "Loaded \"%s\" in %ldms", filename, loadTime);
|
||||||
#else
|
#else
|
||||||
wxLogError( _T("Couldn't create file selector dialog") );
|
wxLogError( _T("Couldn't create file selector dialog") );
|
||||||
|
@@ -100,6 +100,16 @@ bool wxGIFHandler::DoCanRead( wxInputStream& stream )
|
|||||||
return decod.CanRead(stream);
|
return decod.CanRead(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxGIFHandler::GetImageCount( wxInputStream& stream )
|
||||||
|
{
|
||||||
|
wxGIFDecoder decod;
|
||||||
|
wxGIFErrorCode error = decod.LoadGIF(stream);
|
||||||
|
if ( (error != wxGIF_OK) && (error != wxGIF_TRUNCATED) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return decod.GetFrameCount();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_STREAMS
|
#endif // wxUSE_STREAMS
|
||||||
|
|
||||||
#endif // wxUSE_GIF
|
#endif // wxUSE_GIF
|
||||||
|
Reference in New Issue
Block a user