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