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