]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "imaggif.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
25 #if wxUSE_IMAGE && wxUSE_GIF
27 #include "wx/imaggif.h"
28 #include "wx/gifdecod.h"
29 #include "wx/wfstream.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler
,wxImageHandler
)
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
41 bool wxGIFHandler::LoadFile(wxImage
*image
, wxInputStream
& stream
,
42 bool verbose
, int index
)
49 decod
= new wxGIFDecoder(&stream
, TRUE
);
50 error
= decod
->ReadGIF();
52 if ((error
!= wxGIF_OK
) && (error
!= wxGIF_TRUNCATED
))
59 wxLogError(_("GIF: error in GIF image format."));
62 wxLogError(_("GIF: not enough memory."));
65 wxLogError(_("GIF: unknown error!!!"));
73 if ((error
== wxGIF_TRUNCATED
) && verbose
)
75 wxLogError(_("GIF: data stream seems to be truncated."));
76 /* go on; image data is OK */
81 // We're already on index = 0 by default. So no need
82 // to call GoFrame(0) then. On top of that GoFrame doesn't
83 // accept an index of 0. (Instead GoFirstFrame() should be used)
84 // Also if the gif image has only one frame, calling GoFrame(0)
85 // fails because GoFrame() only works with gif animations.
86 // (It fails if IsAnimation() returns FALSE)
87 // All valid reasons to NOT call GoFrame when index equals 0.
90 ok
= decod
->GoFrame(index
);
96 ok
= decod
->ConvertToImage(image
);
100 wxLogError(_("GIF: Invalid gif index."));
108 bool wxGIFHandler::SaveFile( wxImage
* WXUNUSED(image
),
109 wxOutputStream
& WXUNUSED(stream
), bool verbose
)
112 wxLogDebug(wxT("GIF: the handler is read-only!!"));
117 bool wxGIFHandler::DoCanRead( wxInputStream
& stream
)
119 wxGIFDecoder
decod(&stream
);
120 return decod
.CanRead();
123 #endif // wxUSE_STREAMS