| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| | ** | |
| | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | |
| | ** Contact: http://www.qt-project.org/legal | |
| | ** | |
| | ** This file is part of the QtGui module of the Qt Toolkit. | |
| | ** | |
| | ** $QT_BEGIN_LICENSE:LGPL$ | |
| | ** Commercial License Usage | |
| | ** Licensees holding valid commercial Qt licenses may use this file in | |
| | ** accordance with the commercial license agreement provided with the | |
| | ** Software or, alternatively, in accordance with the terms contained in | |
| | ** a written agreement between you and Digia. For licensing terms and | |
| | ** conditions see http://qt.digia.com/licensing. For further information | |
| | ** use the contact form at http://qt.digia.com/contact-us. | |
| | ** | |
| | ** GNU Lesser General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU Lesser | |
| | ** General Public License version 2.1 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.LGPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU Lesser General Public License version 2.1 requirements | |
| | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
| | ** | |
| | ** In addition, as a special exception, Digia gives you certain additional | |
| | ** rights. These rights are described in the Digia Qt LGPL Exception | |
| | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
| | ** | |
| | ** GNU General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU | |
| | ** General Public License version 3.0 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.GPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU General Public License version 3.0 requirements will be | |
| | ** met: http://www.gnu.org/copyleft/gpl.html. | |
| | ** | |
| | ** | |
| | ** $QT_END_LICENSE$ | |
| | ** | |
| | ****************************************************************************/**************************************************************************** | |
| 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/qbmphandler_p.h" | - |
| 43 | | - |
| 44 | #ifndef QT_NO_IMAGEFORMAT_BMP | - |
| 45 | | - |
| 46 | #include <qimage.h> | - |
| 47 | #include <qvariant.h> | - |
| 48 | #include <qvector.h> | - |
| 49 | | - |
| 50 | QT_BEGIN_NAMESPACE | - |
| 51 | | - |
| 52 | static void swapPixel01(QImage *image) // 1-bpp: swap 0 and 1 pixels | - |
| 53 | { | - |
| 54 | int i; | - |
| 55 | if (image->depth() == 1 && image->colorCount() == 2) { | - |
| 56 | register uint *p = (uint *)image->bits(); | - |
| 57 | int nbytes = image->byteCount(); | - |
| 58 | for (i=0; i<nbytes/4; i++) { | - |
| 59 | *p = ~*p; | - |
| 60 | p++; | - |
| 61 | } | - |
| 62 | uchar *p2 = (uchar *)p; | - |
| 63 | for (i=0; i<(nbytes&3); i++) { | - |
| 64 | *p2 = ~*p2; | - |
| 65 | p2++; | - |
| 66 | } | - |
| 67 | QRgb t = image->color(0); // swap color 0 and 1 | - |
| 68 | image->setColor(0, image->color(1)); | - |
| 69 | image->setColor(1, t); | - |
| 70 | } | - |
| 71 | } | - |
| 72 | | - |
| 73 | /* | - |
| 74 | QImageIO::defineIOHandler("BMP", "^BM", 0, | - |
| 75 | read_bmp_image, write_bmp_image); | - |
| 76 | */ | - |
| 77 | | - |
| 78 | /***************************************************************************** | - |
| 79 | BMP (DIB) image read/write functions | - |
| 80 | *****************************************************************************/ | - |
| 81 | | - |
| 82 | const int BMP_FILEHDR_SIZE = 14; // size of BMP_FILEHDR data | - |
| 83 | | - |
| 84 | static QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf) | - |
| 85 | { // read file header | - |
| 86 | s.readRawData(bf.bfType, 2); | - |
| 87 | s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits; | - |
| 88 | return s; | - |
| 89 | } | - |
| 90 | | - |
| 91 | static QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf) | - |
| 92 | { // write file header | - |
| 93 | s.writeRawData(bf.bfType, 2); | - |
| 94 | s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits; | - |
| 95 | return s; | - |
| 96 | } | - |
| 97 | | - |
| 98 | | - |
| 99 | const int BMP_OLD = 12; // old Windows/OS2 BMP size | - |
| 100 | const int BMP_WIN = 40; // Windows BMP v3 size | - |
| 101 | const int BMP_OS2 = 64; // new OS/2 BMP size | - |
| 102 | const int BMP_WIN4 = 108; // Windows BMP v4 size | - |
| 103 | const int BMP_WIN5 = 124; // Windows BMP v5 size | - |
| 104 | | - |
| 105 | const int BMP_RGB = 0; // no compression | - |
| 106 | const int BMP_RLE8 = 1; // run-length encoded, 8 bits | - |
| 107 | const int BMP_RLE4 = 2; // run-length encoded, 4 bits | - |
| 108 | const int BMP_BITFIELDS = 3; // RGB values encoded in data as bit-fields | - |
| 109 | | - |
| 110 | | - |
| 111 | static QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi) | - |
| 112 | { | - |
| 113 | s >> bi.biSize; | - |
| 114 | if (bi.biSize == BMP_WIN || bi.biSize == BMP_OS2 || bi.biSize == BMP_WIN4 || bi.biSize == BMP_WIN5) { | - |
| 115 | s >> bi.biWidth >> bi.biHeight >> bi.biPlanes >> bi.biBitCount; | - |
| 116 | s >> bi.biCompression >> bi.biSizeImage; | - |
| 117 | s >> bi.biXPelsPerMeter >> bi.biYPelsPerMeter; | - |
| 118 | s >> bi.biClrUsed >> bi.biClrImportant; | - |
| 119 | } | - |
| 120 | else { // probably old Windows format | - |
| 121 | qint16 w, h; | - |
| 122 | s >> w >> h >> bi.biPlanes >> bi.biBitCount; | - |
| 123 | bi.biWidth = w; | - |
| 124 | bi.biHeight = h; | - |
| 125 | bi.biCompression = BMP_RGB; // no compression | - |
| 126 | bi.biSizeImage = 0; | - |
| 127 | bi.biXPelsPerMeter = bi.biYPelsPerMeter = 0; | - |
| 128 | bi.biClrUsed = bi.biClrImportant = 0; | - |
| 129 | } | - |
| 130 | return s; | - |
| 131 | } | - |
| 132 | | - |
| 133 | static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi) | - |
| 134 | { | - |
| 135 | s << bi.biSize; | - |
| 136 | s << bi.biWidth << bi.biHeight; | - |
| 137 | s << bi.biPlanes; | - |
| 138 | s << bi.biBitCount; | - |
| 139 | s << bi.biCompression; | - |
| 140 | s << bi.biSizeImage; | - |
| 141 | s << bi.biXPelsPerMeter << bi.biYPelsPerMeter; | - |
| 142 | s << bi.biClrUsed << bi.biClrImportant; | - |
| 143 | return s; | - |
| 144 | } | - |
| 145 | | - |
| 146 | static int calc_shift(intuint mask) | - |
| 147 | { | - |
| 148 | int result = 0; executed (the execution status of this line is deduced): int result = 0; | - |
| 149 | while (mask && !(mask & 1)) { partially evaluated: mask| yes Evaluation Count:1321 | no Evaluation Count:0 |
evaluated: !(mask & 1)| yes Evaluation Count:1192 | yes Evaluation Count:129 |
| 0-1321 |
| 150 | result++; executed (the execution status of this line is deduced): result++; | - |
| 151 | mask >>= 1; executed (the execution status of this line is deduced): mask >>= 1; | - |
| 152 | } executed: }Execution Count:1192 | 1192 |
| 153 | return result; executed: return result;Execution Count:129 | 129 |
| 154 | } | - |
| 155 | | - |
| 156 | static bool read_dib_fileheader(QDataStream &s, BMP_FILEHDR &bf) | - |
| 157 | { | - |
| 158 | // read BMP file header | - |
| 159 | s >> bf; | - |
| 160 | if (s.status() != QDataStream::Ok) | - |
| 161 | return false; | - |
| 162 | | - |
| 163 | // check header | - |
| 164 | if (qstrncmp(bf.bfType,"BM",2) != 0) | - |
| 165 | return false; | - |
| 166 | | - |
| 167 | return true; | - |
| 168 | } | - |
| 169 | | - |
| 170 | static bool read_dib_infoheader(QDataStream &s, BMP_INFOHDR &bi) | - |
| 171 | { | - |
| 172 | s >> bi; // read BMP info header | - |
| 173 | if (s.status() != QDataStream::Ok) | - |
| 174 | return false; | - |
| 175 | | - |
| 176 | int nbits = bi.biBitCount; | - |
| 177 | int comp = bi.biCompression; | - |
| 178 | if (!(nbits == 1 || nbits == 4 || nbits == 8 || nbits == 16 || nbits == 24 || nbits == 32) || | - |
| 179 | bi.biPlanes != 1 || comp > BMP_BITFIELDS) | - |
| 180 | return false; // weird BMP image | - |
| 181 | if (!(comp == BMP_RGB || (nbits == 4 && comp == BMP_RLE4) || | - |
| 182 | (nbits == 8 && comp == BMP_RLE8) || ((nbits == 16 || nbits == 32) && comp == BMP_BITFIELDS))) | - |
| 183 | return false; // weird compression type | - |
| 184 | | - |
| 185 | return true; | - |
| 186 | } | - |
| 187 | | - |
| 188 | static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int startpos, QImage &image) | - |
| 189 | { | - |
| 190 | QIODevice* d = s.device(); executed (the execution status of this line is deduced): QIODevice* d = s.device(); | - |
| 191 | if (d->atEnd()) // end of stream/file partially evaluated: d->atEnd()| no Evaluation Count:0 | yes Evaluation Count:313 |
| 0-313 |
| 192 | return false; never executed: return false; | 0 |
| 193 | #if 0 | - |
| 194 | qDebug("offset...........%d", offset); | - |
| 195 | qDebug("startpos.........%d", startpos); | - |
| 196 | qDebug("biSize...........%d", bi.biSize); | - |
| 197 | qDebug("biWidth..........%d", bi.biWidth); | - |
| 198 | qDebug("biHeight.........%d", bi.biHeight); | - |
| 199 | qDebug("biPlanes.........%d", bi.biPlanes); | - |
| 200 | qDebug("biBitCount.......%d", bi.biBitCount); | - |
| 201 | qDebug("biCompression....%d", bi.biCompression); | - |
| 202 | qDebug("biSizeImage......%d", bi.biSizeImage); | - |
| 203 | qDebug("biXPelsPerMeter..%d", bi.biXPelsPerMeter); | - |
| 204 | qDebug("biYPelsPerMeter..%d", bi.biYPelsPerMeter); | - |
| 205 | qDebug("biClrUsed........%d", bi.biClrUsed); | - |
| 206 | qDebug("biClrImportant...%d", bi.biClrImportant); | - |
| 207 | #endif | - |
| 208 | int w = bi.biWidth, h = bi.biHeight, nbits = bi.biBitCount; executed (the execution status of this line is deduced): int w = bi.biWidth, h = bi.biHeight, nbits = bi.biBitCount; | - |
| 209 | int t = bi.biSize, comp = bi.biCompression; executed (the execution status of this line is deduced): int t = bi.biSize, comp = bi.biCompression; | - |
| 210 | intuint red_mask = 0; executed (the execution status of this line is deduced): uint red_mask = 0; | - |
| 211 | intuint green_mask = 0; executed (the execution status of this line is deduced): uint green_mask = 0; | - |
| 212 | intuint blue_mask = 0; executed (the execution status of this line is deduced): uint blue_mask = 0; | - |
| 213 | int red_shift = 0; executed (the execution status of this line is deduced): int red_shift = 0; | - |
| 214 | int green_shift = 0; executed (the execution status of this line is deduced): int green_shift = 0; | - |
| 215 | int blue_shift = 0; executed (the execution status of this line is deduced): int blue_shift = 0; | - |
| 216 | int red_scale = 0; executed (the execution status of this line is deduced): int red_scale = 0; | - |
| 217 | int green_scale = 0; executed (the execution status of this line is deduced): int green_scale = 0; | - |
| 218 | int blue_scale = 0; executed (the execution status of this line is deduced): int blue_scale = 0; | - |
| 219 | | - |
| 220 | int ncols = 0; executed (the execution status of this line is deduced): int ncols = 0; | - |
| 221 | int depth = 0; executed (the execution status of this line is deduced): int depth = 0; | - |
| 222 | QImage::Format format; executed (the execution status of this line is deduced): QImage::Format format; | - |
| 223 | switch (nbits) { | - |
| 224 | case 32: | - |
| 225 | case 24: | - |
| 226 | case 16: | - |
| 227 | depth = 32; executed (the execution status of this line is deduced): depth = 32; | - |
| 228 | format = QImage::Format_RGB32; executed (the execution status of this line is deduced): format = QImage::Format_RGB32; | - |
| 229 | break; executed: break;Execution Count:139 | 139 |
| 230 | case 8: | - |
| 231 | case 4: | - |
| 232 | depth = 8; executed (the execution status of this line is deduced): depth = 8; | - |
| 233 | format = QImage::Format_Indexed8; executed (the execution status of this line is deduced): format = QImage::Format_Indexed8; | - |
| 234 | break; executed: break;Execution Count:172 | 172 |
| 235 | default: | - |
| 236 | depth = 1; executed (the execution status of this line is deduced): depth = 1; | - |
| 237 | format = QImage::Format_Mono; executed (the execution status of this line is deduced): format = QImage::Format_Mono; | - |
| 238 | } executed: }Execution Count:2 | 2 |
| 239 | | - |
| 240 | if (bi.biHeight < 0) evaluated: bi.biHeight < 0| yes Evaluation Count:20 | yes Evaluation Count:293 |
| 20-293 |
| 241 | h = -h; // support images with negative height executed: h = -h;Execution Count:20 | 20 |
| 242 | | - |
| 243 | if (image.size() != QSize(w, h) || image.format() != format) { partially evaluated: image.size() != QSize(w, h)| yes Evaluation Count:313 | no Evaluation Count:0 |
never evaluated: image.format() != format | 0-313 |
| 244 | image = QImage(w, h, format); executed (the execution status of this line is deduced): image = QImage(w, h, format); | - |
| 245 | if (image.isNull()) // could not create image partially evaluated: image.isNull()| no Evaluation Count:0 | yes Evaluation Count:313 |
| 0-313 |
| 246 | return false; never executed: return false; | 0 |
| 247 | } executed: }Execution Count:313 | 313 |
| 248 | | - |
| 249 | if (depth != 32) { evaluated: depth != 32| yes Evaluation Count:174 | yes Evaluation Count:139 |
| 139-174 |
| 250 | ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits; evaluated: bi.biClrUsed| yes Evaluation Count:163 | yes Evaluation Count:11 |
| 11-163 |
| 251 | if (ncols > 256) // sanity check - don't run out of mem if color table is broken partially evaluated: ncols > 256| no Evaluation Count:0 | yes Evaluation Count:174 |
| 0-174 |
| 252 | return false; never executed: return false; | 0 |
| 253 | image.setColorCount(ncols); executed (the execution status of this line is deduced): image.setColorCount(ncols); | - |
| 254 | } executed: }Execution Count:174 | 174 |
| 255 | | - |
| 256 | image.setDotsPerMeterX(bi.biXPelsPerMeter); executed (the execution status of this line is deduced): image.setDotsPerMeterX(bi.biXPelsPerMeter); | - |
| 257 | image.setDotsPerMeterY(bi.biYPelsPerMeter); executed (the execution status of this line is deduced): image.setDotsPerMeterY(bi.biYPelsPerMeter); | - |
| 258 | | - |
| 259 | if (!d->isSequential()) evaluated: !d->isSequential()| yes Evaluation Count:309 | yes Evaluation Count:4 |
| 4-309 |
| 260 | d->seek(startpos + BMP_FILEHDR_SIZE + (bi.biSize >= BMP_WIN4? BMP_WIN : bi.biSize)); // goto start of colormap executed: d->seek(startpos + BMP_FILEHDR_SIZE + (bi.biSize >= BMP_WIN4? BMP_WIN : bi.biSize));Execution Count:309 | 309 |
| 261 | | - |
| 262 | if (bi.biSize >= BMP_WIN4 || (comp == BMP_BITFIELDS && (nbits == 16 || nbits == 32))) { evaluated: bi.biSize >= BMP_WIN4| yes Evaluation Count:70 | yes Evaluation Count:243 |
evaluated: comp == BMP_BITFIELDS| yes Evaluation Count:8 | yes Evaluation Count:235 |
partially evaluated: nbits == 16| no Evaluation Count:0 | yes Evaluation Count:8 |
partially evaluated: nbits == 32| yes Evaluation Count:8 | no Evaluation Count:0 |
| 0-243 |
| 263 | if (d->read((char *)&red_mask, sizeof(red_mask)) != sizeof(red_mask)) partially evaluated: d->read((char *)&red_mask, sizeof(red_mask)) != sizeof(red_mask)| no Evaluation Count:0 | yes Evaluation Count:78 |
| 0-78 |
| 264 | return false; never executed: return false; | 0 |
| 265 | if (d->read((char *)&green_mask, sizeof(green_mask)) != sizeof(green_mask)) partially evaluated: d->read((char *)&green_mask, sizeof(green_mask)) != sizeof(green_mask)| no Evaluation Count:0 | yes Evaluation Count:78 |
| 0-78 |
| 266 | return false; never executed: return false; | 0 |
| 267 | if (d->read((char *)&blue_mask, sizeof(blue_mask)) != sizeof(blue_mask)) partially evaluated: d->read((char *)&blue_mask, sizeof(blue_mask)) != sizeof(blue_mask)| no Evaluation Count:0 | yes Evaluation Count:78 |
| 0-78 |
| 268 | return false; never executed: return false; | 0 |
| 269 | | - |
| 270 | // Read BMP v4+ header | - |
| 271 | if (bi.biSize >= BMP_WIN4) { evaluated: bi.biSize >= BMP_WIN4| yes Evaluation Count:70 | yes Evaluation Count:8 |
| 8-70 |
| 272 | int alpha_mask = 0; executed (the execution status of this line is deduced): int alpha_mask = 0; | - |
| 273 | int CSType = 0; executed (the execution status of this line is deduced): int CSType = 0; | - |
| 274 | int gamma_red = 0; executed (the execution status of this line is deduced): int gamma_red = 0; | - |
| 275 | int gamma_green = 0; executed (the execution status of this line is deduced): int gamma_green = 0; | - |
| 276 | int gamma_blue = 0; executed (the execution status of this line is deduced): int gamma_blue = 0; | - |
| 277 | int endpoints[9]; executed (the execution status of this line is deduced): int endpoints[9]; | - |
| 278 | | - |
| 279 | if (d->read((char *)&alpha_mask, sizeof(alpha_mask)) != sizeof(alpha_mask)) partially evaluated: d->read((char *)&alpha_mask, sizeof(alpha_mask)) != sizeof(alpha_mask)| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 280 | return false; never executed: return false; | 0 |
| 281 | if (d->read((char *)&CSType, sizeof(CSType)) != sizeof(CSType)) partially evaluated: d->read((char *)&CSType, sizeof(CSType)) != sizeof(CSType)| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 282 | return false; never executed: return false; | 0 |
| 283 | if (d->read((char *)&endpoints, sizeof(endpoints)) != sizeof(endpoints)) partially evaluated: d->read((char *)&endpoints, sizeof(endpoints)) != sizeof(endpoints)| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 284 | return false; never executed: return false; | 0 |
| 285 | if (d->read((char *)&gamma_red, sizeof(gamma_red)) != sizeof(gamma_red)) partially evaluated: d->read((char *)&gamma_red, sizeof(gamma_red)) != sizeof(gamma_red)| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 286 | return false; never executed: return false; | 0 |
| 287 | if (d->read((char *)&gamma_green, sizeof(gamma_green)) != sizeof(gamma_green)) partially evaluated: d->read((char *)&gamma_green, sizeof(gamma_green)) != sizeof(gamma_green)| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 288 | return false; never executed: return false; | 0 |
| 289 | if (d->read((char *)&gamma_blue, sizeof(gamma_blue)) != sizeof(gamma_blue)) partially evaluated: d->read((char *)&gamma_blue, sizeof(gamma_blue)) != sizeof(gamma_blue)| no Evaluation Count:0 | yes Evaluation Count:70 |
| 0-70 |
| 290 | return false; never executed: return false; | 0 |
| 291 | | - |
| 292 | if (bi.biSize == BMP_WIN5) { evaluated: bi.biSize == BMP_WIN5| yes Evaluation Count:35 | yes Evaluation Count:35 |
| 35 |
| 293 | qint32 intent = 0; executed (the execution status of this line is deduced): qint32 intent = 0; | - |
| 294 | qint32 profileData = 0; executed (the execution status of this line is deduced): qint32 profileData = 0; | - |
| 295 | qint32 profileSize = 0; executed (the execution status of this line is deduced): qint32 profileSize = 0; | - |
| 296 | qint32 reserved = 0; executed (the execution status of this line is deduced): qint32 reserved = 0; | - |
| 297 | | - |
| 298 | if (d->read((char *)&intent, sizeof(intent)) != sizeof(intent)) partially evaluated: d->read((char *)&intent, sizeof(intent)) != sizeof(intent)| no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
| 299 | return false; never executed: return false; | 0 |
| 300 | if (d->read((char *)&profileData, sizeof(profileData)) != sizeof(profileData)) partially evaluated: d->read((char *)&profileData, sizeof(profileData)) != sizeof(profileData)| no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
| 301 | return false; never executed: return false; | 0 |
| 302 | if (d->read((char *)&profileSize, sizeof(profileSize)) != sizeof(profileSize)) partially evaluated: d->read((char *)&profileSize, sizeof(profileSize)) != sizeof(profileSize)| no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
| 303 | return false; never executed: return false; | 0 |
| 304 | if (d->read((char *)&reserved, sizeof(reserved)) != sizeof(reserved) || reserved != 0) partially evaluated: d->read((char *)&reserved, sizeof(reserved)) != sizeof(reserved)| no Evaluation Count:0 | yes Evaluation Count:35 |
partially evaluated: reserved != 0| no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
| 305 | return false; never executed: return false; | 0 |
| 306 | } executed: }Execution Count:35 | 35 |
| 307 | } executed: }Execution Count:70 | 70 |
| 308 | } executed: }Execution Count:78 | 78 |
| 309 | | - |
| 310 | if (ncols > 0) { // read color table evaluated: ncols > 0| yes Evaluation Count:174 | yes Evaluation Count:139 |
| 139-174 |
| 311 | uchar rgb[4]; executed (the execution status of this line is deduced): uchar rgb[4]; | - |
| 312 | int rgb_len = t == BMP_OLD ? 3 : 4; partially evaluated: t == BMP_OLD| no Evaluation Count:0 | yes Evaluation Count:174 |
| 0-174 |
| 313 | for (int i=0; i<ncols; i++) { evaluated: i<ncols| yes Evaluation Count:14006 | yes Evaluation Count:161 |
| 161-14006 |
| 314 | if (d->read((char *)rgb, rgb_len) != rgb_len) evaluated: d->read((char *)rgb, rgb_len) != rgb_len| yes Evaluation Count:13 | yes Evaluation Count:13993 |
| 13-13993 |
| 315 | return false; executed: return false;Execution Count:13 | 13 |
| 316 | image.setColor(i, qRgb(rgb[2],rgb[1],rgb[0])); executed (the execution status of this line is deduced): image.setColor(i, qRgb(rgb[2],rgb[1],rgb[0])); | - |
| 317 | if (d->atEnd()) // truncated file partially evaluated: d->atEnd()| no Evaluation Count:0 | yes Evaluation Count:13993 |
| 0-13993 |
| 318 | return false; never executed: return false; | 0 |
| 319 | } executed: }Execution Count:13993 | 13993 |
| 320 | } else if (comp == BMP_BITFIELDS && (nbits == 16 || nbits == 32)) { executed: }Execution Count:161 evaluated: comp == BMP_BITFIELDS| yes Evaluation Count:43 | yes Evaluation Count:96 |
partially evaluated: nbits == 16| no Evaluation Count:0 | yes Evaluation Count:43 |
partially evaluated: nbits == 32| yes Evaluation Count:43 | no Evaluation Count:0 |
| 0-161 |
| 321 | red_shift = calc_shift(red_mask); executed (the execution status of this line is deduced): red_shift = calc_shift(red_mask); | - |
| 322 | red_scale = 256 / ((red_mask >> red_shift) + 1); executed (the execution status of this line is deduced): red_scale = 256 / ((red_mask >> red_shift) + 1); | - |
| 323 | green_shift = calc_shift(green_mask); executed (the execution status of this line is deduced): green_shift = calc_shift(green_mask); | - |
| 324 | green_scale = 256 / ((green_mask >> green_shift) + 1); executed (the execution status of this line is deduced): green_scale = 256 / ((green_mask >> green_shift) + 1); | - |
| 325 | blue_shift = calc_shift(blue_mask); executed (the execution status of this line is deduced): blue_shift = calc_shift(blue_mask); | - |
| 326 | blue_scale = 256 / ((blue_mask >> blue_shift) + 1); executed (the execution status of this line is deduced): blue_scale = 256 / ((blue_mask >> blue_shift) + 1); | - |
| 327 | } else if (comp == BMP_RGB && (nbits == 24 || nbits == 32)) { executed: }Execution Count:43 partially evaluated: comp == BMP_RGB| yes Evaluation Count:96 | no Evaluation Count:0 |
evaluated: nbits == 24| yes Evaluation Count:76 | yes Evaluation Count:20 |
partially evaluated: nbits == 32| no Evaluation Count:0 | yes Evaluation Count:20 |
| 0-96 |
| 328 | blue_mask = 0x000000ff; executed (the execution status of this line is deduced): blue_mask = 0x000000ff; | - |
| 329 | green_mask = 0x0000ff00; executed (the execution status of this line is deduced): green_mask = 0x0000ff00; | - |
| 330 | red_mask = 0x00ff0000; executed (the execution status of this line is deduced): red_mask = 0x00ff0000; | - |
| 331 | blue_shift = 0; executed (the execution status of this line is deduced): blue_shift = 0; | - |
| 332 | green_shift = 8; executed (the execution status of this line is deduced): green_shift = 8; | - |
| 333 | red_shift = 16; executed (the execution status of this line is deduced): red_shift = 16; | - |
| 334 | blue_scale = green_scale = red_scale = 1; executed (the execution status of this line is deduced): blue_scale = green_scale = red_scale = 1; | - |
| 335 | } else if (comp == BMP_RGB && nbits == 16) { executed: }Execution Count:76 partially evaluated: comp == BMP_RGB| yes Evaluation Count:20 | no Evaluation Count:0 |
partially evaluated: nbits == 16| yes Evaluation Count:20 | no Evaluation Count:0 |
| 0-76 |
| 336 | blue_mask = 0x001f; executed (the execution status of this line is deduced): blue_mask = 0x001f; | - |
| 337 | green_mask = 0x03e0; executed (the execution status of this line is deduced): green_mask = 0x03e0; | - |
| 338 | red_mask = 0x7c00; executed (the execution status of this line is deduced): red_mask = 0x7c00; | - |
| 339 | blue_shift = 0; executed (the execution status of this line is deduced): blue_shift = 0; | - |
| 340 | green_shift = 2; executed (the execution status of this line is deduced): green_shift = 2; | - |
| 341 | red_shift = 7; executed (the execution status of this line is deduced): red_shift = 7; | - |
| 342 | red_scale = 1; executed (the execution status of this line is deduced): red_scale = 1; | - |
| 343 | green_scale = 1; executed (the execution status of this line is deduced): green_scale = 1; | - |
| 344 | blue_scale = 8; executed (the execution status of this line is deduced): blue_scale = 8; | - |
| 345 | } executed: }Execution Count:20 | 20 |
| 346 | | - |
| 347 | // offset can be bogus, be careful | - |
| 348 | if (offset>=0 && startpos + offset > d->pos()) { partially evaluated: offset>=0| yes Evaluation Count:300 | no Evaluation Count:0 |
partially evaluated: startpos + offset > d->pos()| no Evaluation Count:0 | yes Evaluation Count:300 |
| 0-300 |
| 349 | if (!d->isSequential()) never evaluated: !d->isSequential() | 0 |
| 350 | d->seek(startpos + offset); // start of image data never executed: d->seek(startpos + offset); | 0 |
| 351 | } | 0 |
| 352 | | - |
| 353 | int bpl = image.bytesPerLine(); executed (the execution status of this line is deduced): int bpl = image.bytesPerLine(); | - |
| 354 | uchar *data = image.bits(); executed (the execution status of this line is deduced): uchar *data = image.bits(); | - |
| 355 | | - |
| 356 | if (nbits == 1) { // 1 bit BMP image evaluated: nbits == 1| yes Evaluation Count:2 | yes Evaluation Count:298 |
| 2-298 |
| 357 | while (--h >= 0) { evaluated: --h >= 0| yes Evaluation Count:140 | yes Evaluation Count:2 |
| 2-140 |
| 358 | if (d->read((char*)(data + h*bpl), bpl) != bpl) partially evaluated: d->read((char*)(data + h*bpl), bpl) != bpl| no Evaluation Count:0 | yes Evaluation Count:140 |
| 0-140 |
| 359 | break; | 0 |
| 360 | } executed: }Execution Count:140 | 140 |
| 361 | if (ncols == 2 && qGray(image.color(0)) < qGray(image.color(1))) partially evaluated: ncols == 2| yes Evaluation Count:2 | no Evaluation Count:0 |
partially evaluated: qGray(image.color(0)) < qGray(image.color(1))| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 362 | swapPixel01(&image); // pixel 0 is white! never executed: swapPixel01(&image); | 0 |
| 363 | } executed: }Execution Count:2 | 2 |
| 364 | | - |
| 365 | else if (nbits == 4) { // 4 bit BMP image evaluated: nbits == 4| yes Evaluation Count:86 | yes Evaluation Count:212 |
| 86-212 |
| 366 | int buflen = ((w+7)/8)*4; executed (the execution status of this line is deduced): int buflen = ((w+7)/8)*4; | - |
| 367 | uchar *buf = new uchar[buflen]; executed (the execution status of this line is deduced): uchar *buf = new uchar[buflen]; | - |
| 368 | if (comp == BMP_RLE4) { // run length compression evaluated: comp == BMP_RLE4| yes Evaluation Count:33 | yes Evaluation Count:53 |
| 33-53 |
| 369 | int x=0, y=0, c, i; executed (the execution status of this line is deduced): int x=0, y=0, c, i; | - |
| 370 | quint8 b; executed (the execution status of this line is deduced): quint8 b; | - |
| 371 | register uchar *p = data + (h-1)*bpl; executed (the execution status of this line is deduced): register uchar *p = data + (h-1)*bpl; | - |
| 372 | const uchar *endp = p + w; executed (the execution status of this line is deduced): const uchar *endp = p + w; | - |
| 373 | while (y < h) { evaluated: y < h| yes Evaluation Count:185485 | yes Evaluation Count:33 |
| 33-185485 |
| 374 | if (!d->getChar((char *)&b)) partially evaluated: !d->getChar((char *)&b)| no Evaluation Count:0 | yes Evaluation Count:185485 |
| 0-185485 |
| 375 | break; | 0 |
| 376 | if (b == 0) { // escape code evaluated: b == 0| yes Evaluation Count:25398 | yes Evaluation Count:160087 |
| 25398-160087 |
| 377 | if (!d->getChar((char *)&b) || b == 1) { partially evaluated: !d->getChar((char *)&b)| no Evaluation Count:0 | yes Evaluation Count:25398 |
evaluated: b == 1| yes Evaluation Count:33 | yes Evaluation Count:25365 |
| 0-25398 |
| 378 | y = h; // exit loop executed (the execution status of this line is deduced): y = h; | - |
| 379 | } else switch (b) { executed: }Execution Count:33 | 33 |
| 380 | case 0: // end of line | - |
| 381 | x = 0; executed (the execution status of this line is deduced): x = 0; | - |
| 382 | y++; executed (the execution status of this line is deduced): y++; | - |
| 383 | p = data + (h-y-1)*bpl; executed (the execution status of this line is deduced): p = data + (h-y-1)*bpl; | - |
| 384 | break; executed: break;Execution Count:9801 | 9801 |
| 385 | case 2: // delta (jump) | - |
| 386 | { | - |
| 387 | quint8 tmp; never executed (the execution status of this line is deduced): quint8 tmp; | - |
| 388 | d->getChar((char *)&tmp); never executed (the execution status of this line is deduced): d->getChar((char *)&tmp); | - |
| 389 | x += tmp; never executed (the execution status of this line is deduced): x += tmp; | - |
| 390 | d->getChar((char *)&tmp); never executed (the execution status of this line is deduced): d->getChar((char *)&tmp); | - |
| 391 | y += tmp; never executed (the execution status of this line is deduced): y += tmp; | - |
| 392 | } | - |
| 393 | | - |
| 394 | // Protection | - |
| 395 | if ((uint)x >= (uint)w) never evaluated: (uint)x >= (uint)w | 0 |
| 396 | x = w-1; | 0 |
| 397 | if ((uint)y >= (uint)h) never evaluated: (uint)y >= (uint)h | 0 |
| 398 | y = h-1; | 0 |
| 399 | | - |
| 400 | p = data + (h-y-1)*bpl + x; never executed (the execution status of this line is deduced): p = data + (h-y-1)*bpl + x; | - |
| 401 | break; | 0 |
| 402 | default: // absolute mode | - |
| 403 | // Protection | - |
| 404 | if (p + b > endp) partially evaluated: p + b > endp| no Evaluation Count:0 | yes Evaluation Count:15564 |
| 0-15564 |
| 405 | b = endp-p; never executed: b = endp-p; | 0 |
| 406 | | - |
| 407 | i = (c = b)/2; executed (the execution status of this line is deduced): i = (c = b)/2; | - |
| 408 | while (i--) { evaluated: i--| yes Evaluation Count:94972 | yes Evaluation Count:15564 |
| 15564-94972 |
| 409 | d->getChar((char *)&b); executed (the execution status of this line is deduced): d->getChar((char *)&b); | - |
| 410 | *p++ = b >> 4; executed (the execution status of this line is deduced): *p++ = b >> 4; | - |
| 411 | *p++ = b & 0x0f; executed (the execution status of this line is deduced): *p++ = b & 0x0f; | - |
| 412 | } executed: }Execution Count:94972 | 94972 |
| 413 | if (c & 1) { evaluated: c & 1| yes Evaluation Count:13 | yes Evaluation Count:15551 |
| 13-15551 |
| 414 | unsigned char tmp; executed (the execution status of this line is deduced): unsigned char tmp; | - |
| 415 | d->getChar((char *)&tmp); executed (the execution status of this line is deduced): d->getChar((char *)&tmp); | - |
| 416 | *p++ = tmp >> 4; executed (the execution status of this line is deduced): *p++ = tmp >> 4; | - |
| 417 | } executed: }Execution Count:13 | 13 |
| 418 | if ((((c & 3) + 1) & 2) == 2) evaluated: (((c & 3) + 1) & 2) == 2| yes Evaluation Count:8253 | yes Evaluation Count:7311 |
| 7311-8253 |
| 419 | d->getChar(0); // align on word boundary executed: d->getChar(0);Execution Count:8253 | 8253 |
| 420 | x += c; | - |
| 421 | } executed: }Execution Count:15564 | 15564 |
| 422 | } else { // encoded mode | - |
| 423 | // Protection | - |
| 424 | if (p + b > endp) partially evaluated: p + b > endp| no Evaluation Count:0 | yes Evaluation Count:160087 |
| 0-160087 |
| 425 | b = endp-p; never executed: b = endp-p; | 0 |
| 426 | | - |
| 427 | i = (c = b)/2; executed (the execution status of this line is deduced): i = (c = b)/2; | - |
| 428 | d->getChar((char *)&b); // 2 pixels to be repeated executed (the execution status of this line is deduced): d->getChar((char *)&b); | - |
| 429 | while (i--) { evaluated: i--| yes Evaluation Count:2980473 | yes Evaluation Count:160087 |
| 160087-2980473 |
| 430 | *p++ = b >> 4; executed (the execution status of this line is deduced): *p++ = b >> 4; | - |
| 431 | *p++ = b & 0x0f; executed (the execution status of this line is deduced): *p++ = b & 0x0f; | - |
| 432 | } executed: }Execution Count:2980473 | 2980473 |
| 433 | if (c & 1) evaluated: c & 1| yes Evaluation Count:52 | yes Evaluation Count:160035 |
| 52-160035 |
| 434 | *p++ = b >> 4; executed: *p++ = b >> 4;Execution Count:52 | 52 |
| 435 | x += c; executed (the execution status of this line is deduced): x += c; | - |
| 436 | } executed: }Execution Count:160087 | 160087 |
| 437 | } | - |
| 438 | } else if (comp == BMP_RGB) { // no compression executed: }Execution Count:33 partially evaluated: comp == BMP_RGB| yes Evaluation Count:53 | no Evaluation Count:0 |
| 0-53 |
| 439 | memset(data, 0, h*bpl); executed (the execution status of this line is deduced): memset(data, 0, h*bpl); | - |
| 440 | while (--h >= 0) { evaluated: --h >= 0| yes Evaluation Count:666 | yes Evaluation Count:42 |
| 42-666 |
| 441 | if (d->read((char*)buf,buflen) != buflen) evaluated: d->read((char*)buf,buflen) != buflen| yes Evaluation Count:11 | yes Evaluation Count:655 |
| 11-655 |
| 442 | break; executed: break;Execution Count:11 | 11 |
| 443 | register uchar *p = data + h*bpl; executed (the execution status of this line is deduced): register uchar *p = data + h*bpl; | - |
| 444 | uchar *b = buf; executed (the execution status of this line is deduced): uchar *b = buf; | - |
| 445 | for (int i=0; i<w/2; i++) { // convert nibbles to bytes evaluated: i<w/2| yes Evaluation Count:45105 | yes Evaluation Count:655 |
| 655-45105 |
| 446 | *p++ = *b >> 4; executed (the execution status of this line is deduced): *p++ = *b >> 4; | - |
| 447 | *p++ = *b++ & 0x0f; executed (the execution status of this line is deduced): *p++ = *b++ & 0x0f; | - |
| 448 | } executed: }Execution Count:45105 | 45105 |
| 449 | if (w & 1) // the last nibble evaluated: w & 1| yes Evaluation Count:319 | yes Evaluation Count:336 |
| 319-336 |
| 450 | *p = *b >> 4; executed: *p = *b >> 4;Execution Count:319 | 319 |
| 451 | } executed: }Execution Count:655 | 655 |
| 452 | } executed: }Execution Count:53 | 53 |
| 453 | delete [] buf; executed (the execution status of this line is deduced): delete [] buf; | - |
| 454 | } executed: }Execution Count:86 | 86 |
| 455 | | - |
| 456 | else if (nbits == 8) { // 8 bit BMP image evaluated: nbits == 8| yes Evaluation Count:73 | yes Evaluation Count:139 |
| 73-139 |
| 457 | if (comp == BMP_RLE8) { // run length compression evaluated: comp == BMP_RLE8| yes Evaluation Count:20 | yes Evaluation Count:53 |
| 20-53 |
| 458 | int x=0, y=0; executed (the execution status of this line is deduced): int x=0, y=0; | - |
| 459 | quint8 b; executed (the execution status of this line is deduced): quint8 b; | - |
| 460 | register uchar *p = data + (h-1)*bpl; executed (the execution status of this line is deduced): register uchar *p = data + (h-1)*bpl; | - |
| 461 | const uchar *endp = p + w; executed (the execution status of this line is deduced): const uchar *endp = p + w; | - |
| 462 | while (y < h) { evaluated: y < h| yes Evaluation Count:455860 | yes Evaluation Count:20 |
| 20-455860 |
| 463 | if (!d->getChar((char *)&b)) partially evaluated: !d->getChar((char *)&b)| no Evaluation Count:0 | yes Evaluation Count:455860 |
| 0-455860 |
| 464 | break; | 0 |
| 465 | if (b == 0) { // escape code evaluated: b == 0| yes Evaluation Count:5600 | yes Evaluation Count:450260 |
| 5600-450260 |
| 466 | if (!d->getChar((char *)&b) || b == 1) { partially evaluated: !d->getChar((char *)&b)| no Evaluation Count:0 | yes Evaluation Count:5600 |
evaluated: b == 1| yes Evaluation Count:20 | yes Evaluation Count:5580 |
| 0-5600 |
| 467 | y = h; // exit loop executed (the execution status of this line is deduced): y = h; | - |
| 468 | } else switch (b) { executed: }Execution Count:20 | 20 |
| 469 | case 0: // end of line | - |
| 470 | x = 0; executed (the execution status of this line is deduced): x = 0; | - |
| 471 | y++; executed (the execution status of this line is deduced): y++; | - |
| 472 | p = data + (h-y-1)*bpl; executed (the execution status of this line is deduced): p = data + (h-y-1)*bpl; | - |
| 473 | break; executed: break;Execution Count:5580 | 5580 |
| 474 | case 2: // delta (jump) | - |
| 475 | // Protection | - |
| 476 | if ((uint)x >= (uint)w) never evaluated: (uint)x >= (uint)w | 0 |
| 477 | x = w-1; | 0 |
| 478 | if ((uint)y >= (uint)h) never evaluated: (uint)y >= (uint)h | 0 |
| 479 | y = h-1; | 0 |
| 480 | | - |
| 481 | { | - |
| 482 | quint8 tmp; never executed (the execution status of this line is deduced): quint8 tmp; | - |
| 483 | d->getChar((char *)&tmp); never executed (the execution status of this line is deduced): d->getChar((char *)&tmp); | - |
| 484 | x += tmp; never executed (the execution status of this line is deduced): x += tmp; | - |
| 485 | d->getChar((char *)&tmp); never executed (the execution status of this line is deduced): d->getChar((char *)&tmp); | - |
| 486 | y += tmp; never executed (the execution status of this line is deduced): y += tmp; | - |
| 487 | } | - |
| 488 | p = data + (h-y-1)*bpl + x; never executed (the execution status of this line is deduced): p = data + (h-y-1)*bpl + x; | - |
| 489 | break; | 0 |
| 490 | default: // absolute mode | - |
| 491 | // Protection | - |
| 492 | if (p + b > endp) never evaluated: p + b > endp | 0 |
| 493 | b = endp-p; never executed: b = endp-p; | 0 |
| 494 | | - |
| 495 | if (d->read((char *)p, b) != b) never evaluated: d->read((char *)p, b) != b | 0 |
| 496 | return false; never executed: return false; | 0 |
| 497 | if ((b & 1) == 1) never evaluated: (b & 1) == 1 | 0 |
| 498 | d->getChar(0); // align on word boundary never executed: d->getChar(0); | 0 |
| 499 | x += b; | - |
| 500 | p += b; | - |
| 501 | } | 0 |
| 502 | } else { // encoded mode | - |
| 503 | // Protection | - |
| 504 | if (p + b > endp) partially evaluated: p + b > endp| no Evaluation Count:0 | yes Evaluation Count:450260 |
| 0-450260 |
| 505 | b = endp-p; never executed: b = endp-p; | 0 |
| 506 | | - |
| 507 | char tmp; executed (the execution status of this line is deduced): char tmp; | - |
| 508 | d->getChar(&tmp); executed (the execution status of this line is deduced): d->getChar(&tmp); | - |
| 509 | memset(p, tmp, b); // repeat pixel executed (the execution status of this line is deduced): memset(p, tmp, b); | - |
| 510 | x += b; executed (the execution status of this line is deduced): x += b; | - |
| 511 | p += b; executed (the execution status of this line is deduced): p += b; | - |
| 512 | } executed: }Execution Count:450260 | 450260 |
| 513 | } | - |
| 514 | } else if (comp == BMP_RGB) { // uncompressed executed: }Execution Count:20 partially evaluated: comp == BMP_RGB| yes Evaluation Count:53 | no Evaluation Count:0 |
| 0-53 |
| 515 | while (--h >= 0) { evaluated: --h >= 0| yes Evaluation Count:10470 | yes Evaluation Count:53 |
| 53-10470 |
| 516 | if (d->read((char *)data + h*bpl, bpl) != bpl) partially evaluated: d->read((char *)data + h*bpl, bpl) != bpl| no Evaluation Count:0 | yes Evaluation Count:10470 |
| 0-10470 |
| 517 | break; | 0 |
| 518 | } executed: }Execution Count:10470 | 10470 |
| 519 | } executed: }Execution Count:53 | 53 |
| 520 | } | - |
| 521 | | - |
| 522 | else if (nbits == 16 || nbits == 24 || nbits == 32) { // 16,24,32 bit BMP image evaluated: nbits == 16| yes Evaluation Count:20 | yes Evaluation Count:119 |
evaluated: nbits == 24| yes Evaluation Count:76 | yes Evaluation Count:43 |
partially evaluated: nbits == 32| yes Evaluation Count:43 | no Evaluation Count:0 |
| 0-119 |
| 523 | register QRgb *p; executed (the execution status of this line is deduced): register QRgb *p; | - |
| 524 | QRgb *end; executed (the execution status of this line is deduced): QRgb *end; | - |
| 525 | uchar *buf24 = new uchar[bpl]; executed (the execution status of this line is deduced): uchar *buf24 = new uchar[bpl]; | - |
| 526 | int bpl24 = ((w*nbits+31)/32)*4; executed (the execution status of this line is deduced): int bpl24 = ((w*nbits+31)/32)*4; | - |
| 527 | uchar *b; executed (the execution status of this line is deduced): uchar *b; | - |
| 528 | int c; executed (the execution status of this line is deduced): int c; | - |
| 529 | | - |
| 530 | while (--h >= 0) { evaluated: --h >= 0| yes Evaluation Count:19736 | yes Evaluation Count:139 |
| 139-19736 |
| 531 | p = (QRgb *)(data + h*bpl); executed (the execution status of this line is deduced): p = (QRgb *)(data + h*bpl); | - |
| 532 | end = p + w; executed (the execution status of this line is deduced): end = p + w; | - |
| 533 | if (d->read((char *)buf24,bpl24) != bpl24) partially evaluated: d->read((char *)buf24,bpl24) != bpl24| no Evaluation Count:0 | yes Evaluation Count:19736 |
| 0-19736 |
| 534 | break; | 0 |
| 535 | b = buf24; executed (the execution status of this line is deduced): b = buf24; | - |
| 536 | while (p < end) { evaluated: p < end| yes Evaluation Count:6330688 | yes Evaluation Count:19736 |
| 19736-6330688 |
| 537 | c = *(uchar*)b | (*(uchar*)(b+1)<<8); executed (the execution status of this line is deduced): c = *(uchar*)b | (*(uchar*)(b+1)<<8); | - |
| 538 | if (nbits != 16) evaluated: nbits != 16| yes Evaluation Count:4794688 | yes Evaluation Count:1536000 |
| 1536000-4794688 |
| 539 | c |= *(uchar*)(b+2)<<16; executed: c |= *(uchar*)(b+2)<<16;Execution Count:4794688 | 4794688 |
| 540 | *p++ = qRgb(((c & red_mask) >> red_shift) * red_scale, executed (the execution status of this line is deduced): *p++ = qRgb(((c & red_mask) >> red_shift) * red_scale, | - |
| 541 | ((c & green_mask) >> green_shift) * green_scale, executed (the execution status of this line is deduced): ((c & green_mask) >> green_shift) * green_scale, | - |
| 542 | ((c & blue_mask) >> blue_shift) * blue_scale); executed (the execution status of this line is deduced): ((c & blue_mask) >> blue_shift) * blue_scale); | - |
| 543 | b += nbits/8; executed (the execution status of this line is deduced): b += nbits/8; | - |
| 544 | } executed: }Execution Count:6330688 | 6330688 |
| 545 | } executed: }Execution Count:19736 | 19736 |
| 546 | delete[] buf24; executed (the execution status of this line is deduced): delete[] buf24; | - |
| 547 | } executed: }Execution Count:139 | 139 |
| 548 | | - |
| 549 | if (bi.biHeight < 0) { evaluated: bi.biHeight < 0| yes Evaluation Count:20 | yes Evaluation Count:280 |
| 20-280 |
| 550 | // Flip the image | - |
| 551 | uchar *buf = new uchar[bpl]; executed (the execution status of this line is deduced): uchar *buf = new uchar[bpl]; | - |
| 552 | h = -bi.biHeight; executed (the execution status of this line is deduced): h = -bi.biHeight; | - |
| 553 | for (int y = 0; y < h/2; ++y) { evaluated: y < h/2| yes Evaluation Count:640 | yes Evaluation Count:20 |
| 20-640 |
| 554 | memcpy(buf, data + y*bpl, bpl); executed (the execution status of this line is deduced): memcpy(buf, data + y*bpl, bpl); | - |
| 555 | memcpy(data + y*bpl, data + (h-y-1)*bpl, bpl); executed (the execution status of this line is deduced): memcpy(data + y*bpl, data + (h-y-1)*bpl, bpl); | - |
| 556 | memcpy(data + (h-y-1)*bpl, buf, bpl); executed (the execution status of this line is deduced): memcpy(data + (h-y-1)*bpl, buf, bpl); | - |
| 557 | } executed: }Execution Count:640 | 640 |
| 558 | delete [] buf; executed (the execution status of this line is deduced): delete [] buf; | - |
| 559 | } executed: }Execution Count:20 | 20 |
| 560 | | - |
| 561 | return true; executed: return true;Execution Count:300 | 300 |
| 562 | } | - |
| 563 | | - |
| 564 | // this is also used in qmime_win.cpp | - |
| 565 | bool qt_write_dib(QDataStream &s, QImage image) | - |
| 566 | { | - |
| 567 | int nbits; | - |
| 568 | int bpl_bmp; | - |
| 569 | int bpl = image.bytesPerLine(); | - |
| 570 | | - |
| 571 | QIODevice* d = s.device(); | - |
| 572 | if (!d->isWritable()) | - |
| 573 | return false; | - |
| 574 | | - |
| 575 | if (image.depth() == 8 && image.colorCount() <= 16) { | - |
| 576 | bpl_bmp = (((bpl+1)/2+3)/4)*4; | - |
| 577 | nbits = 4; | - |
| 578 | } else if (image.depth() == 32) { | - |
| 579 | bpl_bmp = ((image.width()*24+31)/32)*4; | - |
| 580 | nbits = 24; | - |
| 581 | } else { | - |
| 582 | bpl_bmp = bpl; | - |
| 583 | nbits = image.depth(); | - |
| 584 | } | - |
| 585 | | - |
| 586 | BMP_INFOHDR bi; | - |
| 587 | bi.biSize = BMP_WIN; // build info header | - |
| 588 | bi.biWidth = image.width(); | - |
| 589 | bi.biHeight = image.height(); | - |
| 590 | bi.biPlanes = 1; | - |
| 591 | bi.biBitCount = nbits; | - |
| 592 | bi.biCompression = BMP_RGB; | - |
| 593 | bi.biSizeImage = bpl_bmp*image.height(); | - |
| 594 | bi.biXPelsPerMeter = image.dotsPerMeterX() ? image.dotsPerMeterX() | - |
| 595 | : 2834; // 72 dpi default | - |
| 596 | bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834; | - |
| 597 | bi.biClrUsed = image.colorCount(); | - |
| 598 | bi.biClrImportant = image.colorCount(); | - |
| 599 | s << bi; // write info header | - |
| 600 | if (s.status() != QDataStream::Ok) | - |
| 601 | return false; | - |
| 602 | | - |
| 603 | if (image.depth() != 32) { // write color table | - |
| 604 | uchar *color_table = new uchar[4*image.colorCount()]; | - |
| 605 | uchar *rgb = color_table; | - |
| 606 | QVector<QRgb> c = image.colorTable(); | - |
| 607 | for (int i=0; i<image.colorCount(); i++) { | - |
| 608 | *rgb++ = qBlue (c[i]); | - |
| 609 | *rgb++ = qGreen(c[i]); | - |
| 610 | *rgb++ = qRed (c[i]); | - |
| 611 | *rgb++ = 0; | - |
| 612 | } | - |
| 613 | if (d->write((char *)color_table, 4*image.colorCount()) == -1) { | - |
| 614 | delete [] color_table; | - |
| 615 | return false; | - |
| 616 | } | - |
| 617 | delete [] color_table; | - |
| 618 | } | - |
| 619 | | - |
| 620 | if (image.format() == QImage::Format_MonoLSB) | - |
| 621 | image = image.convertToFormat(QImage::Format_Mono); | - |
| 622 | | - |
| 623 | int y; | - |
| 624 | | - |
| 625 | if (nbits == 1 || nbits == 8) { // direct output | - |
| 626 | for (y=image.height()-1; y>=0; y--) { | - |
| 627 | if (d->write((char*)image.constScanLine(y), bpl) == -1) | - |
| 628 | return false; | - |
| 629 | } | - |
| 630 | return true; | - |
| 631 | } | - |
| 632 | | - |
| 633 | uchar *buf = new uchar[bpl_bmp]; | - |
| 634 | uchar *b, *end; | - |
| 635 | register const uchar *p; | - |
| 636 | | - |
| 637 | memset(buf, 0, bpl_bmp); | - |
| 638 | for (y=image.height()-1; y>=0; y--) { // write the image bits | - |
| 639 | if (nbits == 4) { // convert 8 -> 4 bits | - |
| 640 | p = image.constScanLine(y); | - |
| 641 | b = buf; | - |
| 642 | end = b + image.width()/2; | - |
| 643 | while (b < end) { | - |
| 644 | *b++ = (*p << 4) | (*(p+1) & 0x0f); | - |
| 645 | p += 2; | - |
| 646 | } | - |
| 647 | if (image.width() & 1) | - |
| 648 | *b = *p << 4; | - |
| 649 | } else { // 32 bits | - |
| 650 | const QRgb *p = (const QRgb *)image.constScanLine(y); | - |
| 651 | const QRgb *end = p + image.width(); | - |
| 652 | b = buf; | - |
| 653 | while (p < end) { | - |
| 654 | *b++ = qBlue(*p); | - |
| 655 | *b++ = qGreen(*p); | - |
| 656 | *b++ = qRed(*p); | - |
| 657 | p++; | - |
| 658 | } | - |
| 659 | } | - |
| 660 | if (bpl_bmp != d->write((char*)buf, bpl_bmp)) { | - |
| 661 | delete[] buf; | - |
| 662 | return false; | - |
| 663 | } | - |
| 664 | } | - |
| 665 | delete[] buf; | - |
| 666 | return true; | - |
| 667 | } | - |
| 668 | | - |
| 669 | // this is also used in qmime_win.cpp | - |
| 670 | bool qt_read_dib(QDataStream &s, QImage &image) | - |
| 671 | { | - |
| 672 | BMP_INFOHDR bi; | - |
| 673 | if (!read_dib_infoheader(s, bi)) | - |
| 674 | return false; | - |
| 675 | return read_dib_body(s, bi, -1, -BMP_FILEHDR_SIZE, image); | - |
| 676 | } | - |
| 677 | | - |
| 678 | QBmpHandler::QBmpHandler(InternalFormat fmt) : | - |
| 679 | m_format(fmt), state(Ready) | - |
| 680 | { | - |
| 681 | } | - |
| 682 | | - |
| 683 | QByteArray QBmpHandler::formatName() const | - |
| 684 | { | - |
| 685 | return m_format == BmpFormat ? "bmp" : "dib"; | - |
| 686 | } | - |
| 687 | | - |
| 688 | bool QBmpHandler::readHeader() | - |
| 689 | { | - |
| 690 | state = Error; | - |
| 691 | | - |
| 692 | QIODevice *d = device(); | - |
| 693 | QDataStream s(d); | - |
| 694 | startpos = d->pos(); | - |
| 695 | | - |
| 696 | // Intel byte order | - |
| 697 | s.setByteOrder(QDataStream::LittleEndian); | - |
| 698 | | - |
| 699 | // read BMP file header | - |
| 700 | if (m_format == BmpFormat && !read_dib_fileheader(s, fileHeader)) | - |
| 701 | return false; | - |
| 702 | | - |
| 703 | // read BMP info header | - |
| 704 | if (!read_dib_infoheader(s, infoHeader)) | - |
| 705 | return false; | - |
| 706 | | - |
| 707 | state = ReadHeader; | - |
| 708 | return true; | - |
| 709 | } | - |
| 710 | | - |
| 711 | bool QBmpHandler::canRead() const | - |
| 712 | { | - |
| 713 | if (m_format == BmpFormat && state == Ready && !canRead(device())) | - |
| 714 | return false; | - |
| 715 | | - |
| 716 | if (state != Error) { | - |
| 717 | setFormat(formatName()); | - |
| 718 | return true; | - |
| 719 | } | - |
| 720 | | - |
| 721 | return false; | - |
| 722 | } | - |
| 723 | | - |
| 724 | bool QBmpHandler::canRead(QIODevice *device) | - |
| 725 | { | - |
| 726 | if (!device) { | - |
| 727 | qWarning("QBmpHandler::canRead() called with 0 pointer"); | - |
| 728 | return false; | - |
| 729 | } | - |
| 730 | | - |
| 731 | char head[2]; | - |
| 732 | if (device->peek(head, sizeof(head)) != sizeof(head)) | - |
| 733 | return false; | - |
| 734 | | - |
| 735 | return (qstrncmp(head, "BM", 2) == 0); | - |
| 736 | } | - |
| 737 | | - |
| 738 | bool QBmpHandler::read(QImage *image) | - |
| 739 | { | - |
| 740 | if (state == Error) | - |
| 741 | return false; | - |
| 742 | | - |
| 743 | if (!image) { | - |
| 744 | qWarning("QBmpHandler::read: cannot read into null pointer"); | - |
| 745 | return false; | - |
| 746 | } | - |
| 747 | | - |
| 748 | if (state == Ready && !readHeader()) { | - |
| 749 | state = Error; | - |
| 750 | return false; | - |
| 751 | } | - |
| 752 | | - |
| 753 | QIODevice *d = device(); | - |
| 754 | QDataStream s(d); | - |
| 755 | | - |
| 756 | // Intel byte order | - |
| 757 | s.setByteOrder(QDataStream::LittleEndian); | - |
| 758 | | - |
| 759 | // read image | - |
| 760 | const bool readSuccess = m_format == BmpFormat ? | - |
| 761 | read_dib_body(s, infoHeader, fileHeader.bfOffBits, startpos, *image) : | - |
| 762 | read_dib_body(s, infoHeader, -1, startpos - BMP_FILEHDR_SIZE, *image); | - |
| 763 | if (!readSuccess) | - |
| 764 | return false; | - |
| 765 | | - |
| 766 | state = Ready; | - |
| 767 | return true; | - |
| 768 | } | - |
| 769 | | - |
| 770 | bool QBmpHandler::write(const QImage &img) | - |
| 771 | { | - |
| 772 | if (m_format == DibFormat) { | - |
| 773 | QDataStream dibStream(device()); | - |
| 774 | dibStream.setByteOrder(QDataStream::LittleEndian); // Intel byte order | - |
| 775 | return qt_write_dib(dibStream, img); | - |
| 776 | } | - |
| 777 | | - |
| 778 | QImage image; | - |
| 779 | switch (img.format()) { | - |
| 780 | case QImage::Format_ARGB8565_Premultiplied: | - |
| 781 | case QImage::Format_ARGB8555_Premultiplied: | - |
| 782 | case QImage::Format_ARGB6666_Premultiplied: | - |
| 783 | case QImage::Format_ARGB4444_Premultiplied: | - |
| 784 | image = img.convertToFormat(QImage::Format_ARGB32); | - |
| 785 | break; | - |
| 786 | case QImage::Format_RGB16: | - |
| 787 | case QImage::Format_RGB888: | - |
| 788 | case QImage::Format_RGB666: | - |
| 789 | case QImage::Format_RGB555: | - |
| 790 | case QImage::Format_RGB444: | - |
| 791 | image = img.convertToFormat(QImage::Format_RGB32); | - |
| 792 | break; | - |
| 793 | default: | - |
| 794 | image = img; | - |
| 795 | } | - |
| 796 | | - |
| 797 | QIODevice *d = device(); | - |
| 798 | QDataStream s(d); | - |
| 799 | BMP_FILEHDR bf; | - |
| 800 | int bpl_bmp; | - |
| 801 | int bpl = image.bytesPerLine(); | - |
| 802 | | - |
| 803 | // Code partially repeated in qt_write_dib | - |
| 804 | if (image.depth() == 8 && image.colorCount() <= 16) { | - |
| 805 | bpl_bmp = (((bpl+1)/2+3)/4)*4; | - |
| 806 | } else if (image.depth() == 32) { | - |
| 807 | bpl_bmp = ((image.width()*24+31)/32)*4; | - |
| 808 | } else { | - |
| 809 | bpl_bmp = bpl; | - |
| 810 | } | - |
| 811 | | - |
| 812 | // Intel byte order | - |
| 813 | s.setByteOrder(QDataStream::LittleEndian); | - |
| 814 | | - |
| 815 | // build file header | - |
| 816 | memcpy(bf.bfType, "BM", 2); | - |
| 817 | | - |
| 818 | // write file header | - |
| 819 | bf.bfReserved1 = 0; | - |
| 820 | bf.bfReserved2 = 0; | - |
| 821 | bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.colorCount() * 4; | - |
| 822 | bf.bfSize = bf.bfOffBits + bpl_bmp*image.height(); | - |
| 823 | s << bf; | - |
| 824 | | - |
| 825 | // write image | - |
| 826 | return qt_write_dib(s, image); | - |
| 827 | } | - |
| 828 | | - |
| 829 | bool QBmpHandler::supportsOption(ImageOption option) const | - |
| 830 | { | - |
| 831 | return option == Size | - |
| 832 | || option == ImageFormat; | - |
| 833 | } | - |
| 834 | | - |
| 835 | QVariant QBmpHandler::option(ImageOption option) const | - |
| 836 | { | - |
| 837 | if (option == Size) { | - |
| 838 | if (state == Error) | - |
| 839 | return QVariant(); | - |
| 840 | if (state == Ready && !const_cast<QBmpHandler*>(this)->readHeader()) | - |
| 841 | return QVariant(); | - |
| 842 | return QSize(infoHeader.biWidth, infoHeader.biHeight); | - |
| 843 | } else if (option == ImageFormat) { | - |
| 844 | if (state == Error) | - |
| 845 | return QVariant(); | - |
| 846 | if (state == Ready && !const_cast<QBmpHandler*>(this)->readHeader()) | - |
| 847 | return QVariant(); | - |
| 848 | QImage::Format format; | - |
| 849 | switch (infoHeader.biBitCount) { | - |
| 850 | case 32: | - |
| 851 | case 24: | - |
| 852 | case 16: | - |
| 853 | format = QImage::Format_RGB32; | - |
| 854 | break; | - |
| 855 | case 8: | - |
| 856 | case 4: | - |
| 857 | format = QImage::Format_Indexed8; | - |
| 858 | break; | - |
| 859 | default: | - |
| 860 | format = QImage::Format_Mono; | - |
| 861 | } | - |
| 862 | return format; | - |
| 863 | } | - |
| 864 | return QVariant(); | - |
| 865 | } | - |
| 866 | | - |
| 867 | void QBmpHandler::setOption(ImageOption option, const QVariant &value) | - |
| 868 | { | - |
| 869 | Q_UNUSED(option); | - |
| 870 | Q_UNUSED(value); | - |
| 871 | } | - |
| 872 | | - |
| 873 | QByteArray QBmpHandler::name() const | - |
| 874 | { | - |
| 875 | return formatName(); | - |
| 876 | } | - |
| 877 | | - |
| 878 | QT_END_NAMESPACE | - |
| 879 | | - |
| 880 | #endif // QT_NO_IMAGEFORMAT_BMP | - |
| 881 | | - |
| | |