]> git.saurik.com Git - wxWidgets.git/blob - src/common/imaggif.cpp
post wxUniv merge fixes
[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_IMAGE && 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 // image->Destroy();
48 decod = new wxGIFDecoder(&stream, TRUE);
49 error = decod->ReadGIF();
50
51 if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
52 {
53 if (verbose)
54 {
55 switch (error)
56 {
57 case wxGIF_INVFORMAT:
58 wxLogError(_("GIF: error in GIF image format."));
59 break;
60 case wxGIF_MEMERR:
61 wxLogError(_("GIF: not enough memory."));
62 break;
63 default:
64 wxLogError(_("GIF: unknown error!!!"));
65 break;
66 }
67 }
68 delete decod;
69 return FALSE;
70 }
71
72 if ((error == wxGIF_TRUNCATED) && verbose)
73 {
74 wxLogError(_("GIF: data stream seems to be truncated."));
75 /* go on; image data is OK */
76 }
77
78 ok = decod->ConvertToImage(image);
79 delete decod;
80
81 return ok;
82 }
83
84 bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
85 wxOutputStream& WXUNUSED(stream), bool verbose )
86 {
87 if (verbose)
88 wxLogDebug(wxT("GIF: the handler is read-only!!"));
89
90 return FALSE;
91 }
92
93 bool wxGIFHandler::DoCanRead( wxInputStream& stream )
94 {
95 wxGIFDecoder *decod;
96 bool ok;
97
98 decod = new wxGIFDecoder(&stream);
99 ok = decod->CanRead();
100 delete decod;
101
102 return ok;
103 }
104
105 #endif // wxUSE_STREAMS
106
107 #endif // wxUSE_GIF