qppmhandler.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qppmhandler.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12static void discard_pbm_line(QIODevice *d)-
13{-
14 const int buflen = 100;-
15 char buf[buflen];-
16 int res = 0;-
17 do {-
18 res = d->readLine(buf, buflen);-
19 }
never executed: end of block
while (res > 0
res > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& buf[res-1] != '\n'
buf[res-1] != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
);
0
20}
never executed: end of block
0
21-
22static int read_pbm_int(QIODevice *d)-
23{-
24 char c;-
25 int val = -1;-
26 bool digit;-
27 for (;;) {-
28 if (!d->getChar(&c)
!d->getChar(&c)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
29 break;
never executed: break;
0
30 digit = isdigit((uchar) c);-
31 if (val != -1
val != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
32 if (digit
digitDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
33 val = 10*val + c - '0';-
34 continue;
never executed: continue;
0
35 } else {-
36 if (c == '#'
c == '#'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
37 discard_pbm_line(d);
never executed: discard_pbm_line(d);
0
38 break;
never executed: break;
0
39 }-
40 }-
41 if (digit
digitDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
42 val = c - '0';
never executed: val = c - '0';
0
43 else if (isspace((uchar) c)
isspace((uchar) c)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
44 continue;
never executed: continue;
0
45 else if (c == '#'
c == '#'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
46 discard_pbm_line(d);
never executed: discard_pbm_line(d);
0
47 else-
48 break;
never executed: break;
0
49 }-
50 return
never executed: return val;
val;
never executed: return val;
0
51}-
52-
53static bool read_pbm_header(QIODevice *device, char& type, int& w, int& h, int& mcc)-
54{-
55 char buf[3];-
56 if (device->read(buf, 3) != 3
device->read(buf, 3) != 3Description
TRUEnever evaluated
FALSEnever evaluated
)
0
57 return
never executed: return false;
false;
never executed: return false;
0
58-
59 if (!(buf[0] == 'P'
buf[0] == 'P'Description
TRUEnever evaluated
FALSEnever evaluated
&& isdigit((uchar) buf[1])
isdigit((uchar) buf[1])Description
TRUEnever evaluated
FALSEnever evaluated
&& isspace((uchar) buf[2])
isspace((uchar) buf[2])Description
TRUEnever evaluated
FALSEnever evaluated
))
0
60 return
never executed: return false;
false;
never executed: return false;
0
61-
62 type = buf[1];-
63 if (type < '1'
type < '1'Description
TRUEnever evaluated
FALSEnever evaluated
|| type > '6'
type > '6'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
64 return
never executed: return false;
false;
never executed: return false;
0
65-
66 w = read_pbm_int(device);-
67 h = read_pbm_int(device);-
68-
69 if (type == '1'
type == '1'Description
TRUEnever evaluated
FALSEnever evaluated
|| type == '4'
type == '4'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
70 mcc = 1;
never executed: mcc = 1;
0
71 else-
72 mcc = read_pbm_int(device);
never executed: mcc = read_pbm_int(device);
0
73-
74 if (w <= 0
w <= 0Description
TRUEnever evaluated
FALSEnever evaluated
|| w > 32767
w > 32767Description
TRUEnever evaluated
FALSEnever evaluated
|| h <= 0
h <= 0Description
TRUEnever evaluated
FALSEnever evaluated
|| h > 32767
h > 32767Description
TRUEnever evaluated
FALSEnever evaluated
|| mcc <= 0
mcc <= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
75 return
never executed: return false;
false;
never executed: return false;
0
76-
77 return
never executed: return true;
true;
never executed: return true;
0
78}-
79-
80static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, QImage *outImage)-
81{-
82 int nbits, y;-
83 int pbm_bpl;-
84 bool raw;-
85-
86 QImage::Format format;-
87 switch (type) {-
88 case
never executed: case '1':
'1':
never executed: case '1':
0
89 case
never executed: case '4':
'4':
never executed: case '4':
0
90 nbits = 1;-
91 format = QImage::Format_Mono;-
92 break;
never executed: break;
0
93 case
never executed: case '2':
'2':
never executed: case '2':
0
94 case
never executed: case '5':
'5':
never executed: case '5':
0
95 nbits = 8;-
96 format = QImage::Format_Grayscale8;-
97 break;
never executed: break;
0
98 case
never executed: case '3':
'3':
never executed: case '3':
0
99 case
never executed: case '6':
'6':
never executed: case '6':
0
100 nbits = 32;-
101 format = QImage::Format_RGB32;-
102 break;
never executed: break;
0
103 default
never executed: default:
:
never executed: default:
0
104 return
never executed: return false;
false;
never executed: return false;
0
105 }-
106 raw = type >= '4';-
107-
108 int maxc = mcc;-
109 if (maxc > 255
maxc > 255Description
TRUEnever evaluated
FALSEnever evaluated
)
0
110 maxc = 255;
never executed: maxc = 255;
0
111 if (outImage->size() != QSize(w, h)
outImage->size...!= QSize(w, h)Description
TRUEnever evaluated
FALSEnever evaluated
|| outImage->format() != format
outImage->format() != formatDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
112 *outImage = QImage(w, h, format);-
113 if (outImage->isNull()
outImage->isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
114 return
never executed: return false;
false;
never executed: return false;
0
115 }
never executed: end of block
0
116-
117 pbm_bpl = (nbits*w+7)/8;-
118-
119 if (raw
rawDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
120 if (nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
121 pbm_bpl = mcc < 256
mcc < 256Description
TRUEnever evaluated
FALSEnever evaluated
? 3*w : 6*w;
0
122 uchar *buf24 = new uchar[pbm_bpl], *b;-
123 QRgb *p;-
124 QRgb *end;-
125 for (y=0; y<h
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
126 if (device->read((char *)buf24, pbm_bpl) != pbm_bpl
device->read((...pl) != pbm_bplDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
127 delete[] buf24;-
128 return
never executed: return false;
false;
never executed: return false;
0
129 }-
130 p = (QRgb *)outImage->scanLine(y);-
131 end = p + w;-
132 b = buf24;-
133 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
134 if (mcc < 256
mcc < 256Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
135 *p++ = qRgb(b[0],b[1],b[2]);-
136 b += 3;-
137 }
never executed: end of block
else {
0
138 *p++ = qRgb(((int(b[0]) * 256 + int(b[1]) + 1) * 256) / (mcc + 1) - 1,-
139 ((int(b[2]) * 256 + int(b[3]) + 1) * 256) / (mcc + 1) - 1,-
140 ((int(b[4]) * 256 + int(b[5]) + 1) * 256) / (mcc + 1) - 1);-
141 b += 6;-
142 }
never executed: end of block
0
143 }-
144 }
never executed: end of block
0
145 delete[] buf24;-
146 }
never executed: end of block
else {
0
147 for (y=0; y<h
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
148 if (device->read((char *)outImage->scanLine(y), pbm_bpl)
device->read((...pl) != pbm_bplDescription
TRUEnever evaluated
FALSEnever evaluated
0
149 != pbm_bpl
device->read((...pl) != pbm_bplDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
150 return
never executed: return false;
false;
never executed: return false;
0
151 }
never executed: end of block
0
152 }
never executed: end of block
0
153 } else {-
154 uchar *p;-
155 int n;-
156 char buf;-
157 for (y = 0; (
(y < h)Description
TRUEnever evaluated
FALSEnever evaluated
y < h)
(y < h)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(device->peek(&buf, 1) == 1)Description
TRUEnever evaluated
FALSEnever evaluated
device->peek(&buf, 1) == 1)
(device->peek(&buf, 1) == 1)Description
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
158 p = outImage->scanLine(y);-
159 n = pbm_bpl;-
160 if (nbits == 1
nbits == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
161 int b;-
162 int bitsLeft = w;-
163 while (n--
n--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
164 b = 0;-
165 for (int i=0; i<8
i<8Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
166 if (i < bitsLeft
i < bitsLeftDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
167 b = (b << 1) | (read_pbm_int(device) & 1);
never executed: b = (b << 1) | (read_pbm_int(device) & 1);
0
168 else-
169 b = (b << 1) | (0 & 1);
never executed: b = (b << 1) | (0 & 1);
0
170 }-
171 bitsLeft -= 8;-
172 *p++ = b;-
173 }
never executed: end of block
0
174 }
never executed: end of block
else if (nbits == 8
nbits == 8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
175 if (mcc == 255
mcc == 255Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
176 while (n--
n--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
177 *p++ = read_pbm_int(device);-
178 }
never executed: end of block
0
179 }
never executed: end of block
else {
0
180 while (n--
n--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
181 *p++ = read_pbm_int(device) * 255 / mcc;-
182 }
never executed: end of block
0
183 }
never executed: end of block
0
184 } else {-
185 n /= 4;-
186 int r, g, b;-
187 if (mcc == maxc
mcc == maxcDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
188 while (n--
n--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
189 r = read_pbm_int(device);-
190 g = read_pbm_int(device);-
191 b = read_pbm_int(device);-
192 *((QRgb*)p) = qRgb(r, g, b);-
193 p += 4;-
194 }
never executed: end of block
0
195 }
never executed: end of block
else {
0
196 while (n--
n--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
197 r = read_pbm_int(device) * maxc / mcc;-
198 g = read_pbm_int(device) * maxc / mcc;-
199 b = read_pbm_int(device) * maxc / mcc;-
200 *((QRgb*)p) = qRgb(r, g, b);-
201 p += 4;-
202 }
never executed: end of block
0
203 }
never executed: end of block
0
204 }-
205 }-
206 }
never executed: end of block
0
207-
208 if (format == QImage::Format_Mono
format == QImage::Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
209 outImage->setColorCount(2);-
210 outImage->setColor(0, qRgb(255,255,255));-
211 outImage->setColor(1, qRgb(0,0,0));-
212 }
never executed: end of block
0
213-
214 return
never executed: return true;
true;
never executed: return true;
0
215}-
216-
217static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)-
218{-
219 QByteArray str;-
220 QImage image = sourceImage;-
221 QByteArray format = sourceFormat;-
222-
223 format = format.left(3);-
224 bool gray = format == "pgm";-
225-
226 if (format == "pbm"
format == "pbm"Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
227 image = image.convertToFormat(QImage::Format_Mono);-
228 }
never executed: end of block
else if (gray
grayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
229 image = image.convertToFormat(QImage::Format_Grayscale8);-
230 }
never executed: end of block
else {
0
231 switch (image.format()) {-
232 case
never executed: case QImage::Format_Mono:
QImage::Format_Mono:
never executed: case QImage::Format_Mono:
0
233 case
never executed: case QImage::Format_MonoLSB:
QImage::Format_MonoLSB:
never executed: case QImage::Format_MonoLSB:
0
234 image = image.convertToFormat(QImage::Format_Indexed8);-
235 break;
never executed: break;
0
236 case
never executed: case QImage::Format_Indexed8:
QImage::Format_Indexed8:
never executed: case QImage::Format_Indexed8:
0
237 case
never executed: case QImage::Format_RGB32:
QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
238 case
never executed: case QImage::Format_ARGB32:
QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
239 break;
never executed: break;
0
240 default
never executed: default:
:
never executed: default:
0
241 if (image.hasAlphaChannel()
image.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
242 image = image.convertToFormat(QImage::Format_ARGB32);
never executed: image = image.convertToFormat(QImage::Format_ARGB32);
0
243 else-
244 image = image.convertToFormat(QImage::Format_RGB32);
never executed: image = image.convertToFormat(QImage::Format_RGB32);
0
245 break;
never executed: break;
0
246 }-
247 }-
248-
249 if (image.depth() == 1
image.depth() == 1Description
TRUEnever evaluated
FALSEnever evaluated
&& image.colorCount() == 2
image.colorCount() == 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
250 if (qGray(image.color(0)) < qGray(image.color(1))
qGray(image.co...mage.color(1))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
251-
252 image.detach();-
253 for (int y=0; y<image.height()
y<image.height()Description
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
254 uchar *p = image.scanLine(y);-
255 uchar *end = p + image.bytesPerLine();-
256 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
257 *
never executed: *p++ ^= 0xff;
p++ ^= 0xff;
never executed: *p++ ^= 0xff;
0
258 }
never executed: end of block
0
259 }
never executed: end of block
0
260 }
never executed: end of block
0
261-
262 uint w = image.width();-
263 uint h = image.height();-
264-
265 str = "P\n";-
266 str += QByteArray::number(w);-
267 str += ' ';-
268 str += QByteArray::number(h);-
269 str += '\n';-
270-
271 switch (image.depth()) {-
272 case
never executed: case 1:
1:
never executed: case 1:
{
0
273 str.insert(1, '4');-
274 if (out->write(str, str.length()) != str.length()
out->write(str...= str.length()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
275 return
never executed: return false;
false;
never executed: return false;
0
276 w = (w+7)/8;-
277 for (uint y=0; y<h
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
278 uchar* line = image.scanLine(y);-
279 if (w != (uint)out->write((char*)line, w)
w != (uint)out...char*)line, w)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
280 return
never executed: return false;
false;
never executed: return false;
0
281 }
never executed: end of block
0
282 }-
283 break;
never executed: break;
0
284-
285 case
never executed: case 8:
8:
never executed: case 8:
{
0
286 str.insert(1, gray ? '5' : '6');-
287 str.append("255\n");-
288 if (out->write(str, str.length()) != str.length()
out->write(str...= str.length()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
289 return
never executed: return false;
false;
never executed: return false;
0
290 uint bpl = w * (gray ? 1 : 3);-
291 uchar *buf = new uchar[bpl];-
292 if (image.format() == QImage::Format_Indexed8
image.format()...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
293 QVector<QRgb> color = image.colorTable();-
294 for (uint y=0; y<h
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
295 const uchar *b = image.constScanLine(y);-
296 uchar *p = buf;-
297 uchar *end = buf+bpl;-
298 if (gray
grayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
299 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
300 uchar g = (uchar)qGray(color[*b++]);-
301 *p++ = g;-
302 }
never executed: end of block
0
303 }
never executed: end of block
else {
0
304 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
305 QRgb rgb = color[*b++];-
306 *p++ = qRed(rgb);-
307 *p++ = qGreen(rgb);-
308 *p++ = qBlue(rgb);-
309 }
never executed: end of block
0
310 }
never executed: end of block
0
311 if (bpl != (uint)out->write((char*)buf, bpl)
bpl != (uint)o...har*)buf, bpl)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
312 return
never executed: return false;
false;
never executed: return false;
0
313 }
never executed: end of block
0
314 }
never executed: end of block
else {
0
315 for (uint y=0; y<h
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
316 const uchar *b = image.constScanLine(y);-
317 uchar *p = buf;-
318 uchar *end = buf + bpl;-
319 if (gray
grayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
320 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
321 *
never executed: *p++ = *b++;
p++ = *b++;
never executed: *p++ = *b++;
0
322 }
never executed: end of block
else {
0
323 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
324 uchar color = *b++;-
325 *p++ = color;-
326 *p++ = color;-
327 *p++ = color;-
328 }
never executed: end of block
0
329 }
never executed: end of block
0
330 if (bpl != (uint)out->write((char*)buf, bpl)
bpl != (uint)o...har*)buf, bpl)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
331 return
never executed: return false;
false;
never executed: return false;
0
332 }
never executed: end of block
0
333 }
never executed: end of block
0
334 delete [] buf;-
335 break;
never executed: break;
0
336 }-
337-
338 case
never executed: case 32:
32:
never executed: case 32:
{
0
339 str.insert(1, '6');-
340 str.append("255\n");-
341 if (out->write(str, str.length()) != str.length()
out->write(str...= str.length()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
342 return
never executed: return false;
false;
never executed: return false;
0
343 uint bpl = w * 3;-
344 uchar *buf = new uchar[bpl];-
345 for (uint y=0; y<h
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
; y++) {
0
346 const QRgb *b = reinterpret_cast<const QRgb *>(image.constScanLine(y));-
347 uchar *p = buf;-
348 uchar *end = buf+bpl;-
349 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
350 QRgb rgb = *b++;-
351 *p++ = qRed(rgb);-
352 *p++ = qGreen(rgb);-
353 *p++ = qBlue(rgb);-
354 }
never executed: end of block
0
355 if (bpl != (uint)out->write((char*)buf, bpl)
bpl != (uint)o...har*)buf, bpl)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
356 return
never executed: return false;
false;
never executed: return false;
0
357 }
never executed: end of block
0
358 delete [] buf;-
359 break;
never executed: break;
0
360 }-
361-
362 default
never executed: default:
:
never executed: default:
0
363 return
never executed: return false;
false;
never executed: return false;
0
364 }-
365-
366 return
never executed: return true;
true;
never executed: return true;
0
367}-
368-
369QPpmHandler::QPpmHandler()-
370 : state(Ready)-
371{-
372}
never executed: end of block
0
373-
374bool QPpmHandler::readHeader()-
375{-
376 state = Error;-
377 if (!read_pbm_header(device(), type, width, height, mcc)
!read_pbm_head..., height, mcc)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
378 return
never executed: return false;
false;
never executed: return false;
0
379 state = ReadHeader;-
380 return
never executed: return true;
true;
never executed: return true;
0
381}-
382-
383bool QPpmHandler::canRead() const-
384{-
385 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !canRead(device(), &subType)
!canRead(device(), &subType)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
386 return
never executed: return false;
false;
never executed: return false;
0
387-
388 if (state != Error
state != ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
389 setFormat(subType);-
390 return
never executed: return true;
true;
never executed: return true;
0
391 }-
392-
393 return
never executed: return false;
false;
never executed: return false;
0
394}-
395-
396bool QPpmHandler::canRead(QIODevice *device, QByteArray *subType)-
397{-
398 if (!device
!deviceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
399 QMessageLogger(__FILE__, 442, __PRETTY_FUNCTION__).warning("QPpmHandler::canRead() called with no device");-
400 return
never executed: return false;
false;
never executed: return false;
0
401 }-
402-
403 char head[2];-
404 if (device->peek(head, sizeof(head)) != sizeof(head)
device->peek(h...= sizeof(head)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
405 return
never executed: return false;
false;
never executed: return false;
0
406-
407 if (head[0] != 'P'
head[0] != 'P'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
408 return
never executed: return false;
false;
never executed: return false;
0
409-
410 if (head[1] == '1'
head[1] == '1'Description
TRUEnever evaluated
FALSEnever evaluated
|| head[1] == '4'
head[1] == '4'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
411 if (subType
subTypeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
412 *
never executed: *subType = "pbm";
subType = "pbm";
never executed: *subType = "pbm";
0
413 }
never executed: end of block
else if (head[1] == '2'
head[1] == '2'Description
TRUEnever evaluated
FALSEnever evaluated
|| head[1] == '5'
head[1] == '5'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
414 if (subType
subTypeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
415 *
never executed: *subType = "pgm";
subType = "pgm";
never executed: *subType = "pgm";
0
416 }
never executed: end of block
else if (head[1] == '3'
head[1] == '3'Description
TRUEnever evaluated
FALSEnever evaluated
|| head[1] == '6'
head[1] == '6'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
417 if (subType
subTypeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
418 *
never executed: *subType = "ppm";
subType = "ppm";
never executed: *subType = "ppm";
0
419 }
never executed: end of block
else {
0
420 return
never executed: return false;
false;
never executed: return false;
0
421 }-
422 return
never executed: return true;
true;
never executed: return true;
0
423}-
424-
425bool QPpmHandler::read(QImage *image)-
426{-
427 if (state == Error
state == ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
428 return
never executed: return false;
false;
never executed: return false;
0
429-
430 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !readHeader()
!readHeader()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
431 state = Error;-
432 return
never executed: return false;
false;
never executed: return false;
0
433 }-
434-
435 if (!read_pbm_body(device(), type, width, height, mcc, image)
!read_pbm_body...t, mcc, image)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
436 state = Error;-
437 return
never executed: return false;
false;
never executed: return false;
0
438 }-
439-
440 state = Ready;-
441 return
never executed: return true;
true;
never executed: return true;
0
442}-
443-
444bool QPpmHandler::write(const QImage &image)-
445{-
446 return
never executed: return write_pbm_image(device(), image, subType);
write_pbm_image(device(), image, subType);
never executed: return write_pbm_image(device(), image, subType);
0
447}-
448-
449bool QPpmHandler::supportsOption(ImageOption option) const-
450{-
451 return
never executed: return option == SubType || option == Size || option == ImageFormat;
option == SubType
never executed: return option == SubType || option == Size || option == ImageFormat;
0
452 || option == Size
never executed: return option == SubType || option == Size || option == ImageFormat;
0
453 || option == ImageFormat;
never executed: return option == SubType || option == Size || option == ImageFormat;
0
454}-
455-
456QVariant QPpmHandler::option(ImageOption option) const-
457{-
458 if (option == SubType
option == SubTypeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
459 return
never executed: return subType;
subType;
never executed: return subType;
0
460 } else if (option == Size
option == SizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
461 if (state == Error
state == ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
462 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
463 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !const_cast<QPpmHandler*>(this)->readHeader()
!const_cast<QP...->readHeader()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
464 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
465 return
never executed: return QSize(width, height);
QSize(width, height);
never executed: return QSize(width, height);
0
466 } else if (option == ImageFormat
option == ImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
467 if (state == Error
state == ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
468 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
469 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !const_cast<QPpmHandler*>(this)->readHeader()
!const_cast<QP...->readHeader()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
470 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
471 QImage::Format format = QImage::Format_Invalid;-
472 switch (type) {-
473 case
never executed: case '1':
'1':
never executed: case '1':
0
474 case
never executed: case '4':
'4':
never executed: case '4':
0
475 format = QImage::Format_Mono;-
476 break;
never executed: break;
0
477 case
never executed: case '2':
'2':
never executed: case '2':
0
478 case
never executed: case '5':
'5':
never executed: case '5':
0
479 format = QImage::Format_Grayscale8;-
480 break;
never executed: break;
0
481 case
never executed: case '3':
'3':
never executed: case '3':
0
482 case
never executed: case '6':
'6':
never executed: case '6':
0
483 format = QImage::Format_RGB32;-
484 break;
never executed: break;
0
485 default
never executed: default:
:
never executed: default:
0
486 break;
never executed: break;
0
487 }-
488 return
never executed: return format;
format;
never executed: return format;
0
489 }-
490 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
491}-
492-
493void QPpmHandler::setOption(ImageOption option, const QVariant &value)-
494{-
495 if (option == SubType
option == SubTypeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
496 subType = value.toByteArray().toLower();
never executed: subType = value.toByteArray().toLower();
0
497}
never executed: end of block
0
498-
499QByteArray QPpmHandler::name() const-
500{-
501 return
never executed: return subType.isEmpty() ? QByteArray("ppm") : subType;
subType.isEmpty() ? QByteArray("ppm") : subType;
never executed: return subType.isEmpty() ? QByteArray("ppm") : subType;
0
502}-
503-
504-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9