]> git.saurik.com Git - wxWidgets.git/blob - src/common/imaggif.cpp
include "module.h"
[wxWidgets.git] / src / common / imaggif.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: imaggif.cpp
3 // Purpose: wxGIFHandler
4 // Author: Vaclav Slavik & Guillermo Rodriguez Garcia
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik & Guillermo Rodriguez Garcia
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "imaggif.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 # pragma hdrstop
19 #endif
20
21 #ifndef WX_PRECOMP
22 # include "wx/defs.h"
23 #endif
24
25 #if wxUSE_GIF
26
27 #include "wx/imaggif.h"
28 #include "wx/gifdecod.h"
29 #include "wx/wfstream.h"
30 #include "wx/log.h"
31 #include "wx/intl.h"
32
33 IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
34
35 //-----------------------------------------------------------------------------
36 // wxGIFHandler
37 //-----------------------------------------------------------------------------
38
39 #if wxUSE_STREAMS
40
41 bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
42 {
43 wxGIFDecoder *decod;
44 int error;
45 bool ok;
46
47 decod = new wxGIFDecoder(&stream, TRUE);
48
49 if ((error = decod->ReadGIF()) != wxGIF_OK)
50 {
51 if (verbose)
52 {
53 switch (error)
54 {
55 case wxGIF_INVFORMAT: wxLogError(_("wxGIFHandler: error in GIF image format")); break;
56 case wxGIF_MEMERR: wxLogError(_("wxGIFHandler: couldn't allocate enough memory")); break;
57 default: wxLogError(_("wxGIFHandler: unknown error !!!"));
58 }
59 }
60 delete decod;
61 return FALSE;
62 }
63
64 image->Destroy();
65 ok = decod->ConvertToImage(image);
66
67 delete decod;
68 return ok;
69 }
70
71 bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
72 wxOutputStream& WXUNUSED(stream), bool verbose )
73 {
74 if (verbose)
75 wxLogDebug(wxT("wxGIFHandler is read-only!!"));
76
77 return FALSE;
78 }
79
80 bool wxGIFHandler::DoCanRead( wxInputStream& stream )
81 {
82 wxGIFDecoder *decod;
83 bool ok;
84
85 decod = new wxGIFDecoder(&stream);
86 ok = decod->CanRead();
87
88 delete decod;
89 return ok;
90 }
91
92 #endif // wxUSE_STREAMS
93
94 #endif // wxUSE_GIF