]> git.saurik.com Git - wxWidgets.git/blob - src/common/imaggif.cpp
small changes here and there
[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 /*
11 We don't put pragma implement in this file because it is already present in
12 src/common/image.cpp
13 */
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include <wx/wxprec.h>
17
18 #ifdef __BORLANDC__
19 # pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 # include "wx/defs.h"
24 #endif
25
26 #if wxUSE_STREAMS && wxUSE_GIF
27
28 #include "wx/image.h"
29 #include "wx/gifdecod.h"
30 #include "wx/wfstream.h"
31 #include "wx/log.h"
32
33 #if !USE_SHARED_LIBRARIES
34 IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
35 #endif
36
37 //-----------------------------------------------------------------------------
38 // wxGIFHandler
39 //-----------------------------------------------------------------------------
40
41 bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose )
42 {
43 wxGIFDecoder *decod;
44 int error;
45 bool ok;
46
47 decod = new wxGIFDecoder(&stream, TRUE);
48
49 if ((error = decod->ReadGIF()) != E_OK)
50 {
51 if (verbose)
52 {
53 switch (error)
54 {
55 case E_FORMATO: wxLogError(_T("wxGIFHandler: error in image format")); break;
56 case E_MEMORIA: wxLogError(_T("wxGIFHandler: couldn't allocate memory")); break;
57 default: wxLogError(_T("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(_T("wxGIFHandler is read-only!!"));
76
77 return FALSE;
78 }
79
80 bool wxGIFHandler::CanRead( 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 && wxUSE_GIF