image/qppmhandler.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "private/qppmhandler_p.h" -
43 -
44#ifndef QT_NO_IMAGEFORMAT_PPM -
45 -
46#include <qimage.h> -
47#include <qvariant.h> -
48#include <qvector.h> -
49#include <ctype.h> -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53/***************************************************************************** -
54 PBM/PGM/PPM (ASCII and RAW) image read/write functions -
55 *****************************************************************************/ -
56 -
57static int read_pbm_int(QIODevice *d) -
58{ -
59 char c;
executed (the execution status of this line is deduced): char c;
-
60 int val = -1;
executed (the execution status of this line is deduced): int val = -1;
-
61 bool digit;
executed (the execution status of this line is deduced): bool digit;
-
62 const int buflen = 100;
executed (the execution status of this line is deduced): const int buflen = 100;
-
63 char buf[buflen];
executed (the execution status of this line is deduced): char buf[buflen];
-
64 for (;;) {
executed (the execution status of this line is deduced): for (;;) {
-
65 if (!d->getChar(&c)) // end of file
evaluated: !d->getChar(&c)
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:28723
30-28723
66 break;
executed: break;
Execution Count:30
30
67 digit = isdigit((uchar) c);
executed (the execution status of this line is deduced): digit = isdigit((uchar) c);
-
68 if (val != -1) {
evaluated: val != -1
TRUEFALSE
yes
Evaluation Count:12133
yes
Evaluation Count:16590
12133-16590
69 if (digit) {
evaluated: digit
TRUEFALSE
yes
Evaluation Count:1835
yes
Evaluation Count:10298
1835-10298
70 val = 10*val + c - '0';
executed (the execution status of this line is deduced): val = 10*val + c - '0';
-
71 continue;
executed: continue;
Execution Count:1835
1835
72 } else { -
73 if (c == '#') // comment
partially evaluated: c == '#'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10298
0-10298
74 d->readLine(buf, buflen);
never executed: d->readLine(buf, buflen);
0
75 break;
executed: break;
Execution Count:10298
10298
76 } -
77 } -
78 if (digit) // first digit
evaluated: digit
TRUEFALSE
yes
Evaluation Count:10328
yes
Evaluation Count:6262
6262-10328
79 val = c - '0';
executed: val = c - '0';
Execution Count:10328
10328
80 else if (isspace((uchar) c))
partially evaluated: isspace((uchar) c)
TRUEFALSE
yes
Evaluation Count:6262
no
Evaluation Count:0
0-6262
81 continue;
executed: continue;
Execution Count:6262
6262
82 else if (c == '#')
never evaluated: c == '#'
0
83 (void)d->readLine(buf, buflen);
never executed: (void)d->readLine(buf, buflen);
0
84 else -
85 break;
never executed: break;
0
86 } -
87 return val;
executed: return val;
Execution Count:10328
10328
88} -
89 -
90static bool read_pbm_header(QIODevice *device, char& type, int& w, int& h, int& mcc) -
91{ -
92 char buf[3];
executed (the execution status of this line is deduced): char buf[3];
-
93 if (device->read(buf, 3) != 3) // read P[1-6]<white-space>
evaluated: device->read(buf, 3) != 3
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:231
6-231
94 return false;
executed: return false;
Execution Count:6
6
95 -
96 if (!(buf[0] == 'P' && isdigit((uchar) buf[1]) && isspace((uchar) buf[2])))
partially evaluated: buf[0] == 'P'
TRUEFALSE
yes
Evaluation Count:231
no
Evaluation Count:0
partially evaluated: isdigit((uchar) buf[1])
TRUEFALSE
yes
Evaluation Count:231
no
Evaluation Count:0
partially evaluated: isspace((uchar) buf[2])
TRUEFALSE
yes
Evaluation Count:231
no
Evaluation Count:0
0-231
97 return false;
never executed: return false;
0
98 -
99 type = buf[1];
executed (the execution status of this line is deduced): type = buf[1];
-
100 if (type < '1' || type > '6')
partially evaluated: type < '1'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
partially evaluated: type > '6'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
0-231
101 return false;
never executed: return false;
0
102 -
103 w = read_pbm_int(device); // get image width
executed (the execution status of this line is deduced): w = read_pbm_int(device);
-
104 h = read_pbm_int(device); // get image height
executed (the execution status of this line is deduced): h = read_pbm_int(device);
-
105 -
106 if (type == '1' || type == '4')
evaluated: type == '1'
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:198
evaluated: type == '4'
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:194
4-198
107 mcc = 1; // ignore max color component
executed: mcc = 1;
Execution Count:37
37
108 else -
109 mcc = read_pbm_int(device); // get max color component
executed: mcc = read_pbm_int(device);
Execution Count:194
194
110 -
111 if (w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0)
partially evaluated: w <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
partially evaluated: w > 32767
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
partially evaluated: h <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
partially evaluated: h > 32767
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
partially evaluated: mcc <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:231
0-231
112 return false; // weird P.M image
never executed: return false;
0
113 -
114 return true;
executed: return true;
Execution Count:231
231
115} -
116 -
117static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, QImage *outImage) -
118{ -
119 int nbits, y;
executed (the execution status of this line is deduced): int nbits, y;
-
120 int pbm_bpl;
executed (the execution status of this line is deduced): int pbm_bpl;
-
121 bool raw;
executed (the execution status of this line is deduced): bool raw;
-
122 -
123 QImage::Format format;
executed (the execution status of this line is deduced): QImage::Format format;
-
124 switch (type) { -
125 case '1': // ascii PBM -
126 case '4': // raw PBM -
127 nbits = 1;
executed (the execution status of this line is deduced): nbits = 1;
-
128 format = QImage::Format_Mono;
executed (the execution status of this line is deduced): format = QImage::Format_Mono;
-
129 break;
executed: break;
Execution Count:35
35
130 case '2': // ascii PGM -
131 case '5': // raw PGM -
132 nbits = 8;
executed (the execution status of this line is deduced): nbits = 8;
-
133 format = QImage::Format_Indexed8;
executed (the execution status of this line is deduced): format = QImage::Format_Indexed8;
-
134 break;
executed: break;
Execution Count:32
32
135 case '3': // ascii PPM -
136 case '6': // raw PPM -
137 nbits = 32;
executed (the execution status of this line is deduced): nbits = 32;
-
138 format = QImage::Format_RGB32;
executed (the execution status of this line is deduced): format = QImage::Format_RGB32;
-
139 break;
executed: break;
Execution Count:152
152
140 default: -
141 return false;
never executed: return false;
0
142 } -
143 raw = type >= '4';
executed (the execution status of this line is deduced): raw = type >= '4';
-
144 -
145 int maxc = mcc;
executed (the execution status of this line is deduced): int maxc = mcc;
-
146 if (maxc > 255)
evaluated: maxc > 255
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:159
60-159
147 maxc = 255;
executed: maxc = 255;
Execution Count:60
60
148 if (outImage->size() != QSize(w, h) || outImage->format() != format) {
partially evaluated: outImage->size() != QSize(w, h)
TRUEFALSE
yes
Evaluation Count:219
no
Evaluation Count:0
never evaluated: outImage->format() != format
0-219
149 *outImage = QImage(w, h, format);
executed (the execution status of this line is deduced): *outImage = QImage(w, h, format);
-
150 if (outImage->isNull())
partially evaluated: outImage->isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:219
0-219
151 return false;
never executed: return false;
0
152 }
executed: }
Execution Count:219
219
153 -
154 pbm_bpl = (nbits*w+7)/8; // bytes per scanline in PBM
executed (the execution status of this line is deduced): pbm_bpl = (nbits*w+7)/8;
-
155 -
156 if (raw) { // read raw data
evaluated: raw
TRUEFALSE
yes
Evaluation Count:126
yes
Evaluation Count:93
93-126
157 if (nbits == 32) { // type 6
evaluated: nbits == 32
TRUEFALSE
yes
Evaluation Count:121
yes
Evaluation Count:5
5-121
158 pbm_bpl = mcc < 256 ? 3*w : 6*w;
evaluated: mcc < 256
TRUEFALSE
yes
Evaluation Count:61
yes
Evaluation Count:60
60-61
159 uchar *buf24 = new uchar[pbm_bpl], *b;
executed (the execution status of this line is deduced): uchar *buf24 = new uchar[pbm_bpl], *b;
-
160 QRgb *p;
executed (the execution status of this line is deduced): QRgb *p;
-
161 QRgb *end;
executed (the execution status of this line is deduced): QRgb *end;
-
162 for (y=0; y<h; y++) {
evaluated: y<h
TRUEFALSE
yes
Evaluation Count:25996
yes
Evaluation Count:121
121-25996
163 if (device->read((char *)buf24, pbm_bpl) != pbm_bpl) {
partially evaluated: device->read((char *)buf24, pbm_bpl) != pbm_bpl
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25996
0-25996
164 delete[] buf24;
never executed (the execution status of this line is deduced): delete[] buf24;
-
165 return false;
never executed: return false;
0
166 } -
167 p = (QRgb *)outImage->scanLine(y);
executed (the execution status of this line is deduced): p = (QRgb *)outImage->scanLine(y);
-
168 end = p + w;
executed (the execution status of this line is deduced): end = p + w;
-
169 b = buf24;
executed (the execution status of this line is deduced): b = buf24;
-
170 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:8338360
yes
Evaluation Count:25996
25996-8338360
171 if (mcc < 256) {
evaluated: mcc < 256
TRUEFALSE
yes
Evaluation Count:3055660
yes
Evaluation Count:5282700
3055660-5282700
172 *p++ = qRgb(b[0],b[1],b[2]);
executed (the execution status of this line is deduced): *p++ = qRgb(b[0],b[1],b[2]);
-
173 b += 3;
executed (the execution status of this line is deduced): b += 3;
-
174 } else {
executed: }
Execution Count:3055660
3055660
175 *p++ = qRgb(((int(b[0]) * 256 + int(b[1]) + 1) * 256) / (mcc + 1) - 1,
executed (the execution status of this line is deduced): *p++ = qRgb(((int(b[0]) * 256 + int(b[1]) + 1) * 256) / (mcc + 1) - 1,
-
176 ((int(b[2]) * 256 + int(b[3]) + 1) * 256) / (mcc + 1) - 1,
executed (the execution status of this line is deduced): ((int(b[2]) * 256 + int(b[3]) + 1) * 256) / (mcc + 1) - 1,
-
177 ((int(b[4]) * 256 + int(b[5]) + 1) * 256) / (mcc + 1) - 1);
executed (the execution status of this line is deduced): ((int(b[4]) * 256 + int(b[5]) + 1) * 256) / (mcc + 1) - 1);
-
178 b += 6;
executed (the execution status of this line is deduced): b += 6;
-
179 }
executed: }
Execution Count:5282700
5282700
180 } -
181 }
executed: }
Execution Count:25996
25996
182 delete[] buf24;
executed (the execution status of this line is deduced): delete[] buf24;
-
183 } else { // type 4,5
executed: }
Execution Count:121
121
184 for (y=0; y<h; y++) {
evaluated: y<h
TRUEFALSE
yes
Evaluation Count:145
yes
Evaluation Count:5
5-145
185 if (device->read((char *)outImage->scanLine(y), pbm_bpl)
partially evaluated: device->read((char *)outImage->scanLine(y), pbm_bpl) != pbm_bpl
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:145
0-145
186 != pbm_bpl)
partially evaluated: device->read((char *)outImage->scanLine(y), pbm_bpl) != pbm_bpl
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:145
0-145
187 return false;
never executed: return false;
0
188 }
executed: }
Execution Count:145
145
189 }
executed: }
Execution Count:5
5
190 } else { // read ascii data -
191 register uchar *p;
executed (the execution status of this line is deduced): register uchar *p;
-
192 int n;
executed (the execution status of this line is deduced): int n;
-
193 for (y=0; y<h; y++) {
evaluated: y<h
TRUEFALSE
yes
Evaluation Count:527
yes
Evaluation Count:93
93-527
194 p = outImage->scanLine(y);
executed (the execution status of this line is deduced): p = outImage->scanLine(y);
-
195 n = pbm_bpl;
executed (the execution status of this line is deduced): n = pbm_bpl;
-
196 if (nbits == 1) {
evaluated: nbits == 1
TRUEFALSE
yes
Evaluation Count:186
yes
Evaluation Count:341
186-341
197 int b;
executed (the execution status of this line is deduced): int b;
-
198 int bitsLeft = w;
executed (the execution status of this line is deduced): int bitsLeft = w;
-
199 while (n--) {
evaluated: n--
TRUEFALSE
yes
Evaluation Count:372
yes
Evaluation Count:186
186-372
200 b = 0;
executed (the execution status of this line is deduced): b = 0;
-
201 for (int i=0; i<8; i++) {
evaluated: i<8
TRUEFALSE
yes
Evaluation Count:2976
yes
Evaluation Count:372
372-2976
202 if (i < bitsLeft)
partially evaluated: i < bitsLeft
TRUEFALSE
yes
Evaluation Count:2976
no
Evaluation Count:0
0-2976
203 b = (b << 1) | (read_pbm_int(device) & 1);
executed: b = (b << 1) | (read_pbm_int(device) & 1);
Execution Count:2976
2976
204 else -
205 b = (b << 1) | (0 & 1); // pad it our self if we need to
never executed: b = (b << 1) | (0 & 1);
0
206 } -
207 bitsLeft -= 8;
executed (the execution status of this line is deduced): bitsLeft -= 8;
-
208 *p++ = b;
executed (the execution status of this line is deduced): *p++ = b;
-
209 }
executed: }
Execution Count:372
372
210 } else if (nbits == 8) {
executed: }
Execution Count:186
evaluated: nbits == 8
TRUEFALSE
yes
Evaluation Count:217
yes
Evaluation Count:124
124-217
211 if (mcc == maxc) {
partially evaluated: mcc == maxc
TRUEFALSE
yes
Evaluation Count:217
no
Evaluation Count:0
0-217
212 while (n--) {
evaluated: n--
TRUEFALSE
yes
Evaluation Count:5208
yes
Evaluation Count:217
217-5208
213 *p++ = read_pbm_int(device);
executed (the execution status of this line is deduced): *p++ = read_pbm_int(device);
-
214 }
executed: }
Execution Count:5208
5208
215 } else {
executed: }
Execution Count:217
217
216 while (n--) {
never evaluated: n--
0
217 *p++ = read_pbm_int(device) * maxc / mcc;
never executed (the execution status of this line is deduced): *p++ = read_pbm_int(device) * maxc / mcc;
-
218 }
never executed: }
0
219 }
never executed: }
0
220 } else { // 32 bits -
221 n /= 4;
executed (the execution status of this line is deduced): n /= 4;
-
222 int r, g, b;
executed (the execution status of this line is deduced): int r, g, b;
-
223 if (mcc == maxc) {
partially evaluated: mcc == maxc
TRUEFALSE
yes
Evaluation Count:124
no
Evaluation Count:0
0-124
224 while (n--) {
evaluated: n--
TRUEFALSE
yes
Evaluation Count:496
yes
Evaluation Count:124
124-496
225 r = read_pbm_int(device);
executed (the execution status of this line is deduced): r = read_pbm_int(device);
-
226 g = read_pbm_int(device);
executed (the execution status of this line is deduced): g = read_pbm_int(device);
-
227 b = read_pbm_int(device);
executed (the execution status of this line is deduced): b = read_pbm_int(device);
-
228 *((QRgb*)p) = qRgb(r, g, b);
executed (the execution status of this line is deduced): *((QRgb*)p) = qRgb(r, g, b);
-
229 p += 4;
executed (the execution status of this line is deduced): p += 4;
-
230 }
executed: }
Execution Count:496
496
231 } else {
executed: }
Execution Count:124
124
232 while (n--) {
never evaluated: n--
0
233 r = read_pbm_int(device) * maxc / mcc;
never executed (the execution status of this line is deduced): r = read_pbm_int(device) * maxc / mcc;
-
234 g = read_pbm_int(device) * maxc / mcc;
never executed (the execution status of this line is deduced): g = read_pbm_int(device) * maxc / mcc;
-
235 b = read_pbm_int(device) * maxc / mcc;
never executed (the execution status of this line is deduced): b = read_pbm_int(device) * maxc / mcc;
-
236 *((QRgb*)p) = qRgb(r, g, b);
never executed (the execution status of this line is deduced): *((QRgb*)p) = qRgb(r, g, b);
-
237 p += 4;
never executed (the execution status of this line is deduced): p += 4;
-
238 }
never executed: }
0
239 }
never executed: }
0
240 } -
241 } -
242 }
executed: }
Execution Count:93
93
243 -
244 if (nbits == 1) { // bitmap
evaluated: nbits == 1
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:184
35-184
245 outImage->setColorCount(2);
executed (the execution status of this line is deduced): outImage->setColorCount(2);
-
246 outImage->setColor(0, qRgb(255,255,255)); // white
executed (the execution status of this line is deduced): outImage->setColor(0, qRgb(255,255,255));
-
247 outImage->setColor(1, qRgb(0,0,0)); // black
executed (the execution status of this line is deduced): outImage->setColor(1, qRgb(0,0,0));
-
248 } else if (nbits == 8) { // graymap
executed: }
Execution Count:35
evaluated: nbits == 8
TRUEFALSE
yes
Evaluation Count:32
yes
Evaluation Count:152
32-152
249 outImage->setColorCount(maxc+1);
executed (the execution status of this line is deduced): outImage->setColorCount(maxc+1);
-
250 for (int i=0; i<=maxc; i++)
evaluated: i<=maxc
TRUEFALSE
yes
Evaluation Count:752
yes
Evaluation Count:32
32-752
251 outImage->setColor(i, qRgb(i*255/maxc,i*255/maxc,i*255/maxc));
executed: outImage->setColor(i, qRgb(i*255/maxc,i*255/maxc,i*255/maxc));
Execution Count:752
752
252 }
executed: }
Execution Count:32
32
253 -
254 return true;
executed: return true;
Execution Count:219
219
255} -
256 -
257static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat) -
258{ -
259 QByteArray str;
executed (the execution status of this line is deduced): QByteArray str;
-
260 QImage image = sourceImage;
executed (the execution status of this line is deduced): QImage image = sourceImage;
-
261 QByteArray format = sourceFormat;
executed (the execution status of this line is deduced): QByteArray format = sourceFormat;
-
262 -
263 format = format.left(3); // ignore RAW part
executed (the execution status of this line is deduced): format = format.left(3);
-
264 bool gray = format == "pgm";
executed (the execution status of this line is deduced): bool gray = format == "pgm";
-
265 -
266 if (format == "pbm") {
evaluated: format == "pbm"
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22
3-22
267 image = image.convertToFormat(QImage::Format_Mono);
executed (the execution status of this line is deduced): image = image.convertToFormat(QImage::Format_Mono);
-
268 } else if (image.depth() == 1) {
executed: }
Execution Count:3
evaluated: image.depth() == 1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:20
2-20
269 image = image.convertToFormat(QImage::Format_Indexed8);
executed (the execution status of this line is deduced): image = image.convertToFormat(QImage::Format_Indexed8);
-
270 } else {
executed: }
Execution Count:2
2
271 switch (image.format()) { -
272 case QImage::Format_RGB16: -
273 case QImage::Format_RGB666: -
274 case QImage::Format_RGB555: -
275 case QImage::Format_RGB888: -
276 case QImage::Format_RGB444: -
277 image = image.convertToFormat(QImage::Format_RGB32);
executed (the execution status of this line is deduced): image = image.convertToFormat(QImage::Format_RGB32);
-
278 break;
executed: break;
Execution Count:5
5
279 case QImage::Format_ARGB8565_Premultiplied: -
280 case QImage::Format_ARGB6666_Premultiplied: -
281 case QImage::Format_ARGB8555_Premultiplied: -
282 case QImage::Format_ARGB4444_Premultiplied: -
283 image = image.convertToFormat(QImage::Format_ARGB32);
executed (the execution status of this line is deduced): image = image.convertToFormat(QImage::Format_ARGB32);
-
284 break;
executed: break;
Execution Count:4
4
285 default: -
286 break;
executed: break;
Execution Count:11
11
287 } -
288 }
executed: }
Execution Count:20
20
289 -
290 if (image.depth() == 1 && image.colorCount() == 2) {
evaluated: image.depth() == 1
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22
partially evaluated: image.colorCount() == 2
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-22
291 if (qGray(image.color(0)) < qGray(image.color(1))) {
partially evaluated: qGray(image.color(0)) < qGray(image.color(1))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
292 // 0=dark/black, 1=light/white - invert -
293 image.detach();
never executed (the execution status of this line is deduced): image.detach();
-
294 for (int y=0; y<image.height(); y++) {
never evaluated: y<image.height()
0
295 uchar *p = image.scanLine(y);
never executed (the execution status of this line is deduced): uchar *p = image.scanLine(y);
-
296 uchar *end = p + image.bytesPerLine();
never executed (the execution status of this line is deduced): uchar *end = p + image.bytesPerLine();
-
297 while (p < end)
never evaluated: p < end
0
298 *p++ ^= 0xff;
never executed: *p++ ^= 0xff;
0
299 }
never executed: }
0
300 }
never executed: }
0
301 }
executed: }
Execution Count:3
3
302 -
303 uint w = image.width();
executed (the execution status of this line is deduced): uint w = image.width();
-
304 uint h = image.height();
executed (the execution status of this line is deduced): uint h = image.height();
-
305 -
306 str = "P\n";
executed (the execution status of this line is deduced): str = "P\n";
-
307 str += QByteArray::number(w);
executed (the execution status of this line is deduced): str += QByteArray::number(w);
-
308 str += ' ';
executed (the execution status of this line is deduced): str += ' ';
-
309 str += QByteArray::number(h);
executed (the execution status of this line is deduced): str += QByteArray::number(h);
-
310 str += '\n';
executed (the execution status of this line is deduced): str += '\n';
-
311 -
312 switch (image.depth()) { -
313 case 1: { -
314 str.insert(1, '4');
executed (the execution status of this line is deduced): str.insert(1, '4');
-
315 if (out->write(str, str.length()) != str.length())
partially evaluated: out->write(str, str.length()) != str.length()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
316 return false;
never executed: return false;
0
317 w = (w+7)/8;
executed (the execution status of this line is deduced): w = (w+7)/8;
-
318 for (uint y=0; y<h; y++) {
evaluated: y<h
TRUEFALSE
yes
Evaluation Count:104
yes
Evaluation Count:3
3-104
319 uchar* line = image.scanLine(y);
executed (the execution status of this line is deduced): uchar* line = image.scanLine(y);
-
320 if (w != (uint)out->write((char*)line, w))
partially evaluated: w != (uint)out->write((char*)line, w)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:104
0-104
321 return false;
never executed: return false;
0
322 }
executed: }
Execution Count:104
104
323 } -
324 break;
executed: break;
Execution Count:3
3
325 -
326 case 8: { -
327 str.insert(1, gray ? '5' : '6');
executed (the execution status of this line is deduced): str.insert(1, gray ? '5' : '6');
-
328 str.append("255\n");
executed (the execution status of this line is deduced): str.append("255\n");
-
329 if (out->write(str, str.length()) != str.length())
partially evaluated: out->write(str, str.length()) != str.length()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
330 return false;
never executed: return false;
0
331 QVector<QRgb> color = image.colorTable();
executed (the execution status of this line is deduced): QVector<QRgb> color = image.colorTable();
-
332 uint bpl = w*(gray ? 1 : 3);
executed (the execution status of this line is deduced): uint bpl = w*(gray ? 1 : 3);
-
333 uchar *buf = new uchar[bpl];
executed (the execution status of this line is deduced): uchar *buf = new uchar[bpl];
-
334 for (uint y=0; y<h; y++) {
evaluated: y<h
TRUEFALSE
yes
Evaluation Count:217
yes
Evaluation Count:4
4-217
335 uchar *b = image.scanLine(y);
executed (the execution status of this line is deduced): uchar *b = image.scanLine(y);
-
336 uchar *p = buf;
executed (the execution status of this line is deduced): uchar *p = buf;
-
337 uchar *end = buf+bpl;
executed (the execution status of this line is deduced): uchar *end = buf+bpl;
-
338 if (gray) {
evaluated: gray
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:210
7-210
339 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:168
yes
Evaluation Count:7
7-168
340 uchar g = (uchar)qGray(color[*b++]);
executed (the execution status of this line is deduced): uchar g = (uchar)qGray(color[*b++]);
-
341 *p++ = g;
executed (the execution status of this line is deduced): *p++ = g;
-
342 }
executed: }
Execution Count:168
168
343 } else {
executed: }
Execution Count:7
7
344 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:14700
yes
Evaluation Count:210
210-14700
345 QRgb rgb = color[*b++];
executed (the execution status of this line is deduced): QRgb rgb = color[*b++];
-
346 *p++ = qRed(rgb);
executed (the execution status of this line is deduced): *p++ = qRed(rgb);
-
347 *p++ = qGreen(rgb);
executed (the execution status of this line is deduced): *p++ = qGreen(rgb);
-
348 *p++ = qBlue(rgb);
executed (the execution status of this line is deduced): *p++ = qBlue(rgb);
-
349 }
executed: }
Execution Count:14700
14700
350 }
executed: }
Execution Count:210
210
351 if (bpl != (uint)out->write((char*)buf, bpl))
partially evaluated: bpl != (uint)out->write((char*)buf, bpl)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:217
0-217
352 return false;
never executed: return false;
0
353 }
executed: }
Execution Count:217
217
354 delete [] buf;
executed (the execution status of this line is deduced): delete [] buf;
-
355 } -
356 break;
executed: break;
Execution Count:4
4
357 -
358 case 32: { -
359 str.insert(1, gray ? '5' : '6');
executed (the execution status of this line is deduced): str.insert(1, gray ? '5' : '6');
-
360 str.append("255\n");
executed (the execution status of this line is deduced): str.append("255\n");
-
361 if (out->write(str, str.length()) != str.length())
partially evaluated: out->write(str, str.length()) != str.length()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
362 return false;
never executed: return false;
0
363 uint bpl = w*(gray ? 1 : 3);
executed (the execution status of this line is deduced): uint bpl = w*(gray ? 1 : 3);
-
364 uchar *buf = new uchar[bpl];
executed (the execution status of this line is deduced): uchar *buf = new uchar[bpl];
-
365 for (uint y=0; y<h; y++) {
evaluated: y<h
TRUEFALSE
yes
Evaluation Count:2076
yes
Evaluation Count:18
18-2076
366 QRgb *b = (QRgb*)image.scanLine(y);
executed (the execution status of this line is deduced): QRgb *b = (QRgb*)image.scanLine(y);
-
367 uchar *p = buf;
executed (the execution status of this line is deduced): uchar *p = buf;
-
368 uchar *end = buf+bpl;
executed (the execution status of this line is deduced): uchar *end = buf+bpl;
-
369 if (gray) {
partially evaluated: gray
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2076
0-2076
370 while (p < end) {
never evaluated: p < end
0
371 uchar g = (uchar)qGray(*b++);
never executed (the execution status of this line is deduced): uchar g = (uchar)qGray(*b++);
-
372 *p++ = g;
never executed (the execution status of this line is deduced): *p++ = g;
-
373 }
never executed: }
0
374 } else {
never executed: }
0
375 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:419520
yes
Evaluation Count:2076
2076-419520
376 QRgb rgb = *b++;
executed (the execution status of this line is deduced): QRgb rgb = *b++;
-
377 *p++ = qRed(rgb);
executed (the execution status of this line is deduced): *p++ = qRed(rgb);
-
378 *p++ = qGreen(rgb);
executed (the execution status of this line is deduced): *p++ = qGreen(rgb);
-
379 *p++ = qBlue(rgb);
executed (the execution status of this line is deduced): *p++ = qBlue(rgb);
-
380 }
executed: }
Execution Count:419520
419520
381 }
executed: }
Execution Count:2076
2076
382 if (bpl != (uint)out->write((char*)buf, bpl))
partially evaluated: bpl != (uint)out->write((char*)buf, bpl)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2076
0-2076
383 return false;
never executed: return false;
0
384 }
executed: }
Execution Count:2076
2076
385 delete [] buf;
executed (the execution status of this line is deduced): delete [] buf;
-
386 } -
387 break;
executed: break;
Execution Count:18
18
388 -
389 default: -
390 return false;
never executed: return false;
0
391 } -
392 -
393 return true;
executed: return true;
Execution Count:25
25
394} -
395 -
396QPpmHandler::QPpmHandler() -
397 : state(Ready) -
398{ -
399}
executed: }
Execution Count:278
278
400 -
401bool QPpmHandler::readHeader() -
402{ -
403 state = Error;
executed (the execution status of this line is deduced): state = Error;
-
404 if (!read_pbm_header(device(), type, width, height, mcc))
evaluated: !read_pbm_header(device(), type, width, height, mcc)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:231
6-231
405 return false;
executed: return false;
Execution Count:6
6
406 state = ReadHeader;
executed (the execution status of this line is deduced): state = ReadHeader;
-
407 return true;
executed: return true;
Execution Count:231
231
408} -
409 -
410bool QPpmHandler::canRead() const -
411{ -
412 if (state == Ready && !canRead(device(), &subType))
evaluated: state == Ready
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:12
evaluated: !canRead(device(), &subType)
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:82
12-97
413 return false;
executed: return false;
Execution Count:15
15
414 -
415 if (state != Error) {
partially evaluated: state != Error
TRUEFALSE
yes
Evaluation Count:94
no
Evaluation Count:0
0-94
416 setFormat(subType);
executed (the execution status of this line is deduced): setFormat(subType);
-
417 return true;
executed: return true;
Execution Count:94
94
418 } -
419 -
420 return false;
never executed: return false;
0
421} -
422 -
423bool QPpmHandler::canRead(QIODevice *device, QByteArray *subType) -
424{ -
425 if (!device) {
partially evaluated: !device
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:244
0-244
426 qWarning("QPpmHandler::canRead() called with no device");
never executed (the execution status of this line is deduced): QMessageLogger("image/qppmhandler.cpp", 426, __PRETTY_FUNCTION__).warning("QPpmHandler::canRead() called with no device");
-
427 return false;
never executed: return false;
0
428 } -
429 -
430 char head[2];
executed (the execution status of this line is deduced): char head[2];
-
431 if (device->peek(head, sizeof(head)) != sizeof(head))
evaluated: device->peek(head, sizeof(head)) != sizeof(head)
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:226
18-226
432 return false;
executed: return false;
Execution Count:18
18
433 -
434 if (head[0] != 'P')
evaluated: head[0] != 'P'
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:130
96-130
435 return false;
executed: return false;
Execution Count:96
96
436 -
437 if (head[1] == '1' || head[1] == '4') {
evaluated: head[1] == '1'
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:102
evaluated: head[1] == '4'
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:98
4-102
438 if (subType)
partially evaluated: subType
TRUEFALSE
yes
Evaluation Count:32
no
Evaluation Count:0
0-32
439 *subType = "pbm";
executed: *subType = "pbm";
Execution Count:32
32
440 } else if (head[1] == '2' || head[1] == '5') {
executed: }
Execution Count:32
evaluated: head[1] == '2'
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:70
evaluated: head[1] == '5'
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:68
2-70
441 if (subType)
partially evaluated: subType
TRUEFALSE
yes
Evaluation Count:30
no
Evaluation Count:0
0-30
442 *subType = "pgm";
executed: *subType = "pgm";
Execution Count:30
30
443 } else if (head[1] == '3' || head[1] == '6') {
executed: }
Execution Count:30
evaluated: head[1] == '3'
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:40
partially evaluated: head[1] == '6'
TRUEFALSE
yes
Evaluation Count:40
no
Evaluation Count:0
0-40
444 if (subType)
partially evaluated: subType
TRUEFALSE
yes
Evaluation Count:68
no
Evaluation Count:0
0-68
445 *subType = "ppm";
executed: *subType = "ppm";
Execution Count:68
68
446 } else {
executed: }
Execution Count:68
68
447 return false;
never executed: return false;
0
448 } -
449 return true;
executed: return true;
Execution Count:130
130
450} -
451 -
452bool QPpmHandler::read(QImage *image) -
453{ -
454 if (state == Error)
partially evaluated: state == Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:225
0-225
455 return false;
never executed: return false;
0
456 -
457 if (state == Ready && !readHeader()) {
evaluated: state == Ready
TRUEFALSE
yes
Evaluation Count:219
yes
Evaluation Count:6
evaluated: !readHeader()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:213
6-219
458 state = Error;
executed (the execution status of this line is deduced): state = Error;
-
459 return false;
executed: return false;
Execution Count:6
6
460 } -
461 -
462 if (!read_pbm_body(device(), type, width, height, mcc, image)) {
partially evaluated: !read_pbm_body(device(), type, width, height, mcc, image)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:219
0-219
463 state = Error;
never executed (the execution status of this line is deduced): state = Error;
-
464 return false;
never executed: return false;
0
465 } -
466 -
467 state = Ready;
executed (the execution status of this line is deduced): state = Ready;
-
468 return true;
executed: return true;
Execution Count:219
219
469} -
470 -
471bool QPpmHandler::write(const QImage &image) -
472{ -
473 return write_pbm_image(device(), image, subType);
executed: return write_pbm_image(device(), image, subType);
Execution Count:25
25
474} -
475 -
476bool QPpmHandler::supportsOption(ImageOption option) const -
477{ -
478 return option == SubType
executed: return option == SubType || option == Size || option == ImageFormat;
Execution Count:1664
1664
479 || option == Size
executed: return option == SubType || option == Size || option == ImageFormat;
Execution Count:1664
1664
480 || option == ImageFormat;
executed: return option == SubType || option == Size || option == ImageFormat;
Execution Count:1664
1664
481} -
482 -
483QVariant QPpmHandler::option(ImageOption option) const -
484{ -
485 if (option == SubType) {
partially evaluated: option == SubType
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
486 return subType;
never executed: return subType;
0
487 } else if (option == Size) {
evaluated: option == Size
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:6
6-12
488 if (state == Error)
partially evaluated: state == Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
489 return QVariant();
never executed: return QVariant();
0
490 if (state == Ready && !const_cast<QPpmHandler*>(this)->readHeader())
partially evaluated: state == Ready
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
partially evaluated: !const_cast<QPpmHandler*>(this)->readHeader()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
491 return QVariant();
never executed: return QVariant();
0
492 return QSize(width, height);
executed: return QSize(width, height);
Execution Count:12
12
493 } else if (option == ImageFormat) {
partially evaluated: option == ImageFormat
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
494 if (state == Error)
partially evaluated: state == Error
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
495 return QVariant();
never executed: return QVariant();
0
496 if (state == Ready && !const_cast<QPpmHandler*>(this)->readHeader())
partially evaluated: state == Ready
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
partially evaluated: !const_cast<QPpmHandler*>(this)->readHeader()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
497 return QVariant();
never executed: return QVariant();
0
498 QImage::Format format = QImage::Format_Invalid;
executed (the execution status of this line is deduced): QImage::Format format = QImage::Format_Invalid;
-
499 switch (type) { -
500 case '1': // ascii PBM -
501 case '4': // raw PBM -
502 format = QImage::Format_Mono;
executed (the execution status of this line is deduced): format = QImage::Format_Mono;
-
503 break;
executed: break;
Execution Count:1
1
504 case '2': // ascii PGM -
505 case '5': // raw PGM -
506 format = QImage::Format_Indexed8;
executed (the execution status of this line is deduced): format = QImage::Format_Indexed8;
-
507 break;
executed: break;
Execution Count:1
1
508 case '3': // ascii PPM -
509 case '6': // raw PPM -
510 format = QImage::Format_RGB32;
executed (the execution status of this line is deduced): format = QImage::Format_RGB32;
-
511 break;
executed: break;
Execution Count:4
4
512 default: -
513 break;
never executed: break;
0
514 } -
515 return format;
executed: return format;
Execution Count:6
6
516 } -
517 return QVariant();
never executed: return QVariant();
0
518} -
519 -
520void QPpmHandler::setOption(ImageOption option, const QVariant &value) -
521{ -
522 if (option == SubType)
partially evaluated: option == SubType
TRUEFALSE
yes
Evaluation Count:278
no
Evaluation Count:0
0-278
523 subType = value.toByteArray().toLower();
executed: subType = value.toByteArray().toLower();
Execution Count:278
278
524}
executed: }
Execution Count:278
278
525 -
526QByteArray QPpmHandler::name() const -
527{ -
528 return subType.isEmpty() ? QByteArray("ppm") : subType;
never executed: return subType.isEmpty() ? QByteArray("ppm") : subType;
0
529} -
530 -
531QT_END_NAMESPACE -
532 -
533#endif // QT_NO_IMAGEFORMAT_PPM -
534 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial