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