]> git.saurik.com Git - wxWidgets.git/blame - src/common/imaggif.cpp
Applied patch [ 733425 ] Fix for header rendering problem in CalCtrl
[wxWidgets.git] / src / common / imaggif.cpp
CommitLineData
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
b59bf2db
JS
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
8f493002
VS
10#ifdef __GNUG__
11#pragma implementation "imaggif.h"
12#endif
b59bf2db
JS
13
14// For compilers that support precompilation, includes "wx.h".
3096bd2f 15#include "wx/wxprec.h"
b59bf2db
JS
16
17#ifdef __BORLANDC__
464122b6 18# pragma hdrstop
b59bf2db
JS
19#endif
20
ce4169a4 21#ifndef WX_PRECOMP
464122b6 22# include "wx/defs.h"
ce4169a4 23#endif
b59bf2db 24
c96ea657 25#if wxUSE_IMAGE && wxUSE_GIF
8a68d8b6 26
8f493002 27#include "wx/imaggif.h"
464122b6 28#include "wx/gifdecod.h"
ce4169a4 29#include "wx/wfstream.h"
ce4169a4 30#include "wx/log.h"
f6b77239 31#include "wx/intl.h"
b59bf2db 32
ce4169a4
RR
33IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
34
b59bf2db
JS
35//-----------------------------------------------------------------------------
36// wxGIFHandler
37//-----------------------------------------------------------------------------
38
9ab6ee85
GRG
39#if wxUSE_STREAMS
40
b931f7ee
VS
41bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
42 bool verbose, int index)
b59bf2db 43{
464122b6 44 wxGIFDecoder *decod;
e08e239b 45 int error;
b931f7ee 46 bool ok = TRUE;
b59bf2db 47
0141d2c9 48// image->Destroy();
464122b6 49 decod = new wxGIFDecoder(&stream, TRUE);
8141573c 50 error = decod->ReadGIF();
8a68d8b6 51
8141573c 52 if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
995612e2 53 {
e08e239b
GRG
54 if (verbose)
55 {
56 switch (error)
57 {
8141573c 58 case wxGIF_INVFORMAT:
add95ac3 59 wxLogError(_("GIF: error in GIF image format."));
8141573c
GRG
60 break;
61 case wxGIF_MEMERR:
add95ac3 62 wxLogError(_("GIF: not enough memory."));
8141573c
GRG
63 break;
64 default:
add95ac3 65 wxLogError(_("GIF: unknown error!!!"));
8141573c 66 break;
e08e239b
GRG
67 }
68 }
b59bf2db
JS
69 delete decod;
70 return FALSE;
71 }
b59bf2db 72
8141573c
GRG
73 if ((error == wxGIF_TRUNCATED) && verbose)
74 {
add95ac3 75 wxLogError(_("GIF: data stream seems to be truncated."));
8141573c
GRG
76 /* go on; image data is OK */
77 }
78
b931f7ee
VS
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
464122b6 103 delete decod;
0141d2c9 104
464122b6 105 return ok;
b59bf2db
JS
106}
107
74e3313b 108bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
deb2fec0 109 wxOutputStream& WXUNUSED(stream), bool verbose )
b59bf2db 110{
8a68d8b6 111 if (verbose)
add95ac3 112 wxLogDebug(wxT("GIF: the handler is read-only!!"));
8a68d8b6 113
b59bf2db
JS
114 return FALSE;
115}
116
995612e2 117bool wxGIFHandler::DoCanRead( wxInputStream& stream )
0828c087 118{
39d16996
VZ
119 wxGIFDecoder decod(&stream);
120 return decod.CanRead();
0828c087
VS
121}
122
9ab6ee85
GRG
123#endif // wxUSE_STREAMS
124
125#endif // wxUSE_GIF