]> git.saurik.com Git - wxWidgets.git/blob - src/common/imaggif.cpp
started for unicode text control, in case we will not be able to get the MLTE EchoMod...
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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,
42 bool verbose, int index)
43 {
44 wxGIFDecoder *decod;
45 int error;
46 bool ok = TRUE;
47
48 // image->Destroy();
49 decod = new wxGIFDecoder(&stream, TRUE);
50 error = decod->ReadGIF();
51
52 if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
53 {
54 if (verbose)
55 {
56 switch (error)
57 {
58 case wxGIF_INVFORMAT:
59 wxLogError(_("GIF: error in GIF image format."));
60 break;
61 case wxGIF_MEMERR:
62 wxLogError(_("GIF: not enough memory."));
63 break;
64 default:
65 wxLogError(_("GIF: unknown error!!!"));
66 break;
67 }
68 }
69 delete decod;
70 return FALSE;
71 }
72
73 if ((error == wxGIF_TRUNCATED) && verbose)
74 {
75 wxLogError(_("GIF: data stream seems to be truncated."));
76 /* go on; image data is OK */
77 }
78
79 if (index != -1)
80 {
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.
88 if (index != 0)
89 {
90 ok = decod->GoFrame(index);
91 }
92 }
93
94 if (ok)
95 {
96 ok = decod->ConvertToImage(image);
97 }
98 else
99 {
100 wxLogError(_("GIF: Invalid gif index."));
101 }
102
103 delete decod;
104
105 return ok;
106 }
107
108 bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
109 wxOutputStream& WXUNUSED(stream), bool verbose )
110 {
111 if (verbose)
112 wxLogDebug(wxT("GIF: the handler is read-only!!"));
113
114 return FALSE;
115 }
116
117 bool wxGIFHandler::DoCanRead( wxInputStream& stream )
118 {
119 wxGIFDecoder decod(&stream);
120 return decod.CanRead();
121 }
122
123 #endif // wxUSE_STREAMS
124
125 #endif // wxUSE_GIF