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