1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
5#ifndef QBMPHANDLER_P_H
6#define QBMPHANDLER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include "QtGui/qimageiohandler.h"
21
22#ifndef QT_NO_IMAGEFORMAT_BMP
23
24QT_BEGIN_NAMESPACE
25
26struct BMP_FILEHDR { // BMP file header
27 char bfType[2]; // "BM"
28 qint32 bfSize; // size of file
29 qint16 bfReserved1;
30 qint16 bfReserved2;
31 qint32 bfOffBits; // pointer to the pixmap bits
32};
33
34struct BMP_INFOHDR { // BMP information header
35 qint32 biSize; // size of this struct
36 qint32 biWidth; // pixmap width
37 qint32 biHeight; // pixmap height
38 qint16 biPlanes; // should be 1
39 qint16 biBitCount; // number of bits per pixel
40 qint32 biCompression; // compression method
41 qint32 biSizeImage; // size of image
42 qint32 biXPelsPerMeter; // horizontal resolution
43 qint32 biYPelsPerMeter; // vertical resolution
44 qint32 biClrUsed; // number of colors used
45 qint32 biClrImportant; // number of important colors
46 // V4:
47 quint32 biRedMask;
48 quint32 biGreenMask;
49 quint32 biBlueMask;
50 quint32 biAlphaMask;
51 qint32 biCSType;
52 qint32 biEndpoints[9];
53 qint32 biGammaRed;
54 qint32 biGammaGreen;
55 qint32 biGammaBlue;
56 // V5:
57 qint32 biIntent;
58 qint32 biProfileData;
59 qint32 biProfileSize;
60 qint32 biReserved;
61};
62
63// BMP-Handler, which is also able to read and write the DIB
64// (Device-Independent-Bitmap) format used internally in the Windows operating
65// system for OLE/clipboard operations. DIB is a subset of BMP (without file
66// header). The Windows platform plugin accesses the DIB-functionality.
67
68class QBmpHandler : public QImageIOHandler
69{
70public:
71 enum InternalFormat {
72 DibFormat,
73 BmpFormat
74 };
75
76 explicit QBmpHandler(InternalFormat fmt = BmpFormat);
77 bool canRead() const override;
78 bool read(QImage *image) override;
79 bool write(const QImage &image) override;
80
81 static bool canRead(QIODevice *device);
82
83 QVariant option(ImageOption option) const override;
84 void setOption(ImageOption option, const QVariant &value) override;
85 bool supportsOption(ImageOption option) const override;
86
87private:
88 bool readHeader();
89 inline QByteArray formatName() const;
90
91 enum State {
92 Ready,
93 ReadHeader,
94 Error
95 };
96
97 const InternalFormat m_format;
98
99 State state;
100 BMP_FILEHDR fileHeader;
101 BMP_INFOHDR infoHeader;
102 qint64 startpos;
103};
104
105QT_END_NAMESPACE
106
107#endif // QT_NO_IMAGEFORMAT_BMP
108
109#endif // QBMPHANDLER_P_H
110

source code of qtbase/src/gui/image/qbmphandler_p.h