]>
Commit | Line | Data |
---|---|---|
b59bf2db | 1 | ///////////////////////////////////////////////////////////////////////////// |
8898456d | 2 | // Name: src/common/imaggif.cpp |
b59bf2db | 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__ | |
8898456d | 14 | #pragma hdrstop |
b59bf2db JS |
15 | #endif |
16 | ||
8898456d WS |
17 | #if wxUSE_IMAGE && wxUSE_GIF |
18 | ||
ce4169a4 | 19 | #ifndef WX_PRECOMP |
8898456d WS |
20 | #include "wx/intl.h" |
21 | #include "wx/log.h" | |
ce4169a4 | 22 | #endif |
b59bf2db | 23 | |
8f493002 | 24 | #include "wx/imaggif.h" |
464122b6 | 25 | #include "wx/gifdecod.h" |
ce4169a4 | 26 | #include "wx/wfstream.h" |
b59bf2db | 27 | |
ce4169a4 RR |
28 | IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler) |
29 | ||
b59bf2db JS |
30 | //----------------------------------------------------------------------------- |
31 | // wxGIFHandler | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
9ab6ee85 GRG |
34 | #if wxUSE_STREAMS |
35 | ||
b931f7ee VS |
36 | bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream, |
37 | bool verbose, int index) | |
b59bf2db | 38 | { |
464122b6 | 39 | wxGIFDecoder *decod; |
72045d57 | 40 | wxGIFErrorCode error; |
7beb59f3 | 41 | bool ok = true; |
b59bf2db | 42 | |
0141d2c9 | 43 | // image->Destroy(); |
72045d57 VZ |
44 | decod = new wxGIFDecoder(); |
45 | error = decod->LoadGIF(stream); | |
8a68d8b6 | 46 | |
8141573c | 47 | if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED)) |
995612e2 | 48 | { |
e08e239b GRG |
49 | if (verbose) |
50 | { | |
51 | switch (error) | |
52 | { | |
8141573c | 53 | case wxGIF_INVFORMAT: |
add95ac3 | 54 | wxLogError(_("GIF: error in GIF image format.")); |
8141573c GRG |
55 | break; |
56 | case wxGIF_MEMERR: | |
add95ac3 | 57 | wxLogError(_("GIF: not enough memory.")); |
8141573c GRG |
58 | break; |
59 | default: | |
add95ac3 | 60 | wxLogError(_("GIF: unknown error!!!")); |
8141573c | 61 | break; |
e08e239b GRG |
62 | } |
63 | } | |
b59bf2db | 64 | delete decod; |
7beb59f3 | 65 | return false; |
b59bf2db | 66 | } |
b59bf2db | 67 | |
8141573c GRG |
68 | if ((error == wxGIF_TRUNCATED) && verbose) |
69 | { | |
add95ac3 | 70 | wxLogError(_("GIF: data stream seems to be truncated.")); |
8141573c GRG |
71 | /* go on; image data is OK */ |
72 | } | |
73 | ||
b931f7ee VS |
74 | if (ok) |
75 | { | |
72045d57 | 76 | ok = decod->ConvertToImage(index != -1 ? (size_t)index : 0, image); |
b931f7ee VS |
77 | } |
78 | else | |
79 | { | |
80 | wxLogError(_("GIF: Invalid gif index.")); | |
81 | } | |
82 | ||
464122b6 | 83 | delete decod; |
0141d2c9 | 84 | |
464122b6 | 85 | return ok; |
b59bf2db JS |
86 | } |
87 | ||
74e3313b | 88 | bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image), |
deb2fec0 | 89 | wxOutputStream& WXUNUSED(stream), bool verbose ) |
b59bf2db | 90 | { |
8a68d8b6 | 91 | if (verbose) |
af588446 | 92 | { |
add95ac3 | 93 | wxLogDebug(wxT("GIF: the handler is read-only!!")); |
af588446 | 94 | } |
8a68d8b6 | 95 | |
7beb59f3 | 96 | return false; |
b59bf2db JS |
97 | } |
98 | ||
995612e2 | 99 | bool wxGIFHandler::DoCanRead( wxInputStream& stream ) |
0828c087 | 100 | { |
72045d57 VZ |
101 | wxGIFDecoder decod; |
102 | return decod.CanRead(stream); | |
8faef7cc | 103 | // it's ok to modify the stream position here |
0828c087 VS |
104 | } |
105 | ||
8faef7cc | 106 | int wxGIFHandler::DoGetImageCount( wxInputStream& stream ) |
85fcb94f VZ |
107 | { |
108 | wxGIFDecoder decod; | |
109 | wxGIFErrorCode error = decod.LoadGIF(stream); | |
110 | if ( (error != wxGIF_OK) && (error != wxGIF_TRUNCATED) ) | |
111 | return -1; | |
03647350 | 112 | |
8faef7cc FM |
113 | // NOTE: this function modifies the current stream position but it's ok |
114 | // (see wxImageHandler::GetImageCount) | |
85fcb94f VZ |
115 | |
116 | return decod.GetFrameCount(); | |
117 | } | |
118 | ||
9ab6ee85 GRG |
119 | #endif // wxUSE_STREAMS |
120 | ||
121 | #endif // wxUSE_GIF |