author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the plugins of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
** WARNING: |
|
41 |
** A separate license from Unisys may be required to use the gif |
|
42 |
** reader. See http://www.unisys.com/about__unisys/lzw/ |
|
43 |
** for information from Unisys |
|
44 |
** |
|
45 |
****************************************************************************/ |
|
46 |
||
47 |
#include "qgifhandler.h" |
|
48 |
||
49 |
#include <qimage.h> |
|
50 |
#include <qiodevice.h> |
|
51 |
#include <qvariant.h> |
|
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
||
55 |
#define Q_TRANSPARENT 0x00ffffff |
|
56 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
57 |
// avoid going through QImage::scanLine() which calls detach |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
58 |
#define FAST_SCAN_LINE(bits, bpl, y) (bits + (y) * bpl) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
59 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
60 |
|
0 | 61 |
/* |
62 |
Incremental image decoder for GIF image format. |
|
63 |
||
64 |
This subclass of QImageFormat decodes GIF format images, |
|
65 |
including animated GIFs. Internally in |
|
66 |
*/ |
|
67 |
||
68 |
class QGIFFormat { |
|
69 |
public: |
|
70 |
QGIFFormat(); |
|
71 |
~QGIFFormat(); |
|
72 |
||
73 |
int decode(QImage *image, const uchar* buffer, int length, |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
74 |
int *nextFrameDelay, int *loopCount); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
75 |
static void scan(QIODevice *device, QVector<QSize> *imageSizes, int *loopCount); |
0 | 76 |
|
77 |
bool newFrame; |
|
78 |
bool partialNewFrame; |
|
79 |
||
80 |
private: |
|
81 |
void fillRect(QImage *image, int x, int y, int w, int h, QRgb col); |
|
82 |
inline QRgb color(uchar index) const; |
|
83 |
||
84 |
// GIF specific stuff |
|
85 |
QRgb* globalcmap; |
|
86 |
QRgb* localcmap; |
|
87 |
QImage backingstore; |
|
88 |
unsigned char hold[16]; |
|
89 |
bool gif89; |
|
90 |
int count; |
|
91 |
int ccount; |
|
92 |
int expectcount; |
|
93 |
enum State { |
|
94 |
Header, |
|
95 |
LogicalScreenDescriptor, |
|
96 |
GlobalColorMap, |
|
97 |
LocalColorMap, |
|
98 |
Introducer, |
|
99 |
ImageDescriptor, |
|
100 |
TableImageLZWSize, |
|
101 |
ImageDataBlockSize, |
|
102 |
ImageDataBlock, |
|
103 |
ExtensionLabel, |
|
104 |
GraphicControlExtension, |
|
105 |
ApplicationExtension, |
|
106 |
NetscapeExtensionBlockSize, |
|
107 |
NetscapeExtensionBlock, |
|
108 |
SkipBlockSize, |
|
109 |
SkipBlock, |
|
110 |
Done, |
|
111 |
Error |
|
112 |
} state; |
|
113 |
int gncols; |
|
114 |
int lncols; |
|
115 |
int ncols; |
|
116 |
int lzwsize; |
|
117 |
bool lcmap; |
|
118 |
int swidth, sheight; |
|
119 |
int width, height; |
|
120 |
int left, top, right, bottom; |
|
121 |
enum Disposal { NoDisposal, DoNotChange, RestoreBackground, RestoreImage }; |
|
122 |
Disposal disposal; |
|
123 |
bool disposed; |
|
124 |
int trans_index; |
|
125 |
bool gcmap; |
|
126 |
int bgcol; |
|
127 |
int interlace; |
|
128 |
int accum; |
|
129 |
int bitcount; |
|
130 |
||
131 |
enum { max_lzw_bits=12 }; // (poor-compiler's static const int) |
|
132 |
||
133 |
int code_size, clear_code, end_code, max_code_size, max_code; |
|
134 |
int firstcode, oldcode, incode; |
|
135 |
short table[2][1<< max_lzw_bits]; |
|
136 |
short stack[(1<<(max_lzw_bits))*2]; |
|
137 |
short *sp; |
|
138 |
bool needfirst; |
|
139 |
int x, y; |
|
140 |
int frame; |
|
141 |
bool out_of_bounds; |
|
142 |
bool digress; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
143 |
void nextY(unsigned char *bits, int bpl); |
0 | 144 |
void disposePrevious(QImage *image); |
145 |
}; |
|
146 |
||
147 |
/*! |
|
148 |
Constructs a QGIFFormat. |
|
149 |
*/ |
|
150 |
QGIFFormat::QGIFFormat() |
|
151 |
{ |
|
152 |
globalcmap = 0; |
|
153 |
localcmap = 0; |
|
154 |
lncols = 0; |
|
155 |
gncols = 0; |
|
156 |
disposal = NoDisposal; |
|
157 |
out_of_bounds = false; |
|
158 |
disposed = true; |
|
159 |
frame = -1; |
|
160 |
state = Header; |
|
161 |
count = 0; |
|
162 |
lcmap = false; |
|
163 |
newFrame = false; |
|
164 |
partialNewFrame = false; |
|
165 |
} |
|
166 |
||
167 |
/*! |
|
168 |
Destroys a QGIFFormat. |
|
169 |
*/ |
|
170 |
QGIFFormat::~QGIFFormat() |
|
171 |
{ |
|
172 |
if (globalcmap) delete[] globalcmap; |
|
173 |
if (localcmap) delete[] localcmap; |
|
174 |
} |
|
175 |
||
176 |
void QGIFFormat::disposePrevious(QImage *image) |
|
177 |
{ |
|
178 |
if (out_of_bounds) { |
|
179 |
// flush anything that survived |
|
180 |
// ### Changed: QRect(0, 0, swidth, sheight) |
|
181 |
} |
|
182 |
||
183 |
// Handle disposal of previous image before processing next one |
|
184 |
||
185 |
if (disposed) return; |
|
186 |
||
187 |
int l = qMin(swidth-1,left); |
|
188 |
int r = qMin(swidth-1,right); |
|
189 |
int t = qMin(sheight-1,top); |
|
190 |
int b = qMin(sheight-1,bottom); |
|
191 |
||
192 |
switch (disposal) { |
|
193 |
case NoDisposal: |
|
194 |
break; |
|
195 |
case DoNotChange: |
|
196 |
break; |
|
197 |
case RestoreBackground: |
|
198 |
if (trans_index>=0) { |
|
199 |
// Easy: we use the transparent color |
|
200 |
fillRect(image, l, t, r-l+1, b-t+1, Q_TRANSPARENT); |
|
201 |
} else if (bgcol>=0) { |
|
202 |
// Easy: we use the bgcol given |
|
203 |
fillRect(image, l, t, r-l+1, b-t+1, color(bgcol)); |
|
204 |
} else { |
|
205 |
// Impossible: We don't know of a bgcol - use pixel 0 |
|
206 |
QRgb *bits = (QRgb*)image->bits(); |
|
207 |
fillRect(image, l, t, r-l+1, b-t+1, bits[0]); |
|
208 |
} |
|
209 |
// ### Changed: QRect(l, t, r-l+1, b-t+1) |
|
210 |
break; |
|
211 |
case RestoreImage: { |
|
212 |
if (frame >= 0) { |
|
213 |
for (int ln=t; ln<=b; ln++) { |
|
214 |
memcpy(image->scanLine(ln)+l, |
|
215 |
backingstore.scanLine(ln-t), |
|
216 |
(r-l+1)*sizeof(QRgb)); |
|
217 |
} |
|
218 |
// ### Changed: QRect(l, t, r-l+1, b-t+1) |
|
219 |
} |
|
220 |
} |
|
221 |
} |
|
222 |
disposal = NoDisposal; // Until an extension says otherwise. |
|
223 |
||
224 |
disposed = true; |
|
225 |
} |
|
226 |
||
227 |
/*! |
|
228 |
This function decodes some data into image changes. |
|
229 |
||
230 |
Returns the number of bytes consumed. |
|
231 |
*/ |
|
232 |
int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
233 |
int *nextFrameDelay, int *loopCount) |
0 | 234 |
{ |
235 |
// We are required to state that |
|
236 |
// "The Graphics Interchange Format(c) is the Copyright property of |
|
237 |
// CompuServe Incorporated. GIF(sm) is a Service Mark property of |
|
238 |
// CompuServe Incorporated." |
|
239 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
240 |
image->detach(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
241 |
int bpl = image->bytesPerLine(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
242 |
unsigned char *bits = image->bits(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
243 |
|
0 | 244 |
#define LM(l, m) (((m)<<8)|l) |
245 |
digress = false; |
|
246 |
const int initial = length; |
|
247 |
while (!digress && length) { |
|
248 |
length--; |
|
249 |
unsigned char ch=*buffer++; |
|
250 |
switch (state) { |
|
251 |
case Header: |
|
252 |
hold[count++]=ch; |
|
253 |
if (count==6) { |
|
254 |
// Header |
|
255 |
gif89=(hold[3]!='8' || hold[4]!='7'); |
|
256 |
state=LogicalScreenDescriptor; |
|
257 |
count=0; |
|
258 |
} |
|
259 |
break; |
|
260 |
case LogicalScreenDescriptor: |
|
261 |
hold[count++]=ch; |
|
262 |
if (count==7) { |
|
263 |
// Logical Screen Descriptor |
|
264 |
swidth=LM(hold[0], hold[1]); |
|
265 |
sheight=LM(hold[2], hold[3]); |
|
266 |
gcmap=!!(hold[4]&0x80); |
|
267 |
//UNUSED: bpchan=(((hold[4]&0x70)>>3)+1); |
|
268 |
//UNUSED: gcmsortflag=!!(hold[4]&0x08); |
|
269 |
gncols=2<<(hold[4]&0x7); |
|
270 |
bgcol=(gcmap) ? hold[5] : -1; |
|
271 |
//aspect=hold[6] ? double(hold[6]+15)/64.0 : 1.0; |
|
272 |
||
273 |
trans_index = -1; |
|
274 |
count=0; |
|
275 |
ncols=gncols; |
|
276 |
if (gcmap) { |
|
277 |
ccount=0; |
|
278 |
state=GlobalColorMap; |
|
279 |
globalcmap = new QRgb[gncols+1]; // +1 for trans_index |
|
280 |
globalcmap[gncols] = Q_TRANSPARENT; |
|
281 |
} else { |
|
282 |
state=Introducer; |
|
283 |
} |
|
284 |
} |
|
285 |
break; |
|
286 |
case GlobalColorMap: case LocalColorMap: |
|
287 |
hold[count++]=ch; |
|
288 |
if (count==3) { |
|
289 |
QRgb rgb = qRgb(hold[0], hold[1], hold[2]); |
|
290 |
if (state == LocalColorMap) { |
|
291 |
if (ccount < lncols) |
|
292 |
localcmap[ccount] = rgb; |
|
293 |
} else { |
|
294 |
globalcmap[ccount] = rgb; |
|
295 |
} |
|
296 |
if (++ccount >= ncols) { |
|
297 |
if (state == LocalColorMap) |
|
298 |
state=TableImageLZWSize; |
|
299 |
else |
|
300 |
state=Introducer; |
|
301 |
} |
|
302 |
count=0; |
|
303 |
} |
|
304 |
break; |
|
305 |
case Introducer: |
|
306 |
hold[count++]=ch; |
|
307 |
switch (ch) { |
|
308 |
case ',': |
|
309 |
state=ImageDescriptor; |
|
310 |
break; |
|
311 |
case '!': |
|
312 |
state=ExtensionLabel; |
|
313 |
break; |
|
314 |
case ';': |
|
315 |
// ### Changed: QRect(0, 0, swidth, sheight) |
|
316 |
state=Done; |
|
317 |
break; |
|
318 |
default: |
|
319 |
digress=true; |
|
320 |
// Unexpected Introducer - ignore block |
|
321 |
state=Error; |
|
322 |
} |
|
323 |
break; |
|
324 |
case ImageDescriptor: |
|
325 |
hold[count++]=ch; |
|
326 |
if (count==10) { |
|
327 |
int newleft=LM(hold[1], hold[2]); |
|
328 |
int newtop=LM(hold[3], hold[4]); |
|
329 |
int newwidth=LM(hold[5], hold[6]); |
|
330 |
int newheight=LM(hold[7], hold[8]); |
|
331 |
||
332 |
// disbelieve ridiculous logical screen sizes, |
|
333 |
// unless the image frames are also large. |
|
334 |
if (swidth/10 > qMax(newwidth,200)) |
|
335 |
swidth = -1; |
|
336 |
if (sheight/10 > qMax(newheight,200)) |
|
337 |
sheight = -1; |
|
338 |
||
339 |
if (swidth <= 0) |
|
340 |
swidth = newleft + newwidth; |
|
341 |
if (sheight <= 0) |
|
342 |
sheight = newtop + newheight; |
|
343 |
||
344 |
QImage::Format format = trans_index >= 0 ? QImage::Format_ARGB32 : QImage::Format_RGB32; |
|
345 |
if (image->isNull()) { |
|
346 |
(*image) = QImage(swidth, sheight, format); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
347 |
bpl = image->bytesPerLine(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
348 |
bits = image->bits(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
349 |
memset(bits, 0, image->byteCount()); |
0 | 350 |
} |
351 |
||
352 |
disposePrevious(image); |
|
353 |
disposed = false; |
|
354 |
||
355 |
left = newleft; |
|
356 |
top = newtop; |
|
357 |
width = newwidth; |
|
358 |
height = newheight; |
|
359 |
||
360 |
right=qMax(0, qMin(left+width, swidth)-1); |
|
361 |
bottom=qMax(0, qMin(top+height, sheight)-1); |
|
362 |
lcmap=!!(hold[9]&0x80); |
|
363 |
interlace=!!(hold[9]&0x40); |
|
364 |
//bool lcmsortflag=!!(hold[9]&0x20); |
|
365 |
lncols=lcmap ? (2<<(hold[9]&0x7)) : 0; |
|
366 |
if (lncols) { |
|
367 |
if (localcmap) |
|
368 |
delete [] localcmap; |
|
369 |
localcmap = new QRgb[lncols+1]; |
|
370 |
localcmap[lncols] = Q_TRANSPARENT; |
|
371 |
ncols = lncols; |
|
372 |
} else { |
|
373 |
ncols = gncols; |
|
374 |
} |
|
375 |
frame++; |
|
376 |
if (frame == 0) { |
|
377 |
if (left || top || width<swidth || height<sheight) { |
|
378 |
// Not full-size image - erase with bg or transparent |
|
379 |
if (trans_index >= 0) { |
|
380 |
fillRect(image, 0, 0, swidth, sheight, color(trans_index)); |
|
381 |
// ### Changed: QRect(0, 0, swidth, sheight) |
|
382 |
} else if (bgcol>=0) { |
|
383 |
fillRect(image, 0, 0, swidth, sheight, color(bgcol)); |
|
384 |
// ### Changed: QRect(0, 0, swidth, sheight) |
|
385 |
} |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
if (disposal == RestoreImage) { |
|
390 |
int l = qMin(swidth-1,left); |
|
391 |
int r = qMin(swidth-1,right); |
|
392 |
int t = qMin(sheight-1,top); |
|
393 |
int b = qMin(sheight-1,bottom); |
|
394 |
int w = r-l+1; |
|
395 |
int h = b-t+1; |
|
396 |
||
397 |
if (backingstore.width() < w |
|
398 |
|| backingstore.height() < h) { |
|
399 |
// We just use the backing store as a byte array |
|
400 |
backingstore = QImage(qMax(backingstore.width(), w), |
|
401 |
qMax(backingstore.height(), h), |
|
402 |
QImage::Format_RGB32); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
403 |
memset(bits, 0, image->byteCount()); |
0 | 404 |
} |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
405 |
const int dest_bpl = backingstore.bytesPerLine(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
406 |
unsigned char *dest_data = backingstore.bits(); |
0 | 407 |
for (int ln=0; ln<h; ln++) { |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
408 |
memcpy(FAST_SCAN_LINE(dest_data, dest_bpl, ln), |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
409 |
FAST_SCAN_LINE(bits, bpl, t+ln) + l, w*sizeof(QRgb)); |
0 | 410 |
} |
411 |
} |
|
412 |
||
413 |
count=0; |
|
414 |
if (lcmap) { |
|
415 |
ccount=0; |
|
416 |
state=LocalColorMap; |
|
417 |
} else { |
|
418 |
state=TableImageLZWSize; |
|
419 |
} |
|
420 |
x = left; |
|
421 |
y = top; |
|
422 |
accum = 0; |
|
423 |
bitcount = 0; |
|
424 |
sp = stack; |
|
425 |
firstcode = oldcode = 0; |
|
426 |
needfirst = true; |
|
427 |
out_of_bounds = left>=swidth || y>=sheight; |
|
428 |
} |
|
429 |
break; |
|
430 |
case TableImageLZWSize: { |
|
431 |
lzwsize=ch; |
|
432 |
if (lzwsize > max_lzw_bits) { |
|
433 |
state=Error; |
|
434 |
} else { |
|
435 |
code_size=lzwsize+1; |
|
436 |
clear_code=1<<lzwsize; |
|
437 |
end_code=clear_code+1; |
|
438 |
max_code_size=2*clear_code; |
|
439 |
max_code=clear_code+2; |
|
440 |
int i; |
|
441 |
for (i=0; i<clear_code; i++) { |
|
442 |
table[0][i]=0; |
|
443 |
table[1][i]=i; |
|
444 |
} |
|
445 |
state=ImageDataBlockSize; |
|
446 |
} |
|
447 |
count=0; |
|
448 |
break; |
|
449 |
} case ImageDataBlockSize: |
|
450 |
expectcount=ch; |
|
451 |
if (expectcount) { |
|
452 |
state=ImageDataBlock; |
|
453 |
} else { |
|
454 |
state=Introducer; |
|
455 |
digress = true; |
|
456 |
newFrame = true; |
|
457 |
} |
|
458 |
break; |
|
459 |
case ImageDataBlock: |
|
460 |
count++; |
|
461 |
accum|=(ch<<bitcount); |
|
462 |
bitcount+=8; |
|
463 |
while (bitcount>=code_size && state==ImageDataBlock) { |
|
464 |
int code=accum&((1<<code_size)-1); |
|
465 |
bitcount-=code_size; |
|
466 |
accum>>=code_size; |
|
467 |
||
468 |
if (code==clear_code) { |
|
469 |
if (!needfirst) { |
|
470 |
code_size=lzwsize+1; |
|
471 |
max_code_size=2*clear_code; |
|
472 |
max_code=clear_code+2; |
|
473 |
} |
|
474 |
needfirst=true; |
|
475 |
} else if (code==end_code) { |
|
476 |
bitcount = -32768; |
|
477 |
// Left the block end arrive |
|
478 |
} else { |
|
479 |
if (needfirst) { |
|
480 |
firstcode=oldcode=code; |
|
481 |
if (!out_of_bounds && image->height() > y && firstcode!=trans_index) |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
482 |
((QRgb*)FAST_SCAN_LINE(bits, bpl, y))[x] = color(firstcode); |
0 | 483 |
x++; |
484 |
if (x>=swidth) out_of_bounds = true; |
|
485 |
needfirst=false; |
|
486 |
if (x>=left+width) { |
|
487 |
x=left; |
|
488 |
out_of_bounds = left>=swidth || y>=sheight; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
489 |
nextY(bits, bpl); |
0 | 490 |
} |
491 |
} else { |
|
492 |
incode=code; |
|
493 |
if (code>=max_code) { |
|
494 |
*sp++=firstcode; |
|
495 |
code=oldcode; |
|
496 |
} |
|
497 |
while (code>=clear_code+2) { |
|
498 |
*sp++=table[1][code]; |
|
499 |
if (code==table[0][code]) { |
|
500 |
state=Error; |
|
501 |
break; |
|
502 |
} |
|
503 |
if (sp-stack>=(1<<(max_lzw_bits))*2) { |
|
504 |
state=Error; |
|
505 |
break; |
|
506 |
} |
|
507 |
code=table[0][code]; |
|
508 |
} |
|
509 |
*sp++=firstcode=table[1][code]; |
|
510 |
code=max_code; |
|
511 |
if (code<(1<<max_lzw_bits)) { |
|
512 |
table[0][code]=oldcode; |
|
513 |
table[1][code]=firstcode; |
|
514 |
max_code++; |
|
515 |
if ((max_code>=max_code_size) |
|
516 |
&& (max_code_size<(1<<max_lzw_bits))) |
|
517 |
{ |
|
518 |
max_code_size*=2; |
|
519 |
code_size++; |
|
520 |
} |
|
521 |
} |
|
522 |
oldcode=incode; |
|
523 |
const int h = image->height(); |
|
524 |
const QRgb *map = lcmap ? localcmap : globalcmap; |
|
525 |
QRgb *line = 0; |
|
526 |
if (!out_of_bounds && h > y) |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
527 |
line = (QRgb*)FAST_SCAN_LINE(bits, bpl, y); |
0 | 528 |
while (sp>stack) { |
529 |
const uchar index = *(--sp); |
|
530 |
if (!out_of_bounds && h > y && index!=trans_index) { |
|
531 |
if (index > ncols) |
|
532 |
line[x] = Q_TRANSPARENT; |
|
533 |
else |
|
534 |
line[x] = map ? map[index] : 0; |
|
535 |
} |
|
536 |
x++; |
|
537 |
if (x>=swidth) out_of_bounds = true; |
|
538 |
if (x>=left+width) { |
|
539 |
x=left; |
|
540 |
out_of_bounds = left>=swidth || y>=sheight; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
541 |
nextY(bits, bpl); |
0 | 542 |
if (!out_of_bounds && h > y) |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
543 |
line = (QRgb*)FAST_SCAN_LINE(bits, bpl, y); |
0 | 544 |
} |
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
partialNewFrame = true; |
|
550 |
if (count==expectcount) { |
|
551 |
count=0; |
|
552 |
state=ImageDataBlockSize; |
|
553 |
} |
|
554 |
break; |
|
555 |
case ExtensionLabel: |
|
556 |
switch (ch) { |
|
557 |
case 0xf9: |
|
558 |
state=GraphicControlExtension; |
|
559 |
break; |
|
560 |
case 0xff: |
|
561 |
state=ApplicationExtension; |
|
562 |
break; |
|
563 |
#if 0 |
|
564 |
case 0xfe: |
|
565 |
state=CommentExtension; |
|
566 |
break; |
|
567 |
case 0x01: |
|
568 |
break; |
|
569 |
#endif |
|
570 |
default: |
|
571 |
state=SkipBlockSize; |
|
572 |
} |
|
573 |
count=0; |
|
574 |
break; |
|
575 |
case ApplicationExtension: |
|
576 |
if (count<11) hold[count]=ch; |
|
577 |
count++; |
|
578 |
if (count==hold[0]+1) { |
|
579 |
if (qstrncmp((char*)(hold+1), "NETSCAPE", 8)==0) { |
|
580 |
// Looping extension |
|
581 |
state=NetscapeExtensionBlockSize; |
|
582 |
} else { |
|
583 |
state=SkipBlockSize; |
|
584 |
} |
|
585 |
count=0; |
|
586 |
} |
|
587 |
break; |
|
588 |
case NetscapeExtensionBlockSize: |
|
589 |
expectcount=ch; |
|
590 |
count=0; |
|
591 |
if (expectcount) state=NetscapeExtensionBlock; |
|
592 |
else state=Introducer; |
|
593 |
break; |
|
594 |
case NetscapeExtensionBlock: |
|
595 |
if (count<3) hold[count]=ch; |
|
596 |
count++; |
|
597 |
if (count==expectcount) { |
|
598 |
*loopCount = hold[1]+hold[2]*256; |
|
599 |
state=SkipBlockSize; // Ignore further blocks |
|
600 |
} |
|
601 |
break; |
|
602 |
case GraphicControlExtension: |
|
603 |
if (count<5) hold[count]=ch; |
|
604 |
count++; |
|
605 |
if (count==hold[0]+1) { |
|
606 |
disposePrevious(image); |
|
607 |
disposal=Disposal((hold[1]>>2)&0x7); |
|
608 |
//UNUSED: waitforuser=!!((hold[1]>>1)&0x1); |
|
609 |
int delay=count>3 ? LM(hold[2], hold[3]) : 1; |
|
610 |
// IE and mozilla use a minimum delay of 10. With the minimum delay of 10 |
|
611 |
// we are compatible to them and avoid huge loads on the app and xserver. |
|
612 |
*nextFrameDelay = (delay < 2 ? 10 : delay) * 10; |
|
613 |
||
614 |
bool havetrans=hold[1]&0x1; |
|
615 |
trans_index = havetrans ? hold[4] : -1; |
|
616 |
||
617 |
count=0; |
|
618 |
state=SkipBlockSize; |
|
619 |
} |
|
620 |
break; |
|
621 |
case SkipBlockSize: |
|
622 |
expectcount=ch; |
|
623 |
count=0; |
|
624 |
if (expectcount) state=SkipBlock; |
|
625 |
else state=Introducer; |
|
626 |
break; |
|
627 |
case SkipBlock: |
|
628 |
count++; |
|
629 |
if (count==expectcount) state=SkipBlockSize; |
|
630 |
break; |
|
631 |
case Done: |
|
632 |
digress=true; |
|
633 |
/* Netscape ignores the junk, so we do too. |
|
634 |
length++; // Unget |
|
635 |
state=Error; // More calls to this is an error |
|
636 |
*/ |
|
637 |
break; |
|
638 |
case Error: |
|
639 |
return -1; // Called again after done. |
|
640 |
} |
|
641 |
} |
|
642 |
return initial-length; |
|
643 |
} |
|
644 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
645 |
/*! |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
646 |
Scans through the data stream defined by \a device and returns the image |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
647 |
sizes found in the stream in the \a imageSizes vector. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
648 |
*/ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
649 |
void QGIFFormat::scan(QIODevice *device, QVector<QSize> *imageSizes, int *loopCount) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
650 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
651 |
if (!device) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
652 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
653 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
654 |
qint64 oldPos = device->pos(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
655 |
if (!device->seek(0)) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
656 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
657 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
658 |
int colorCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
659 |
int localColorCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
660 |
int globalColorCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
661 |
int colorReadCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
662 |
bool localColormap = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
663 |
bool globalColormap = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
664 |
int count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
665 |
int blockSize = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
666 |
int imageWidth = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
667 |
int imageHeight = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
668 |
bool done = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
669 |
uchar hold[16]; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
670 |
State state = Header; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
671 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
672 |
const int readBufferSize = 40960; // 40k read buffer |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
673 |
QByteArray readBuffer(device->read(readBufferSize)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
674 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
675 |
if (readBuffer.isEmpty()) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
676 |
device->seek(oldPos); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
677 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
678 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
679 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
680 |
// This is a specialized version of the state machine from decode(), |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
681 |
// which doesn't do any image decoding or mallocing, and has an |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
682 |
// optimized way of skipping SkipBlocks, ImageDataBlocks and |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
683 |
// Global/LocalColorMaps. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
684 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
685 |
while (!readBuffer.isEmpty()) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
686 |
int length = readBuffer.size(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
687 |
const uchar *buffer = (const uchar *) readBuffer.constData(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
688 |
while (!done && length) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
689 |
length--; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
690 |
uchar ch = *buffer++; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
691 |
switch (state) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
692 |
case Header: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
693 |
hold[count++] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
694 |
if (count == 6) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
695 |
state = LogicalScreenDescriptor; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
696 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
697 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
698 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
699 |
case LogicalScreenDescriptor: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
700 |
hold[count++] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
701 |
if (count == 7) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
702 |
imageWidth = LM(hold[0], hold[1]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
703 |
imageHeight = LM(hold[2], hold[3]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
704 |
globalColormap = !!(hold[4] & 0x80); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
705 |
globalColorCount = 2 << (hold[4] & 0x7); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
706 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
707 |
colorCount = globalColorCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
708 |
if (globalColormap) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
709 |
int colorTableSize = 3 * globalColorCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
710 |
if (length >= colorTableSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
711 |
// skip the global color table in one go |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
712 |
length -= colorTableSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
713 |
buffer += colorTableSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
714 |
state = Introducer; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
715 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
716 |
colorReadCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
717 |
state = GlobalColorMap; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
718 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
719 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
720 |
state=Introducer; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
721 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
722 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
723 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
724 |
case GlobalColorMap: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
725 |
case LocalColorMap: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
726 |
hold[count++] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
727 |
if (count == 3) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
728 |
if (++colorReadCount >= colorCount) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
729 |
if (state == LocalColorMap) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
730 |
state = TableImageLZWSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
731 |
else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
732 |
state = Introducer; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
733 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
734 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
735 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
736 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
737 |
case Introducer: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
738 |
hold[count++] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
739 |
switch (ch) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
740 |
case 0x2c: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
741 |
state = ImageDescriptor; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
742 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
743 |
case 0x21: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
744 |
state = ExtensionLabel; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
745 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
746 |
case 0x3b: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
747 |
state = Done; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
748 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
749 |
default: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
750 |
done = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
751 |
state = Error; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
752 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
753 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
754 |
case ImageDescriptor: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
755 |
hold[count++] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
756 |
if (count == 10) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
757 |
int newLeft = LM(hold[1], hold[2]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
758 |
int newTop = LM(hold[3], hold[4]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
759 |
int newWidth = LM(hold[5], hold[6]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
760 |
int newHeight = LM(hold[7], hold[8]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
761 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
762 |
if (imageWidth/10 > qMax(newWidth,200)) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
763 |
imageWidth = -1; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
764 |
if (imageHeight/10 > qMax(newHeight,200)) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
765 |
imageHeight = -1; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
766 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
767 |
if (imageWidth <= 0) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
768 |
imageWidth = newLeft + newWidth; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
769 |
if (imageHeight <= 0) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
770 |
imageHeight = newTop + newHeight; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
771 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
772 |
*imageSizes << QSize(imageWidth, imageHeight); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
773 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
774 |
localColormap = !!(hold[9] & 0x80); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
775 |
localColorCount = localColormap ? (2 << (hold[9] & 0x7)) : 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
776 |
if (localColorCount) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
777 |
colorCount = localColorCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
778 |
else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
779 |
colorCount = globalColorCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
780 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
781 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
782 |
if (localColormap) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
783 |
int colorTableSize = 3 * localColorCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
784 |
if (length >= colorTableSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
785 |
// skip the local color table in one go |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
786 |
length -= colorTableSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
787 |
buffer += colorTableSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
788 |
state = TableImageLZWSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
789 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
790 |
colorReadCount = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
791 |
state = LocalColorMap; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
792 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
793 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
794 |
state = TableImageLZWSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
795 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
796 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
797 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
798 |
case TableImageLZWSize: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
799 |
if (ch > max_lzw_bits) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
800 |
state = Error; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
801 |
else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
802 |
state = ImageDataBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
803 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
804 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
805 |
case ImageDataBlockSize: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
806 |
blockSize = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
807 |
if (blockSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
808 |
if (length >= blockSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
809 |
// we can skip the block in one go |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
810 |
length -= blockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
811 |
buffer += blockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
812 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
813 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
814 |
state = ImageDataBlock; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
815 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
816 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
817 |
state = Introducer; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
818 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
819 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
820 |
case ImageDataBlock: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
821 |
++count; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
822 |
if (count == blockSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
823 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
824 |
state = ImageDataBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
825 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
826 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
827 |
case ExtensionLabel: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
828 |
switch (ch) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
829 |
case 0xf9: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
830 |
state = GraphicControlExtension; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
831 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
832 |
case 0xff: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
833 |
state = ApplicationExtension; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
834 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
835 |
default: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
836 |
state = SkipBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
837 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
838 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
839 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
840 |
case ApplicationExtension: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
841 |
if (count < 11) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
842 |
hold[count] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
843 |
++count; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
844 |
if (count == hold[0] + 1) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
845 |
if (qstrncmp((char*)(hold+1), "NETSCAPE", 8) == 0) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
846 |
state=NetscapeExtensionBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
847 |
else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
848 |
state=SkipBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
849 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
850 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
851 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
852 |
case GraphicControlExtension: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
853 |
if (count < 5) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
854 |
hold[count] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
855 |
++count; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
856 |
if (count == hold[0] + 1) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
857 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
858 |
state = SkipBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
859 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
860 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
861 |
case NetscapeExtensionBlockSize: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
862 |
blockSize = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
863 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
864 |
if (blockSize) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
865 |
state = NetscapeExtensionBlock; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
866 |
else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
867 |
state = Introducer; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
868 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
869 |
case NetscapeExtensionBlock: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
870 |
if (count < 3) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
871 |
hold[count] = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
872 |
count++; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
873 |
if (count == blockSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
874 |
*loopCount = LM(hold[1], hold[2]); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
875 |
state = SkipBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
876 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
877 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
878 |
case SkipBlockSize: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
879 |
blockSize = ch; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
880 |
count = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
881 |
if (blockSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
882 |
if (length >= blockSize) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
883 |
// we can skip the block in one go |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
884 |
length -= blockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
885 |
buffer += blockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
886 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
887 |
state = SkipBlock; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
888 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
889 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
890 |
state = Introducer; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
891 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
892 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
893 |
case SkipBlock: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
894 |
++count; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
895 |
if (count == blockSize) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
896 |
state = SkipBlockSize; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
897 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
898 |
case Done: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
899 |
done = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
900 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
901 |
case Error: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
902 |
device->seek(oldPos); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
903 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
904 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
905 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
906 |
readBuffer = device->read(readBufferSize); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
907 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
908 |
device->seek(oldPos); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
909 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
910 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
911 |
|
0 | 912 |
void QGIFFormat::fillRect(QImage *image, int col, int row, int w, int h, QRgb color) |
913 |
{ |
|
914 |
if (w>0) { |
|
915 |
for (int j=0; j<h; j++) { |
|
916 |
QRgb *line = (QRgb*)image->scanLine(j+row); |
|
917 |
for (int i=0; i<w; i++) |
|
918 |
*(line+col+i) = color; |
|
919 |
} |
|
920 |
} |
|
921 |
} |
|
922 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
923 |
void QGIFFormat::nextY(unsigned char *bits, int bpl) |
0 | 924 |
{ |
925 |
int my; |
|
926 |
switch (interlace) { |
|
927 |
case 0: // Non-interlaced |
|
928 |
// if (!out_of_bounds) { |
|
929 |
// ### Changed: QRect(left, y, right - left + 1, 1); |
|
930 |
// } |
|
931 |
y++; |
|
932 |
break; |
|
933 |
case 1: { |
|
934 |
int i; |
|
935 |
my = qMin(7, bottom-y); |
|
936 |
// Don't dup with transparency |
|
937 |
if (trans_index < 0) { |
|
938 |
for (i=1; i<=my; i++) { |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
939 |
memcpy(FAST_SCAN_LINE(bits, bpl, y+i)+left*sizeof(QRgb), FAST_SCAN_LINE(bits, bpl, y)+left*sizeof(QRgb), |
0 | 940 |
(right-left+1)*sizeof(QRgb)); |
941 |
} |
|
942 |
} |
|
943 |
||
944 |
// if (!out_of_bounds) { |
|
945 |
// ### Changed: QRect(left, y, right - left + 1, my + 1); |
|
946 |
// } |
|
947 |
// if (!out_of_bounds) |
|
948 |
// qDebug("consumer->changed(QRect(%d, %d, %d, %d))", left, y, right-left+1, my+1); |
|
949 |
y+=8; |
|
950 |
if (y>bottom) { |
|
951 |
interlace++; y=top+4; |
|
952 |
if (y > bottom) { // for really broken GIFs with bottom < 5 |
|
953 |
interlace=2; |
|
954 |
y = top + 2; |
|
955 |
if (y > bottom) { // for really broken GIF with bottom < 3 |
|
956 |
interlace = 0; |
|
957 |
y = top + 1; |
|
958 |
} |
|
959 |
} |
|
960 |
} |
|
961 |
} break; |
|
962 |
case 2: { |
|
963 |
int i; |
|
964 |
my = qMin(3, bottom-y); |
|
965 |
// Don't dup with transparency |
|
966 |
if (trans_index < 0) { |
|
967 |
for (i=1; i<=my; i++) { |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
968 |
memcpy(FAST_SCAN_LINE(bits, bpl, y+i)+left*sizeof(QRgb), FAST_SCAN_LINE(bits, bpl, y)+left*sizeof(QRgb), |
0 | 969 |
(right-left+1)*sizeof(QRgb)); |
970 |
} |
|
971 |
} |
|
972 |
||
973 |
// if (!out_of_bounds) { |
|
974 |
// ### Changed: QRect(left, y, right - left + 1, my + 1); |
|
975 |
// } |
|
976 |
y+=8; |
|
977 |
if (y>bottom) { |
|
978 |
interlace++; y=top+2; |
|
979 |
// handle broken GIF with bottom < 3 |
|
980 |
if (y > bottom) { |
|
981 |
interlace = 3; |
|
982 |
y = top + 1; |
|
983 |
} |
|
984 |
} |
|
985 |
} break; |
|
986 |
case 3: { |
|
987 |
int i; |
|
988 |
my = qMin(1, bottom-y); |
|
989 |
// Don't dup with transparency |
|
990 |
if (trans_index < 0) { |
|
991 |
for (i=1; i<=my; i++) { |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
992 |
memcpy(FAST_SCAN_LINE(bits, bpl, y+i)+left*sizeof(QRgb), FAST_SCAN_LINE(bits, bpl, y)+left*sizeof(QRgb), |
0 | 993 |
(right-left+1)*sizeof(QRgb)); |
994 |
} |
|
995 |
} |
|
996 |
// if (!out_of_bounds) { |
|
997 |
// ### Changed: QRect(left, y, right - left + 1, my + 1); |
|
998 |
// } |
|
999 |
y+=4; |
|
1000 |
if (y>bottom) { interlace++; y=top+1; } |
|
1001 |
} break; |
|
1002 |
case 4: |
|
1003 |
// if (!out_of_bounds) { |
|
1004 |
// ### Changed: QRect(left, y, right - left + 1, 1); |
|
1005 |
// } |
|
1006 |
y+=2; |
|
1007 |
} |
|
1008 |
||
1009 |
// Consume bogus extra lines |
|
1010 |
if (y >= sheight) out_of_bounds=true; //y=bottom; |
|
1011 |
} |
|
1012 |
||
1013 |
inline QRgb QGIFFormat::color(uchar index) const |
|
1014 |
{ |
|
1015 |
if (index == trans_index || index > ncols) |
|
1016 |
return Q_TRANSPARENT; |
|
1017 |
||
1018 |
QRgb *map = lcmap ? localcmap : globalcmap; |
|
1019 |
return map ? map[index] : 0; |
|
1020 |
} |
|
1021 |
||
1022 |
//------------------------------------------------------------------------- |
|
1023 |
//------------------------------------------------------------------------- |
|
1024 |
//------------------------------------------------------------------------- |
|
1025 |
||
1026 |
QGifHandler::QGifHandler() |
|
1027 |
{ |
|
1028 |
gifFormat = new QGIFFormat; |
|
1029 |
nextDelay = 0; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1030 |
loopCnt = 1; |
0 | 1031 |
frameNumber = -1; |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1032 |
scanIsCached = false; |
0 | 1033 |
} |
1034 |
||
1035 |
QGifHandler::~QGifHandler() |
|
1036 |
{ |
|
1037 |
delete gifFormat; |
|
1038 |
} |
|
1039 |
||
1040 |
// Does partial decode if necessary, just to see if an image is coming |
|
1041 |
||
1042 |
bool QGifHandler::imageIsComing() const |
|
1043 |
{ |
|
1044 |
const int GifChunkSize = 4096; |
|
1045 |
||
1046 |
while (!gifFormat->partialNewFrame) { |
|
1047 |
if (buffer.isEmpty()) { |
|
1048 |
buffer += device()->read(GifChunkSize); |
|
1049 |
if (buffer.isEmpty()) |
|
1050 |
break; |
|
1051 |
} |
|
1052 |
||
1053 |
int decoded = gifFormat->decode(&lastImage, (const uchar *)buffer.constData(), buffer.size(), |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1054 |
&nextDelay, &loopCnt); |
0 | 1055 |
if (decoded == -1) |
1056 |
break; |
|
1057 |
buffer.remove(0, decoded); |
|
1058 |
} |
|
1059 |
return gifFormat->partialNewFrame; |
|
1060 |
} |
|
1061 |
||
1062 |
bool QGifHandler::canRead() const |
|
1063 |
{ |
|
1064 |
if (!nextDelay && canRead(device())) { |
|
1065 |
setFormat("gif"); |
|
1066 |
return true; |
|
1067 |
} |
|
1068 |
||
1069 |
return imageIsComing(); |
|
1070 |
} |
|
1071 |
||
1072 |
bool QGifHandler::canRead(QIODevice *device) |
|
1073 |
{ |
|
1074 |
if (!device) { |
|
1075 |
qWarning("QGifHandler::canRead() called with no device"); |
|
1076 |
return false; |
|
1077 |
} |
|
1078 |
||
1079 |
char head[6]; |
|
1080 |
if (device->peek(head, sizeof(head)) == sizeof(head)) |
|
1081 |
return qstrncmp(head, "GIF87a", 6) == 0 |
|
1082 |
|| qstrncmp(head, "GIF89a", 6) == 0; |
|
1083 |
return false; |
|
1084 |
} |
|
1085 |
||
1086 |
bool QGifHandler::read(QImage *image) |
|
1087 |
{ |
|
1088 |
const int GifChunkSize = 4096; |
|
1089 |
||
1090 |
while (!gifFormat->newFrame) { |
|
1091 |
if (buffer.isEmpty()) { |
|
1092 |
buffer += device()->read(GifChunkSize); |
|
1093 |
if (buffer.isEmpty()) |
|
1094 |
break; |
|
1095 |
} |
|
1096 |
||
1097 |
int decoded = gifFormat->decode(&lastImage, (const uchar *)buffer.constData(), buffer.size(), |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1098 |
&nextDelay, &loopCnt); |
0 | 1099 |
if (decoded == -1) |
1100 |
break; |
|
1101 |
buffer.remove(0, decoded); |
|
1102 |
} |
|
1103 |
if (gifFormat->newFrame || (gifFormat->partialNewFrame && device()->atEnd())) { |
|
1104 |
*image = lastImage; |
|
1105 |
++frameNumber; |
|
1106 |
gifFormat->newFrame = false; |
|
1107 |
gifFormat->partialNewFrame = false; |
|
1108 |
return true; |
|
1109 |
} |
|
1110 |
||
1111 |
return false; |
|
1112 |
} |
|
1113 |
||
1114 |
bool QGifHandler::write(const QImage &image) |
|
1115 |
{ |
|
1116 |
Q_UNUSED(image); |
|
1117 |
return false; |
|
1118 |
} |
|
1119 |
||
1120 |
bool QGifHandler::supportsOption(ImageOption option) const |
|
1121 |
{ |
|
1122 |
return option == Size |
|
1123 |
|| option == Animation; |
|
1124 |
} |
|
1125 |
||
1126 |
QVariant QGifHandler::option(ImageOption option) const |
|
1127 |
{ |
|
1128 |
if (option == Size) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1129 |
if (!scanIsCached) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1130 |
QGIFFormat::scan(device(), &imageSizes, &loopCnt); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1131 |
scanIsCached = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1132 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1133 |
// before the first frame is read, or we have an empty data stream |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1134 |
if (frameNumber == -1) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1135 |
return (imageSizes.count() > 0) ? QVariant(imageSizes.at(0)) : QVariant(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1136 |
// after the last frame has been read, the next size is undefined |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1137 |
if (frameNumber >= imageSizes.count() - 1) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1138 |
return QVariant(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1139 |
// and the last case: the size of the next frame |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1140 |
return imageSizes.at(frameNumber + 1); |
0 | 1141 |
} else if (option == Animation) { |
1142 |
return true; |
|
1143 |
} |
|
1144 |
return QVariant(); |
|
1145 |
} |
|
1146 |
||
1147 |
void QGifHandler::setOption(ImageOption option, const QVariant &value) |
|
1148 |
{ |
|
1149 |
Q_UNUSED(option); |
|
1150 |
Q_UNUSED(value); |
|
1151 |
} |
|
1152 |
||
1153 |
int QGifHandler::nextImageDelay() const |
|
1154 |
{ |
|
1155 |
return nextDelay; |
|
1156 |
} |
|
1157 |
||
1158 |
int QGifHandler::imageCount() const |
|
1159 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1160 |
if (!scanIsCached) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1161 |
QGIFFormat::scan(device(), &imageSizes, &loopCnt); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1162 |
scanIsCached = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1163 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1164 |
return imageSizes.count(); |
0 | 1165 |
} |
1166 |
||
1167 |
int QGifHandler::loopCount() const |
|
1168 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1169 |
if (!scanIsCached) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1170 |
QGIFFormat::scan(device(), &imageSizes, &loopCnt); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1171 |
scanIsCached = true; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1172 |
} |
0 | 1173 |
return loopCnt-1; // In GIF, loop count is iteration count, so subtract one |
1174 |
} |
|
1175 |
||
1176 |
int QGifHandler::currentImageNumber() const |
|
1177 |
{ |
|
1178 |
return frameNumber; |
|
1179 |
} |
|
1180 |
||
1181 |
QByteArray QGifHandler::name() const |
|
1182 |
{ |
|
1183 |
return "gif"; |
|
1184 |
} |
|
1185 |
||
1186 |
QT_END_NAMESPACE |