]>
git.saurik.com Git - wxWidgets.git/blob - src/common/imaggif.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGIFHandler
4 // Author: Vaclav Slavik & Guillermo Rodriguez Garcia
6 // Copyright: (c) 1999 Vaclav Slavik & Guillermo Rodriguez Garcia
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
21 #if wxUSE_IMAGE && wxUSE_GIF
23 #include "wx/imaggif.h"
24 #include "wx/gifdecod.h"
25 #include "wx/wfstream.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler
,wxImageHandler
)
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
37 bool wxGIFHandler::LoadFile(wxImage
*image
, wxInputStream
& stream
,
38 bool verbose
, int index
)
45 decod
= new wxGIFDecoder(&stream
, true);
46 error
= decod
->ReadGIF();
48 if ((error
!= wxGIF_OK
) && (error
!= wxGIF_TRUNCATED
))
55 wxLogError(_("GIF: error in GIF image format."));
58 wxLogError(_("GIF: not enough memory."));
61 wxLogError(_("GIF: unknown error!!!"));
69 if ((error
== wxGIF_TRUNCATED
) && verbose
)
71 wxLogError(_("GIF: data stream seems to be truncated."));
72 /* go on; image data is OK */
77 // We're already on index = 0 by default. So no need
78 // to call GoFrame(0) then. On top of that GoFrame doesn't
79 // accept an index of 0. (Instead GoFirstFrame() should be used)
80 // Also if the gif image has only one frame, calling GoFrame(0)
81 // fails because GoFrame() only works with gif animations.
82 // (It fails if IsAnimation() returns false)
83 // All valid reasons to NOT call GoFrame when index equals 0.
86 ok
= decod
->GoFrame(index
);
92 ok
= decod
->ConvertToImage(image
);
96 wxLogError(_("GIF: Invalid gif index."));
104 bool wxGIFHandler::SaveFile( wxImage
* WXUNUSED(image
),
105 wxOutputStream
& WXUNUSED(stream
), bool verbose
)
108 wxLogDebug(wxT("GIF: the handler is read-only!!"));
113 bool wxGIFHandler::DoCanRead( wxInputStream
& stream
)
115 wxGIFDecoder
decod(&stream
);
116 return decod
.CanRead();
119 #endif // wxUSE_STREAMS