Added IFF handler.
[wxWidgets.git] / src / common / imagiff.cpp
1 //
2 // imgiff.cc - image handler for Amiga IFF images
3 // parts of the source taken by xv source code.
4 //
5 // (c) Steffen Gutmann, 2002
6 //
7 // Creation date: 08.01.2002
8 // Last modified: 08.01.2002
9 //
10
11 #ifdef __GNUG__
12 #pragma implementation "imagiff.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 # pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 # include "wx/defs.h"
24 #endif
25
26 #include "wx/imagiff.h"
27 #include "wx/iffdecod.h"
28 #include "wx/wfstream.h"
29 #include "wx/log.h"
30 #include "wx/intl.h"
31
32 #if wxUSE_IMAGE && wxUSE_IFF
33
34 IMPLEMENT_DYNAMIC_CLASS(wxIFFHandler, wxImageHandler)
35
36 //-----------------------------------------------------------------------------
37 // wxIFFHandler
38 //-----------------------------------------------------------------------------
39
40 #if wxUSE_STREAMS
41
42 bool wxIFFHandler::LoadFile(wxImage *image, wxInputStream& stream,
43 bool verbose, int WXUNUSED(index))
44 {
45 wxIFFDecoder *decod;
46 int error;
47 bool ok;
48
49 decod = new wxIFFDecoder(&stream);
50 error = decod->ReadIFF();
51
52 if ((error != wxIFF_OK) && (error != wxIFF_TRUNCATED))
53 {
54 if (verbose)
55 {
56 switch (error)
57 {
58 case wxIFF_INVFORMAT:
59 wxLogError(_("IFF: error in IFF image format."));
60 break;
61 case wxIFF_MEMERR:
62 wxLogError(_("IFF: not enough memory."));
63 break;
64 default:
65 wxLogError(_("IFF: unknown error!!!"));
66 break;
67 }
68 }
69 delete decod;
70 return FALSE;
71 }
72
73 if ((error == wxIFF_TRUNCATED) && verbose)
74 {
75 wxLogError(_("IFF: data stream seems to be truncated."));
76 /* go on; image data is OK */
77 }
78
79 ok = decod->ConvertToImage(image);
80 delete decod;
81
82 return ok;
83 }
84
85 bool wxIFFHandler::SaveFile(wxImage * WXUNUSED(image),
86 wxOutputStream& WXUNUSED(stream), bool verbose)
87 {
88 if (verbose)
89 wxLogDebug(wxT("IFF: the handler is read-only!!"));
90
91 return FALSE;
92 }
93
94 bool wxIFFHandler::DoCanRead(wxInputStream& stream)
95 {
96 wxIFFDecoder *decod;
97 bool ok;
98
99 decod = new wxIFFDecoder(&stream);
100 ok = decod->CanRead();
101 delete decod;
102
103 return ok;
104 }
105
106 #endif
107 #endif
108