qbmphandler.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qbmphandler.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static void swapPixel01(QImage *image)-
8{-
9 int i;-
10 if (image->depth() == 1
image->depth() == 1Description
TRUEnever evaluated
FALSEnever evaluated
&& image->colorCount() == 2
image->colorCount() == 2Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
11 uint *p = (uint *)image->bits();-
12 int nbytes = image->byteCount();-
13 for (i=0; i<nbytes/4
i<nbytes/4Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
14 *p = ~*p;-
15 p++;-
16 }
never executed: end of block
0
17 uchar *p2 = (uchar *)p;-
18 for (i=0; i<(nbytes&3)
i<(nbytes&3)Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
19 *p2 = ~*p2;-
20 p2++;-
21 }
never executed: end of block
0
22 QRgb t = image->color(0);-
23 image->setColor(0, image->color(1));-
24 image->setColor(1, t);-
25 }
never executed: end of block
0
26}
never executed: end of block
0
27const int BMP_FILEHDR_SIZE = 14;-
28-
29static QDataStream &operator>>(QDataStream &s, BMP_FILEHDR &bf)-
30{-
31 s.readRawData(bf.bfType, 2);-
32 s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits;-
33 return
never executed: return s;
s;
never executed: return s;
0
34}-
35-
36static QDataStream &operator<<(QDataStream &s, const BMP_FILEHDR &bf)-
37{-
38 s.writeRawData(bf.bfType, 2);-
39 s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits;-
40 return
never executed: return s;
s;
never executed: return s;
0
41}-
42-
43-
44const int BMP_OLD = 12;-
45const int BMP_WIN = 40;-
46const int BMP_OS2 = 64;-
47const int BMP_WIN4 = 108;-
48const int BMP_WIN5 = 124;-
49-
50const int BMP_RGB = 0;-
51const int BMP_RLE8 = 1;-
52const int BMP_RLE4 = 2;-
53const int BMP_BITFIELDS = 3;-
54-
55-
56static QDataStream &operator>>(QDataStream &s, BMP_INFOHDR &bi)-
57{-
58 s >> bi.biSize;-
59 if (bi.biSize == BMP_WIN
bi.biSize == BMP_WINDescription
TRUEnever evaluated
FALSEnever evaluated
|| bi.biSize == BMP_OS2
bi.biSize == BMP_OS2Description
TRUEnever evaluated
FALSEnever evaluated
|| bi.biSize == BMP_WIN4
bi.biSize == BMP_WIN4Description
TRUEnever evaluated
FALSEnever evaluated
|| bi.biSize == BMP_WIN5
bi.biSize == BMP_WIN5Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
60 s >> bi.biWidth >> bi.biHeight >> bi.biPlanes >> bi.biBitCount;-
61 s >> bi.biCompression >> bi.biSizeImage;-
62 s >> bi.biXPelsPerMeter >> bi.biYPelsPerMeter;-
63 s >> bi.biClrUsed >> bi.biClrImportant;-
64 }
never executed: end of block
0
65 else {-
66 qint16 w, h;-
67 s >> w >> h >> bi.biPlanes >> bi.biBitCount;-
68 bi.biWidth = w;-
69 bi.biHeight = h;-
70 bi.biCompression = BMP_RGB;-
71 bi.biSizeImage = 0;-
72 bi.biXPelsPerMeter = bi.biYPelsPerMeter = 0;-
73 bi.biClrUsed = bi.biClrImportant = 0;-
74 }
never executed: end of block
0
75 return
never executed: return s;
s;
never executed: return s;
0
76}-
77-
78static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)-
79{-
80 s << bi.biSize;-
81 s << bi.biWidth << bi.biHeight;-
82 s << bi.biPlanes;-
83 s << bi.biBitCount;-
84 s << bi.biCompression;-
85 s << bi.biSizeImage;-
86 s << bi.biXPelsPerMeter << bi.biYPelsPerMeter;-
87 s << bi.biClrUsed << bi.biClrImportant;-
88 return
never executed: return s;
s;
never executed: return s;
0
89}-
90-
91static int calc_shift(uint mask)-
92{-
93 int result = 0;-
94 while (mask
maskDescription
TRUEnever evaluated
FALSEnever evaluated
&& !(mask & 1)
!(mask & 1)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
95 result++;-
96 mask >>= 1;-
97 }
never executed: end of block
0
98 return
never executed: return result;
result;
never executed: return result;
0
99}-
100-
101static bool read_dib_fileheader(QDataStream &s, BMP_FILEHDR &bf)-
102{-
103-
104 s >> bf;-
105 if (s.status() != QDataStream::Ok
s.status() != QDataStream::OkDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
106 return
never executed: return false;
false;
never executed: return false;
0
107-
108-
109 if (qstrncmp(bf.bfType,"BM",2) != 0
qstrncmp(bf.bf...e,"BM",2) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
110 return
never executed: return false;
false;
never executed: return false;
0
111-
112 return
never executed: return true;
true;
never executed: return true;
0
113}-
114-
115static bool read_dib_infoheader(QDataStream &s, BMP_INFOHDR &bi)-
116{-
117 s >> bi;-
118 if (s.status() != QDataStream::Ok
s.status() != QDataStream::OkDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
119 return
never executed: return false;
false;
never executed: return false;
0
120-
121 int nbits = bi.biBitCount;-
122 int comp = bi.biCompression;-
123 if (!(nbits == 1
nbits == 1Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 4
nbits == 4Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 8
nbits == 8Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 16
nbits == 16Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 24
nbits == 24Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
) ||
0
124 bi.biPlanes != 1
bi.biPlanes != 1Description
TRUEnever evaluated
FALSEnever evaluated
|| comp > BMP_BITFIELDS
comp > BMP_BITFIELDSDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
125 return
never executed: return false;
false;
never executed: return false;
0
126 if (!(comp == BMP_RGB
comp == BMP_RGBDescription
TRUEnever evaluated
FALSEnever evaluated
|| (nbits == 4
nbits == 4Description
TRUEnever evaluated
FALSEnever evaluated
&& comp == BMP_RLE4
comp == BMP_RLE4Description
TRUEnever evaluated
FALSEnever evaluated
) ||
0
127 (nbits == 8
nbits == 8Description
TRUEnever evaluated
FALSEnever evaluated
&& comp == BMP_RLE8
comp == BMP_RLE8Description
TRUEnever evaluated
FALSEnever evaluated
) || ((nbits == 16
nbits == 16Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
) && comp == BMP_BITFIELDS
comp == BMP_BITFIELDSDescription
TRUEnever evaluated
FALSEnever evaluated
)))
0
128 return
never executed: return false;
false;
never executed: return false;
0
129-
130 return
never executed: return true;
true;
never executed: return true;
0
131}-
132-
133static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int startpos, QImage &image)-
134{-
135 QIODevice* d = s.device();-
136 if (d->atEnd()
d->atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
137 return
never executed: return false;
false;
never executed: return false;
0
138 int w = bi.biWidth, h = bi.biHeight, nbits = bi.biBitCount;-
139 int t = bi.biSize, comp = bi.biCompression;-
140 uint red_mask = 0;-
141 uint green_mask = 0;-
142 uint blue_mask = 0;-
143 uint alpha_mask = 0;-
144 int red_shift = 0;-
145 int green_shift = 0;-
146 int blue_shift = 0;-
147 int alpha_shift = 0;-
148 int red_scale = 0;-
149 int green_scale = 0;-
150 int blue_scale = 0;-
151 int alpha_scale = 0;-
152-
153 if (!d->isSequential()
!d->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
154 d->seek(startpos + BMP_FILEHDR_SIZE + (bi.biSize >= BMP_WIN4 ? BMP_WIN : bi.biSize));
never executed: d->seek(startpos + BMP_FILEHDR_SIZE + (bi.biSize >= BMP_WIN4 ? BMP_WIN : bi.biSize));
0
155-
156 if (bi.biSize >= BMP_WIN4
bi.biSize >= BMP_WIN4Description
TRUEnever evaluated
FALSEnever evaluated
|| (comp == BMP_BITFIELDS
comp == BMP_BITFIELDSDescription
TRUEnever evaluated
FALSEnever evaluated
&& (nbits == 16
nbits == 16Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
))) {
0
157 if (d->read((char *)&red_mask, sizeof(red_mask)) != sizeof(red_mask)
d->read((char ...zeof(red_mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
158 return
never executed: return false;
false;
never executed: return false;
0
159 if (d->read((char *)&green_mask, sizeof(green_mask)) != sizeof(green_mask)
d->read((char ...of(green_mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
160 return
never executed: return false;
false;
never executed: return false;
0
161 if (d->read((char *)&blue_mask, sizeof(blue_mask)) != sizeof(blue_mask)
d->read((char ...eof(blue_mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
162 return
never executed: return false;
false;
never executed: return false;
0
163-
164-
165 if (bi.biSize >= BMP_WIN4
bi.biSize >= BMP_WIN4Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
166 int CSType = 0;-
167 int gamma_red = 0;-
168 int gamma_green = 0;-
169 int gamma_blue = 0;-
170 int endpoints[9];-
171-
172 if (d->read((char *)&alpha_mask, sizeof(alpha_mask)) != sizeof(alpha_mask)
d->read((char ...of(alpha_mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
173 return
never executed: return false;
false;
never executed: return false;
0
174 if (d->read((char *)&CSType, sizeof(CSType)) != sizeof(CSType)
d->read((char ...sizeof(CSType)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
175 return
never executed: return false;
false;
never executed: return false;
0
176 if (d->read((char *)&endpoints, sizeof(endpoints)) != sizeof(endpoints)
d->read((char ...eof(endpoints)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
177 return
never executed: return false;
false;
never executed: return false;
0
178 if (d->read((char *)&gamma_red, sizeof(gamma_red)) != sizeof(gamma_red)
d->read((char ...eof(gamma_red)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
179 return
never executed: return false;
false;
never executed: return false;
0
180 if (d->read((char *)&gamma_green, sizeof(gamma_green)) != sizeof(gamma_green)
d->read((char ...f(gamma_green)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
181 return
never executed: return false;
false;
never executed: return false;
0
182 if (d->read((char *)&gamma_blue, sizeof(gamma_blue)) != sizeof(gamma_blue)
d->read((char ...of(gamma_blue)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
183 return
never executed: return false;
false;
never executed: return false;
0
184-
185 if (bi.biSize == BMP_WIN5
bi.biSize == BMP_WIN5Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
186 qint32 intent = 0;-
187 qint32 profileData = 0;-
188 qint32 profileSize = 0;-
189 qint32 reserved = 0;-
190-
191 if (d->read((char *)&intent, sizeof(intent)) != sizeof(intent)
d->read((char ...sizeof(intent)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
192 return
never executed: return false;
false;
never executed: return false;
0
193 if (d->read((char *)&profileData, sizeof(profileData)) != sizeof(profileData)
d->read((char ...f(profileData)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
194 return
never executed: return false;
false;
never executed: return false;
0
195 if (d->read((char *)&profileSize, sizeof(profileSize)) != sizeof(profileSize)
d->read((char ...f(profileSize)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
196 return
never executed: return false;
false;
never executed: return false;
0
197 if (d->read((char *)&reserved, sizeof(reserved)) != sizeof(reserved)
d->read((char ...zeof(reserved)Description
TRUEnever evaluated
FALSEnever evaluated
|| reserved != 0
reserved != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
198 return
never executed: return false;
false;
never executed: return false;
0
199 }
never executed: end of block
0
200 }
never executed: end of block
0
201 }
never executed: end of block
0
202-
203 bool transp = (
(comp == BMP_BITFIELDS)Description
TRUEnever evaluated
FALSEnever evaluated
comp == BMP_BITFIELDS)
(comp == BMP_BITFIELDS)Description
TRUEnever evaluated
FALSEnever evaluated
&& alpha_mask
alpha_maskDescription
TRUEnever evaluated
FALSEnever evaluated
;
0
204 int ncols = 0;-
205 int depth = 0;-
206 QImage::Format format;-
207 switch (nbits) {-
208 case
never executed: case 32:
32:
never executed: case 32:
0
209 case
never executed: case 24:
24:
never executed: case 24:
0
210 case
never executed: case 16:
16:
never executed: case 16:
0
211 depth = 32;-
212 format = transp
transpDescription
TRUEnever evaluated
FALSEnever evaluated
? QImage::Format_ARGB32 : QImage::Format_RGB32;
0
213 break;
never executed: break;
0
214 case
never executed: case 8:
8:
never executed: case 8:
0
215 case
never executed: case 4:
4:
never executed: case 4:
0
216 depth = 8;-
217 format = QImage::Format_Indexed8;-
218 break;
never executed: break;
0
219 default
never executed: default:
:
never executed: default:
0
220 depth = 1;-
221 format = QImage::Format_Mono;-
222 }
never executed: end of block
0
223-
224 if (depth != 32
depth != 32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
225 ncols = bi.biClrUsed
bi.biClrUsedDescription
TRUEnever evaluated
FALSEnever evaluated
? bi.biClrUsed : 1 << nbits;
0
226 if (ncols < 1
ncols < 1Description
TRUEnever evaluated
FALSEnever evaluated
|| ncols > 256
ncols > 256Description
TRUEnever evaluated
FALSEnever evaluated
)
0
227 return
never executed: return false;
false;
never executed: return false;
0
228 }
never executed: end of block
0
229-
230 if (bi.biHeight < 0
bi.biHeight < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
231 h = -h;
never executed: h = -h;
0
232-
233 if (image.size() != QSize(w, h)
image.size() != QSize(w, h)Description
TRUEnever evaluated
FALSEnever evaluated
|| image.format() != format
image.format() != formatDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
234 image = QImage(w, h, format);-
235 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
236 return
never executed: return false;
false;
never executed: return false;
0
237 if (ncols
ncolsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
238 image.setColorCount(ncols);
never executed: image.setColorCount(ncols);
0
239 }
never executed: end of block
0
240-
241 image.setDotsPerMeterX(bi.biXPelsPerMeter);-
242 image.setDotsPerMeterY(bi.biYPelsPerMeter);-
243-
244 if (ncols > 0
ncols > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
245 image.setColorCount(ncols);-
246 uchar rgb[4];-
247 int rgb_len = t == BMP_OLD
t == BMP_OLDDescription
TRUEnever evaluated
FALSEnever evaluated
? 3 : 4;
0
248 for (int i=0; i<ncols
i<ncolsDescription
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
249 if (d->read((char *)rgb, rgb_len) != rgb_len
d->read((char ...en) != rgb_lenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
250 return
never executed: return false;
false;
never executed: return false;
0
251 image.setColor(i, qRgb(rgb[2],rgb[1],rgb[0]));-
252 if (d->atEnd()
d->atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
253 return
never executed: return false;
false;
never executed: return false;
0
254 }
never executed: end of block
0
255 }
never executed: end of block
else if (comp == BMP_BITFIELDS
comp == BMP_BITFIELDSDescription
TRUEnever evaluated
FALSEnever evaluated
&& (nbits == 16
nbits == 16Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
256 red_shift = calc_shift(red_mask);-
257 if (((
((red_mask >> ...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
red_mask >> red_shift) + 1) == 0
((red_mask >> ...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
258 return
never executed: return false;
false;
never executed: return false;
0
259 red_scale = 256 / ((red_mask >> red_shift) + 1);-
260 green_shift = calc_shift(green_mask);-
261 if (((
((green_mask >...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
green_mask >> green_shift) + 1) == 0
((green_mask >...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
262 return
never executed: return false;
false;
never executed: return false;
0
263 green_scale = 256 / ((green_mask >> green_shift) + 1);-
264 blue_shift = calc_shift(blue_mask);-
265 if (((
((blue_mask >>...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
blue_mask >> blue_shift) + 1) == 0
((blue_mask >>...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
266 return
never executed: return false;
false;
never executed: return false;
0
267 blue_scale = 256 / ((blue_mask >> blue_shift) + 1);-
268 alpha_shift = calc_shift(alpha_mask);-
269 if (((
((alpha_mask >...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
alpha_mask >> alpha_shift) + 1) == 0
((alpha_mask >...ift) + 1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
270 return
never executed: return false;
false;
never executed: return false;
0
271 alpha_scale = 256 / ((alpha_mask >> alpha_shift) + 1);-
272 }
never executed: end of block
else if (comp == BMP_RGB
comp == BMP_RGBDescription
TRUEnever evaluated
FALSEnever evaluated
&& (nbits == 24
nbits == 24Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
273 blue_mask = 0x000000ff;-
274 green_mask = 0x0000ff00;-
275 red_mask = 0x00ff0000;-
276 blue_shift = 0;-
277 green_shift = 8;-
278 red_shift = 16;-
279 blue_scale = green_scale = red_scale = 1;-
280 }
never executed: end of block
else if (comp == BMP_RGB
comp == BMP_RGBDescription
TRUEnever evaluated
FALSEnever evaluated
&& nbits == 16
nbits == 16Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
281 blue_mask = 0x001f;-
282 green_mask = 0x03e0;-
283 red_mask = 0x7c00;-
284 blue_shift = 0;-
285 green_shift = 2;-
286 red_shift = 7;-
287 red_scale = 1;-
288 green_scale = 1;-
289 blue_scale = 8;-
290 }
never executed: end of block
0
291 if (offset>=0
offset>=0Description
TRUEnever evaluated
FALSEnever evaluated
&& startpos + offset > d->pos()
startpos + offset > d->pos()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
292 if (!d->isSequential()
!d->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
293 d->seek(startpos + offset);
never executed: d->seek(startpos + offset);
0
294 }
never executed: end of block
0
295-
296 int bpl = image.bytesPerLine();-
297 uchar *data = image.bits();-
298-
299 if (nbits == 1
nbits == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
300 while (--
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
h >= 0
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
301 if (d->read((char*)(data + h*bpl), bpl) != bpl
d->read((char*...), bpl) != bplDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
302 break;
never executed: break;
0
303 }
never executed: end of block
0
304 if (ncols == 2
ncols == 2Description
TRUEnever evaluated
FALSEnever evaluated
&& qGray(image.color(0)) < qGray(image.color(1))
qGray(image.co...mage.color(1))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
305 swapPixel01(&image);
never executed: swapPixel01(&image);
0
306 }
never executed: end of block
0
307-
308 else if (nbits == 4
nbits == 4Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
309 int buflen = ((w+7)/8)*4;-
310 uchar *buf = new uchar[buflen];-
311 if (comp == BMP_RLE4
comp == BMP_RLE4Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
312 int x=0, y=0, c, i;-
313 quint8 b;-
314 uchar *p = data + (h-1)*bpl;-
315 const uchar *endp = p + w;-
316 while (y < h
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
317 if (!d->getChar((char *)&b)
!d->getChar((char *)&b)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
318 break;
never executed: break;
0
319 if (b == 0
b == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
320 if (!d->getChar((char *)&b)
!d->getChar((char *)&b)Description
TRUEnever evaluated
FALSEnever evaluated
|| b == 1
b == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
321 y = h;-
322 }
never executed: end of block
else switch (b) {
0
323 case
never executed: case 0:
0:
never executed: case 0:
0
324 x = 0;-
325 y++;-
326 p = data + (h-y-1)*bpl;-
327 break;
never executed: break;
0
328 case
never executed: case 2:
2:
never executed: case 2:
0
329 {-
330 quint8 tmp;-
331 d->getChar((char *)&tmp);-
332 x += tmp;-
333 d->getChar((char *)&tmp);-
334 y += tmp;-
335 }-
336-
337-
338 if ((
(uint)x >= (uint)wDescription
TRUEnever evaluated
FALSEnever evaluated
uint)x >= (uint)w
(uint)x >= (uint)wDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
339 x = w-1;
never executed: x = w-1;
0
340 if ((
(uint)y >= (uint)hDescription
TRUEnever evaluated
FALSEnever evaluated
uint)y >= (uint)h
(uint)y >= (uint)hDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
341 y = h-1;
never executed: y = h-1;
0
342-
343 p = data + (h-y-1)*bpl + x;-
344 break;
never executed: break;
0
345 default
never executed: default:
:
never executed: default:
0
346-
347 if (p + b > endp
p + b > endpDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
348 b = endp-p;
never executed: b = endp-p;
0
349-
350 i = (c = b)/2;-
351 while (i--
i--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
352 d->getChar((char *)&b);-
353 *p++ = b >> 4;-
354 *p++ = b & 0x0f;-
355 }
never executed: end of block
0
356 if (c & 1
c & 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
357 unsigned char tmp;-
358 d->getChar((char *)&tmp);-
359 *p++ = tmp >> 4;-
360 }
never executed: end of block
0
361 if ((((
(((c & 3) + 1) & 2) == 2Description
TRUEnever evaluated
FALSEnever evaluated
c & 3) + 1) & 2) == 2
(((c & 3) + 1) & 2) == 2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
362 d->getChar(0);
never executed: d->getChar(0);
0
363 x += c;-
364 }
never executed: end of block
0
365 } else {-
366-
367 if (p + b > endp
p + b > endpDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
368 b = endp-p;
never executed: b = endp-p;
0
369-
370 i = (c = b)/2;-
371 d->getChar((char *)&b);-
372 while (i--
i--Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
373 *p++ = b >> 4;-
374 *p++ = b & 0x0f;-
375 }
never executed: end of block
0
376 if (c & 1
c & 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
377 *
never executed: *p++ = b >> 4;
p++ = b >> 4;
never executed: *p++ = b >> 4;
0
378 x += c;-
379 }
never executed: end of block
0
380 }-
381 }
never executed: end of block
else if (comp == BMP_RGB
comp == BMP_RGBDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
382 memset(data, 0, h*bpl);-
383 while (--
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
h >= 0
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
384 if (d->read((char*)buf,buflen) != buflen
d->read((char*...len) != buflenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
385 break;
never executed: break;
0
386 uchar *p = data + h*bpl;-
387 uchar *b = buf;-
388 for (int i=0; i<w/2
i<w/2Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
389 *p++ = *b >> 4;-
390 *p++ = *b++ & 0x0f;-
391 }
never executed: end of block
0
392 if (w & 1
w & 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
393 *
never executed: *p = *b >> 4;
p = *b >> 4;
never executed: *p = *b >> 4;
0
394 }
never executed: end of block
0
395 }
never executed: end of block
0
396 delete [] buf;-
397 }
never executed: end of block
0
398-
399 else if (nbits == 8
nbits == 8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
400 if (comp == BMP_RLE8
comp == BMP_RLE8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
401 int x=0, y=0;-
402 quint8 b;-
403 uchar *p = data + (h-1)*bpl;-
404 const uchar *endp = p + w;-
405 while (y < h
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
406 if (!d->getChar((char *)&b)
!d->getChar((char *)&b)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
407 break;
never executed: break;
0
408 if (b == 0
b == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
409 if (!d->getChar((char *)&b)
!d->getChar((char *)&b)Description
TRUEnever evaluated
FALSEnever evaluated
|| b == 1
b == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
410 y = h;-
411 }
never executed: end of block
else switch (b) {
0
412 case
never executed: case 0:
0:
never executed: case 0:
0
413 x = 0;-
414 y++;-
415 p = data + (h-y-1)*bpl;-
416 break;
never executed: break;
0
417 case
never executed: case 2:
2:
never executed: case 2:
0
418 {-
419 quint8 tmp;-
420 d->getChar((char *)&tmp);-
421 x += tmp;-
422 d->getChar((char *)&tmp);-
423 y += tmp;-
424 }-
425-
426-
427 if ((
(uint)x >= (uint)wDescription
TRUEnever evaluated
FALSEnever evaluated
uint)x >= (uint)w
(uint)x >= (uint)wDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
428 x = w-1;
never executed: x = w-1;
0
429 if ((
(uint)y >= (uint)hDescription
TRUEnever evaluated
FALSEnever evaluated
uint)y >= (uint)h
(uint)y >= (uint)hDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
430 y = h-1;
never executed: y = h-1;
0
431-
432 p = data + (h-y-1)*bpl + x;-
433 break;
never executed: break;
0
434 default
never executed: default:
:
never executed: default:
0
435-
436 if (p + b > endp
p + b > endpDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
437 b = endp-p;
never executed: b = endp-p;
0
438-
439 if (d->read((char *)p, b) != b
d->read((char *)p, b) != bDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
440 return
never executed: return false;
false;
never executed: return false;
0
441 if ((
(b & 1) == 1Description
TRUEnever evaluated
FALSEnever evaluated
b & 1) == 1
(b & 1) == 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
442 d->getChar(0);
never executed: d->getChar(0);
0
443 x += b;-
444 p += b;-
445 }
never executed: end of block
0
446 } else {-
447-
448 if (p + b > endp
p + b > endpDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
449 b = endp-p;
never executed: b = endp-p;
0
450-
451 char tmp;-
452 d->getChar(&tmp);-
453 memset(p, tmp, b);-
454 x += b;-
455 p += b;-
456 }
never executed: end of block
0
457 }-
458 }
never executed: end of block
else if (comp == BMP_RGB
comp == BMP_RGBDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
459 while (--
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
h >= 0
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
460 if (d->read((char *)data + h*bpl, bpl) != bpl
d->read((char ...l, bpl) != bplDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
461 break;
never executed: break;
0
462 }
never executed: end of block
0
463 }
never executed: end of block
0
464 }
never executed: end of block
0
465-
466 else if (nbits == 16
nbits == 16Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 24
nbits == 24Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 32
nbits == 32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
467 QRgb *p;-
468 QRgb *end;-
469 uchar *buf24 = new uchar[bpl];-
470 int bpl24 = ((w*nbits+31)/32)*4;-
471 uchar *b;-
472 int c;-
473-
474 while (--
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
h >= 0
--h >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
475 p = (QRgb *)(data + h*bpl);-
476 end = p + w;-
477 if (d->read((char *)buf24,bpl24) != bpl24
d->read((char ...pl24) != bpl24Description
TRUEnever evaluated
FALSEnever evaluated
)
0
478 break;
never executed: break;
0
479 b = buf24;-
480 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
481 c = *(uchar*)b | (*(uchar*)(b+1)<<8);-
482 if (nbits > 16
nbits > 16Description
TRUEnever evaluated
FALSEnever evaluated
)
0
483 c |= *(uchar*)(b+2)<<16;
never executed: c |= *(uchar*)(b+2)<<16;
0
484 if (nbits > 24
nbits > 24Description
TRUEnever evaluated
FALSEnever evaluated
)
0
485 c |= *(uchar*)(b+3)<<24;
never executed: c |= *(uchar*)(b+3)<<24;
0
486 *p++ = qRgba(((c & red_mask) >> red_shift) * red_scale,-
487 ((c & green_mask) >> green_shift) * green_scale,-
488 ((c & blue_mask) >> blue_shift) * blue_scale,-
489 transp ? ((c & alpha_mask) >> alpha_shift) * alpha_scale : 0xff);-
490 b += nbits/8;-
491 }
never executed: end of block
0
492 }
never executed: end of block
0
493 delete[] buf24;-
494 }
never executed: end of block
0
495-
496 if (bi.biHeight < 0
bi.biHeight < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
497-
498 uchar *buf = new uchar[bpl];-
499 h = -bi.biHeight;-
500 for (int y = 0; y < h/2
y < h/2Description
TRUEnever evaluated
FALSEnever evaluated
; ++y) {
0
501 memcpy(buf, data + y*bpl, bpl);-
502 memcpy(data + y*bpl, data + (h-y-1)*bpl, bpl);-
503 memcpy(data + (h-y-1)*bpl, buf, bpl);-
504 }
never executed: end of block
0
505 delete [] buf;-
506 }
never executed: end of block
0
507-
508 return
never executed: return true;
true;
never executed: return true;
0
509}-
510-
511-
512bool qt_write_dib(QDataStream &s, QImage image)-
513{-
514 int nbits;-
515 int bpl_bmp;-
516 int bpl = image.bytesPerLine();-
517-
518 QIODevice* d = s.device();-
519 if (!d->isWritable()
!d->isWritable()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
520 return
never executed: return false;
false;
never executed: return false;
0
521-
522 if (image.depth() == 8
image.depth() == 8Description
TRUEnever evaluated
FALSEnever evaluated
&& image.colorCount() <= 16
image.colorCount() <= 16Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
523 bpl_bmp = (((bpl+1)/2+3)/4)*4;-
524 nbits = 4;-
525 }
never executed: end of block
else if (image.depth() == 32
image.depth() == 32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
526 bpl_bmp = ((image.width()*24+31)/32)*4;-
527 nbits = 24;-
528 }
never executed: end of block
else {
0
529 bpl_bmp = bpl;-
530 nbits = image.depth();-
531 }
never executed: end of block
0
532-
533 BMP_INFOHDR bi;-
534 bi.biSize = BMP_WIN;-
535 bi.biWidth = image.width();-
536 bi.biHeight = image.height();-
537 bi.biPlanes = 1;-
538 bi.biBitCount = nbits;-
539 bi.biCompression = BMP_RGB;-
540 bi.biSizeImage = bpl_bmp*image.height();-
541 bi.biXPelsPerMeter = image.dotsPerMeterX()
image.dotsPerMeterX()Description
TRUEnever evaluated
FALSEnever evaluated
? image.dotsPerMeterX()
0
542 : 2834;-
543 bi.biYPelsPerMeter = image.dotsPerMeterY()
image.dotsPerMeterY()Description
TRUEnever evaluated
FALSEnever evaluated
? image.dotsPerMeterY() : 2834;
0
544 bi.biClrUsed = image.colorCount();-
545 bi.biClrImportant = image.colorCount();-
546 s << bi;-
547 if (s.status() != QDataStream::Ok
s.status() != QDataStream::OkDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
548 return
never executed: return false;
false;
never executed: return false;
0
549-
550 if (image.depth() != 32
image.depth() != 32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
551 uchar *color_table = new uchar[4*image.colorCount()];-
552 uchar *rgb = color_table;-
553 QVector<QRgb> c = image.colorTable();-
554 for (int i=0; i<image.colorCount()
i<image.colorCount()Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
555 *rgb++ = qBlue (c[i]);-
556 *rgb++ = qGreen(c[i]);-
557 *rgb++ = qRed (c[i]);-
558 *rgb++ = 0;-
559 }
never executed: end of block
0
560 if (d->write((char *)color_table, 4*image.colorCount()) == -1
d->write((char...Count()) == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
561 delete [] color_table;-
562 return
never executed: return false;
false;
never executed: return false;
0
563 }-
564 delete [] color_table;-
565 }
never executed: end of block
0
566-
567 if (image.format() == QImage::Format_MonoLSB
image.format()...Format_MonoLSBDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
568 image = image.convertToFormat(QImage::Format_Mono);
never executed: image = image.convertToFormat(QImage::Format_Mono);
0
569-
570 int y;-
571-
572 if (nbits == 1
nbits == 1Description
TRUEnever evaluated
FALSEnever evaluated
|| nbits == 8
nbits == 8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
573 for (y=image.height()-1; y>=0
y>=0Description
TRUEnever evaluated
FALSEnever evaluated
; y--) {
0
574 if (d->write((const char*)image.constScanLine(y), bpl) == -1
d->write((cons...y), bpl) == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
575 return
never executed: return false;
false;
never executed: return false;
0
576 }
never executed: end of block
0
577 return
never executed: return true;
true;
never executed: return true;
0
578 }-
579-
580 uchar *buf = new uchar[bpl_bmp];-
581 uchar *b, *end;-
582 const uchar *p;-
583-
584 memset(buf, 0, bpl_bmp);-
585 for (y=image.height()-1; y>=0
y>=0Description
TRUEnever evaluated
FALSEnever evaluated
; y--) {
0
586 if (nbits == 4
nbits == 4Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
587 p = image.constScanLine(y);-
588 b = buf;-
589 end = b + image.width()/2;-
590 while (b < end
b < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
591 *b++ = (*p << 4) | (*(p+1) & 0x0f);-
592 p += 2;-
593 }
never executed: end of block
0
594 if (image.width() & 1
image.width() & 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
595 *
never executed: *b = *p << 4;
b = *p << 4;
never executed: *b = *p << 4;
0
596 }
never executed: end of block
else {
0
597 const QRgb *p = (const QRgb *)image.constScanLine(y);-
598 const QRgb *end = p + image.width();-
599 b = buf;-
600 while (p < end
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
601 *b++ = qBlue(*p);-
602 *b++ = qGreen(*p);-
603 *b++ = qRed(*p);-
604 p++;-
605 }
never executed: end of block
0
606 }
never executed: end of block
0
607 if (bpl_bmp != d->write((char*)buf, bpl_bmp)
bpl_bmp != d->...)buf, bpl_bmp)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
608 delete[] buf;-
609 return
never executed: return false;
false;
never executed: return false;
0
610 }-
611 }
never executed: end of block
0
612 delete[] buf;-
613 return
never executed: return true;
true;
never executed: return true;
0
614}-
615-
616-
617bool qt_read_dib(QDataStream &s, QImage &image)-
618{-
619 BMP_INFOHDR bi;-
620 if (!read_dib_infoheader(s, bi)
!read_dib_infoheader(s, bi)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
621 return
never executed: return false;
false;
never executed: return false;
0
622 return
never executed: return read_dib_body(s, bi, -1, -BMP_FILEHDR_SIZE, image);
read_dib_body(s, bi, -1, -BMP_FILEHDR_SIZE, image);
never executed: return read_dib_body(s, bi, -1, -BMP_FILEHDR_SIZE, image);
0
623}-
624-
625QBmpHandler::QBmpHandler(InternalFormat fmt) :-
626 m_format(fmt), state(Ready)-
627{-
628}
never executed: end of block
0
629-
630QByteArray QBmpHandler::formatName() const-
631{-
632 return
never executed: return m_format == BmpFormat ? "bmp" : "dib";
m_format == BmpFormat ? "bmp" : "dib";
never executed: return m_format == BmpFormat ? "bmp" : "dib";
0
633}-
634-
635bool QBmpHandler::readHeader()-
636{-
637 state = Error;-
638-
639 QIODevice *d = device();-
640 QDataStream s(d);-
641 startpos = d->pos();-
642-
643-
644 s.setByteOrder(QDataStream::LittleEndian);-
645-
646-
647 if (m_format == BmpFormat
m_format == BmpFormatDescription
TRUEnever evaluated
FALSEnever evaluated
&& !read_dib_fileheader(s, fileHeader)
!read_dib_file...s, fileHeader)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
648 return
never executed: return false;
false;
never executed: return false;
0
649-
650-
651 if (!read_dib_infoheader(s, infoHeader)
!read_dib_info...s, infoHeader)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
652 return
never executed: return false;
false;
never executed: return false;
0
653-
654 state = ReadHeader;-
655 return
never executed: return true;
true;
never executed: return true;
0
656}-
657-
658bool QBmpHandler::canRead() const-
659{-
660 if (m_format == BmpFormat
m_format == BmpFormatDescription
TRUEnever evaluated
FALSEnever evaluated
&& state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !canRead(device())
!canRead(device())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
661 return
never executed: return false;
false;
never executed: return false;
0
662-
663 if (state != Error
state != ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
664 setFormat(formatName());-
665 return
never executed: return true;
true;
never executed: return true;
0
666 }-
667-
668 return
never executed: return false;
false;
never executed: return false;
0
669}-
670-
671bool QBmpHandler::canRead(QIODevice *device)-
672{-
673 if (!device
!deviceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
674 QMessageLogger(__FILE__, 751, __PRETTY_FUNCTION__).warning("QBmpHandler::canRead() called with 0 pointer");-
675 return
never executed: return false;
false;
never executed: return false;
0
676 }-
677-
678 char head[2];-
679 if (device->peek(head, sizeof(head)) != sizeof(head)
device->peek(h...= sizeof(head)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
680 return
never executed: return false;
false;
never executed: return false;
0
681-
682 return
never executed: return (qstrncmp(head, "BM", 2) == 0);
(qstrncmp(head, "BM", 2) == 0);
never executed: return (qstrncmp(head, "BM", 2) == 0);
0
683}-
684-
685bool QBmpHandler::read(QImage *image)-
686{-
687 if (state == Error
state == ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
688 return
never executed: return false;
false;
never executed: return false;
0
689-
690 if (!image
!imageDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
691 QMessageLogger(__FILE__, 768, __PRETTY_FUNCTION__).warning("QBmpHandler::read: cannot read into null pointer");-
692 return
never executed: return false;
false;
never executed: return false;
0
693 }-
694-
695 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !readHeader()
!readHeader()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
696 state = Error;-
697 return
never executed: return false;
false;
never executed: return false;
0
698 }-
699-
700 QIODevice *d = device();-
701 QDataStream s(d);-
702-
703-
704 s.setByteOrder(QDataStream::LittleEndian);-
705-
706-
707 const bool readSuccess = m_format == BmpFormat
m_format == BmpFormatDescription
TRUEnever evaluated
FALSEnever evaluated
?
0
708 read_dib_body(s, infoHeader, fileHeader.bfOffBits, startpos, *image) :-
709 read_dib_body(s, infoHeader, -1, startpos - BMP_FILEHDR_SIZE, *image);-
710 if (!readSuccess
!readSuccessDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
711 return
never executed: return false;
false;
never executed: return false;
0
712-
713 state = Ready;-
714 return
never executed: return true;
true;
never executed: return true;
0
715}-
716-
717bool QBmpHandler::write(const QImage &img)-
718{-
719 if (m_format == DibFormat
m_format == DibFormatDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
720 QDataStream dibStream(device());-
721 dibStream.setByteOrder(QDataStream::LittleEndian);-
722 return
never executed: return qt_write_dib(dibStream, img);
qt_write_dib(dibStream, img);
never executed: return qt_write_dib(dibStream, img);
0
723 }-
724-
725 QImage image;-
726 switch (img.format()) {-
727 case
never executed: case QImage::Format_Mono:
QImage::Format_Mono:
never executed: case QImage::Format_Mono:
0
728 case
never executed: case QImage::Format_MonoLSB:
QImage::Format_MonoLSB:
never executed: case QImage::Format_MonoLSB:
0
729 case
never executed: case QImage::Format_Indexed8:
QImage::Format_Indexed8:
never executed: case QImage::Format_Indexed8:
0
730 case
never executed: case QImage::Format_RGB32:
QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
731 case
never executed: case QImage::Format_ARGB32:
QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
732 image = img;-
733 break;
never executed: break;
0
734 case
never executed: case QImage::Format_Alpha8:
QImage::Format_Alpha8:
never executed: case QImage::Format_Alpha8:
0
735 case
never executed: case QImage::Format_Grayscale8:
QImage::Format_Grayscale8:
never executed: case QImage::Format_Grayscale8:
0
736 image = img.convertToFormat(QImage::Format_Indexed8);-
737 break;
never executed: break;
0
738 default
never executed: default:
:
never executed: default:
0
739 if (img.hasAlphaChannel()
img.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
740 image = img.convertToFormat(QImage::Format_ARGB32);
never executed: image = img.convertToFormat(QImage::Format_ARGB32);
0
741 else-
742 image = img.convertToFormat(QImage::Format_RGB32);
never executed: image = img.convertToFormat(QImage::Format_RGB32);
0
743 break;
never executed: break;
0
744 }-
745-
746 QIODevice *d = device();-
747 QDataStream s(d);-
748 BMP_FILEHDR bf;-
749 int bpl_bmp;-
750 int bpl = image.bytesPerLine();-
751-
752-
753 if (image.depth() == 8
image.depth() == 8Description
TRUEnever evaluated
FALSEnever evaluated
&& image.colorCount() <= 16
image.colorCount() <= 16Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
754 bpl_bmp = (((bpl+1)/2+3)/4)*4;-
755 }
never executed: end of block
else if (image.depth() == 32
image.depth() == 32Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
756 bpl_bmp = ((image.width()*24+31)/32)*4;-
757 }
never executed: end of block
else {
0
758 bpl_bmp = bpl;-
759 }
never executed: end of block
0
760-
761-
762 s.setByteOrder(QDataStream::LittleEndian);-
763-
764-
765 memcpy(bf.bfType, "BM", 2);-
766-
767-
768 bf.bfReserved1 = 0;-
769 bf.bfReserved2 = 0;-
770 bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.colorCount() * 4;-
771 bf.bfSize = bf.bfOffBits + bpl_bmp*image.height();-
772 s << bf;-
773-
774-
775 return
never executed: return qt_write_dib(s, image);
qt_write_dib(s, image);
never executed: return qt_write_dib(s, image);
0
776}-
777-
778bool QBmpHandler::supportsOption(ImageOption option) const-
779{-
780 return
never executed: return option == Size || option == ImageFormat;
option == Size
never executed: return option == Size || option == ImageFormat;
0
781 || option == ImageFormat;
never executed: return option == Size || option == ImageFormat;
0
782}-
783-
784QVariant QBmpHandler::option(ImageOption option) const-
785{-
786 if (option == Size
option == SizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
787 if (state == Error
state == ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
788 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
789 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !const_cast<QBmpHandler*>(this)->readHeader()
!const_cast<QB...->readHeader()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
790 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
791 return
never executed: return QSize(infoHeader.biWidth, infoHeader.biHeight);
QSize(infoHeader.biWidth, infoHeader.biHeight);
never executed: return QSize(infoHeader.biWidth, infoHeader.biHeight);
0
792 } else if (option == ImageFormat
option == ImageFormatDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
793 if (state == Error
state == ErrorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
794 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
795 if (state == Ready
state == ReadyDescription
TRUEnever evaluated
FALSEnever evaluated
&& !const_cast<QBmpHandler*>(this)->readHeader()
!const_cast<QB...->readHeader()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
796 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
797 QImage::Format format;-
798 switch (infoHeader.biBitCount) {-
799 case
never executed: case 32:
32:
never executed: case 32:
0
800 case
never executed: case 24:
24:
never executed: case 24:
0
801 case
never executed: case 16:
16:
never executed: case 16:
0
802 format = QImage::Format_RGB32;-
803 break;
never executed: break;
0
804 case
never executed: case 8:
8:
never executed: case 8:
0
805 case
never executed: case 4:
4:
never executed: case 4:
0
806 format = QImage::Format_Indexed8;-
807 break;
never executed: break;
0
808 default
never executed: default:
:
never executed: default:
0
809 format = QImage::Format_Mono;-
810 }
never executed: end of block
0
811 return
never executed: return format;
format;
never executed: return format;
0
812 }-
813 return
never executed: return QVariant();
QVariant();
never executed: return QVariant();
0
814}-
815-
816void QBmpHandler::setOption(ImageOption option, const QVariant &value)-
817{-
818 (void)option;;-
819 (void)value;;-
820}
never executed: end of block
0
821-
822QByteArray QBmpHandler::name() const-
823{-
824 return
never executed: return formatName();
formatName();
never executed: return formatName();
0
825}-
826-
827-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9