]>
Commit | Line | Data |
---|---|---|
b59bf2db JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: imaggif.cpp | |
3 | // Purpose: wxGIFHandler | |
8a68d8b6 | 4 | // Author: Vaclav Slavik & Guillermo Rodriguez Garcia |
464122b6 | 5 | // RCS-ID: $Id$ |
e08e239b | 6 | // Copyright: (c) 1999 Vaclav Slavik & Guillermo Rodriguez Garcia |
65571936 | 7 | // Licence: wxWindows licence |
b59bf2db JS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
b59bf2db | 10 | // For compilers that support precompilation, includes "wx.h". |
3096bd2f | 11 | #include "wx/wxprec.h" |
b59bf2db JS |
12 | |
13 | #ifdef __BORLANDC__ | |
464122b6 | 14 | # pragma hdrstop |
b59bf2db JS |
15 | #endif |
16 | ||
ce4169a4 | 17 | #ifndef WX_PRECOMP |
464122b6 | 18 | # include "wx/defs.h" |
ce4169a4 | 19 | #endif |
b59bf2db | 20 | |
c96ea657 | 21 | #if wxUSE_IMAGE && wxUSE_GIF |
8a68d8b6 | 22 | |
8f493002 | 23 | #include "wx/imaggif.h" |
464122b6 | 24 | #include "wx/gifdecod.h" |
ce4169a4 | 25 | #include "wx/wfstream.h" |
ce4169a4 | 26 | #include "wx/log.h" |
f6b77239 | 27 | #include "wx/intl.h" |
b59bf2db | 28 | |
ce4169a4 RR |
29 | IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler) |
30 | ||
b59bf2db JS |
31 | //----------------------------------------------------------------------------- |
32 | // wxGIFHandler | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
9ab6ee85 GRG |
35 | #if wxUSE_STREAMS |
36 | ||
b931f7ee VS |
37 | bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream, |
38 | bool verbose, int index) | |
b59bf2db | 39 | { |
464122b6 | 40 | wxGIFDecoder *decod; |
e08e239b | 41 | int error; |
7beb59f3 | 42 | bool ok = true; |
b59bf2db | 43 | |
0141d2c9 | 44 | // image->Destroy(); |
7beb59f3 | 45 | decod = new wxGIFDecoder(&stream, true); |
8141573c | 46 | error = decod->ReadGIF(); |
8a68d8b6 | 47 | |
8141573c | 48 | if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED)) |
995612e2 | 49 | { |
e08e239b GRG |
50 | if (verbose) |
51 | { | |
52 | switch (error) | |
53 | { | |
8141573c | 54 | case wxGIF_INVFORMAT: |
add95ac3 | 55 | wxLogError(_("GIF: error in GIF image format.")); |
8141573c GRG |
56 | break; |
57 | case wxGIF_MEMERR: | |
add95ac3 | 58 | wxLogError(_("GIF: not enough memory.")); |
8141573c GRG |
59 | break; |
60 | default: | |
add95ac3 | 61 | wxLogError(_("GIF: unknown error!!!")); |
8141573c | 62 | break; |
e08e239b GRG |
63 | } |
64 | } | |
b59bf2db | 65 | delete decod; |
7beb59f3 | 66 | return false; |
b59bf2db | 67 | } |
b59bf2db | 68 | |
8141573c GRG |
69 | if ((error == wxGIF_TRUNCATED) && verbose) |
70 | { | |
add95ac3 | 71 | wxLogError(_("GIF: data stream seems to be truncated.")); |
8141573c GRG |
72 | /* go on; image data is OK */ |
73 | } | |
74 | ||
b931f7ee VS |
75 | if (index != -1) |
76 | { | |
77 | // We're already on index = 0 by default. So no need | |
78 | // to call GoFrame(0) then. On top of that GoFrame doesn't | |
79 | // accept an index of 0. (Instead GoFirstFrame() should be used) | |
80 | // Also if the gif image has only one frame, calling GoFrame(0) | |
81 | // fails because GoFrame() only works with gif animations. | |
7beb59f3 | 82 | // (It fails if IsAnimation() returns false) |
b931f7ee VS |
83 | // All valid reasons to NOT call GoFrame when index equals 0. |
84 | if (index != 0) | |
85 | { | |
86 | ok = decod->GoFrame(index); | |
87 | } | |
88 | } | |
89 | ||
90 | if (ok) | |
91 | { | |
92 | ok = decod->ConvertToImage(image); | |
93 | } | |
94 | else | |
95 | { | |
96 | wxLogError(_("GIF: Invalid gif index.")); | |
97 | } | |
98 | ||
464122b6 | 99 | delete decod; |
0141d2c9 | 100 | |
464122b6 | 101 | return ok; |
b59bf2db JS |
102 | } |
103 | ||
74e3313b | 104 | bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image), |
deb2fec0 | 105 | wxOutputStream& WXUNUSED(stream), bool verbose ) |
b59bf2db | 106 | { |
8a68d8b6 | 107 | if (verbose) |
add95ac3 | 108 | wxLogDebug(wxT("GIF: the handler is read-only!!")); |
8a68d8b6 | 109 | |
7beb59f3 | 110 | return false; |
b59bf2db JS |
111 | } |
112 | ||
995612e2 | 113 | bool wxGIFHandler::DoCanRead( wxInputStream& stream ) |
0828c087 | 114 | { |
39d16996 VZ |
115 | wxGIFDecoder decod(&stream); |
116 | return decod.CanRead(); | |
0828c087 VS |
117 | } |
118 | ||
9ab6ee85 GRG |
119 | #endif // wxUSE_STREAMS |
120 | ||
121 | #endif // wxUSE_GIF |