1/*
2 Progressive image displaying library.
3
4 Copyright (C) 2004,2005 Maks Orlovich (maksim@kde.org)
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23*/
24
25#ifndef IMAGE_LOADER_H
26#define IMAGE_LOADER_H
27
28#include "imageformat.h"
29#include "image.h"
30
31namespace khtmlImLoad
32{
33
34class Image;
35
36/**
37 A base class for decoders. The decoders should inherit off this, and use the protected functions to
38 feed their images data
39*/
40class ImageLoader
41{
42protected:
43 Image *image;
44
45 ImageLoader()
46 {
47 image = nullptr;
48 }
49
50 /**
51 Call to declare canvas geometry and format. May only be called once
52 */
53 void notifyImageInfo(int width, int height)
54 {
55 image->notifyImageInfo(width, height);
56 }
57
58 /**
59 Call to declare frame geometry, should be called for each frame.
60 */
61 void notifyAppendFrame(int fwidth, int fheight, const ImageFormat &format)
62 {
63 image->notifyAppendFrame(fwidth, fheight, format);
64 }
65
66 /**
67 wrapper for the above method for single-frame images
68 */
69 void notifySingleFrameImage(int width, int height, const ImageFormat &format)
70 {
71 notifyImageInfo(width, height);
72 notifyAppendFrame(width, height, format);
73 }
74
75 /**
76 Call to provide a scanline, for active frame, and given "version".
77 The decoder must feed multiple versions of the image inside here, top-to-bottom,
78 and incrementing versions. When it's done, it should either feed the last
79 version with FinalVersionID, or call notifyFinished() separately.
80 */
81 void notifyScanline(unsigned char version, unsigned char *line)
82 {
83 image->notifyScanline(version, line);
84 }
85
86 void notifyQImage(unsigned char version, const QImage *qimage)
87 {
88 image->notifyQImage(version, qimage);
89 }
90
91 /**
92 Call this to exract the current state of a scanline to the provided bufer
93 */
94 void requestScanline(unsigned int lineNum, unsigned char *lineBuf)
95 {
96 image->requestScanline(lineNum, lineBuf);
97 }
98
99 /**
100 Call this to get the first frame
101 */
102 PixmapPlane *requestFrame0()
103 {
104 return image->getSize(image->size());
105 }
106
107public:
108 //Some constants. Not consts since some compilers are broken
109 enum {
110 DefaultFrame = 0,
111 FinalVersionID = 0xff
112 };
113
114 void setImage(Image *_image)
115 {
116 image = _image;
117 }
118
119 virtual ~ImageLoader()
120 {}
121
122 enum Status {
123 Done = -2,
124 Error = -1
125 };
126
127 /**
128 Decodes a portion of the image, and returns the appropriate
129 status, or the number of bytes read
130 */
131 virtual int processData(uchar *data, int length) = 0;
132
133 /**
134 This method is called to notify the decoder that the input is done, if the decoder
135 has not already indicated some sort of completion on the stream; this is intended
136 mostly for non-incremental decoders. It should return Done if all is OK. Note that
137 the "if" above should mean that the non-incremental decoders should just return
138 the bytes read in processData
139 */
140 virtual int processEOF()
141 {
142 return Done; //### Probably should be Error if notifyImageInfo has not been called
143 }
144};
145
146}
147
148#endif
149