]> git.saurik.com Git - wxWidgets.git/blame - src/common/imaggif.cpp
Include wx/stream.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / common / imaggif.cpp
CommitLineData
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
28IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
29
b59bf2db
JS
30//-----------------------------------------------------------------------------
31// wxGIFHandler
32//-----------------------------------------------------------------------------
33
9ab6ee85
GRG
34#if wxUSE_STREAMS
35
b931f7ee
VS
36bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
37 bool verbose, int index)
b59bf2db 38{
464122b6 39 wxGIFDecoder *decod;
e08e239b 40 int error;
7beb59f3 41 bool ok = true;
b59bf2db 42
0141d2c9 43// image->Destroy();
7beb59f3 44 decod = new wxGIFDecoder(&stream, true);
8141573c 45 error = decod->ReadGIF();
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 (index != -1)
75 {
76 // We're already on index = 0 by default. So no need
77 // to call GoFrame(0) then. On top of that GoFrame doesn't
78 // accept an index of 0. (Instead GoFirstFrame() should be used)
79 // Also if the gif image has only one frame, calling GoFrame(0)
80 // fails because GoFrame() only works with gif animations.
7beb59f3 81 // (It fails if IsAnimation() returns false)
b931f7ee
VS
82 // All valid reasons to NOT call GoFrame when index equals 0.
83 if (index != 0)
84 {
85 ok = decod->GoFrame(index);
86 }
87 }
88
89 if (ok)
90 {
91 ok = decod->ConvertToImage(image);
92 }
93 else
94 {
95 wxLogError(_("GIF: Invalid gif index."));
96 }
97
464122b6 98 delete decod;
0141d2c9 99
464122b6 100 return ok;
b59bf2db
JS
101}
102
74e3313b 103bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
deb2fec0 104 wxOutputStream& WXUNUSED(stream), bool verbose )
b59bf2db 105{
8a68d8b6 106 if (verbose)
add95ac3 107 wxLogDebug(wxT("GIF: the handler is read-only!!"));
8a68d8b6 108
7beb59f3 109 return false;
b59bf2db
JS
110}
111
995612e2 112bool wxGIFHandler::DoCanRead( wxInputStream& stream )
0828c087 113{
39d16996
VZ
114 wxGIFDecoder decod(&stream);
115 return decod.CanRead();
0828c087
VS
116}
117
9ab6ee85
GRG
118#endif // wxUSE_STREAMS
119
120#endif // wxUSE_GIF