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