Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qicnshandler_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Alex Char.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:critical reason:data-parser
5
6#ifndef QICNSHANDLER_P_H
7#define QICNSHANDLER_P_H
8
9#include <QtGui/qimageiohandler.h>
10#include <QtCore/qlist.h>
11
12#ifndef QT_NO_DATASTREAM
13
14#define MAKEOSTYPE(c0,c1,c2,c3) (((quint8)c0 << 24) | ((quint8)c1 << 16) | ((quint8)c2 << 8) | (quint8)c3)
15
16QT_BEGIN_NAMESPACE
17
18struct ICNSBlockHeader
19{
20 enum OS {
21 TypeIcns = MAKEOSTYPE('i', 'c', 'n', 's'), // Icns container magic
22 TypeToc = MAKEOSTYPE('T', 'O', 'C', ' '), // Table of contents
23 TypeIcnv = MAKEOSTYPE('i', 'c', 'n', 'V'), // Icon Composer version
24 // Legacy:
25 TypeClut = MAKEOSTYPE('c', 'l', 'u', 't'), // Color look-up table (pre-OS X resources)
26 TypeTile = MAKEOSTYPE('t', 'i', 'l', 'e'), // Container (icon variants)
27 TypeOver = MAKEOSTYPE('o', 'v', 'e', 'r'), // Container (icon variants)
28 TypeOpen = MAKEOSTYPE('o', 'p', 'e', 'n'), // Container (icon variants)
29 TypeDrop = MAKEOSTYPE('d', 'r', 'o', 'p'), // Container (icon variants)
30 TypeOdrp = MAKEOSTYPE('o', 'd', 'r', 'p'), // Container (icon variants)
31 };
32
33 quint32 ostype;
34 quint32 length;
35};
36
38{
39 enum Group {
40 GroupUnknown = 0, // Default for invalid ones
41 GroupMini = 'm', // "mini" (16x12)
42 GroupSmall = 's', // "small" (16x16)
43 GroupLarge = 'l', // "large" (32x32)
44 GroupHuge = 'h', // "huge" (48x48)
45 GroupThumbnail = 't', // "thumbnail" (128x128)
46 GroupPortable = 'p', // "portable"? (Speculation, used for png/jp2)
47 GroupCompressed = 'c', // "compressed"? (Speculation, used for png/jp2)
48 // Legacy icons:
49 GroupICON = 'N', // "ICON" (32x32)
50 };
51 enum Depth {
52 DepthUnknown = 0, // Default for invalid or compressed ones
57 };
58 enum Flags {
59 Unknown = 0x0, // Default for invalid ones
60 IsIcon = 0x1, // Contains a raw icon without alpha or compressed icon
61 IsMask = 0x2, // Contains alpha mask
62 IconPlusMask = IsIcon | IsMask // Contains raw icon and mask combined in one entry (double size)
63 };
64 enum Format {
65 FormatUnknown = 0, // Default for invalid or undetermined ones
66 RawIcon, // Raw legacy icon, uncompressed
67 RLE24, // Raw 32bit icon, data is compressed
68 PNG, // Compressed icon in PNG format
69 JP2 // Compressed icon in JPEG2000 format
70 };
71
72 quint32 ostype; // Real OSType
73 quint32 variant; // Virtual OSType: a parent container, zero if parent is icns root
74 Group group; // ASCII character number
75 quint32 width; // For uncompressed icons only, zero for compressed ones for now
76 quint32 height; // For uncompressed icons only, zero for compressed ones fow now
77 Depth depth; // Color depth
78 Flags flags; // Flags to determine the type of entry
79 Format dataFormat; // Format of the image data
80 quint32 dataLength; // Length of the image data in bytes
81 qint64 dataOffset; // Offset from the initial position of the file/device
82
88};
90
92{
93public:
95
96 bool canRead() const override;
97 bool read(QImage *image) override;
98 bool write(const QImage &image) override;
99
100 bool supportsOption(ImageOption option) const override;
101 QVariant option(ImageOption option) const override;
102
103 int imageCount() const override;
104 bool jumpToImage(int imageNumber) override;
106
107 static bool canRead(QIODevice *device);
108
109private:
110 bool ensureScanned() const;
111 bool scanDevice();
112 bool addEntry(const ICNSBlockHeader &header, qint64 imgDataOffset, quint32 variant = 0);
113 const ICNSEntry &getIconMask(const ICNSEntry &icon) const;
114
115private:
116 enum ScanState {
117 ScanError = -1,
118 ScanNotScanned = 0,
119 ScanSuccess = 1,
120 };
121
122 int m_currentIconIndex;
123 QList<ICNSEntry> m_icons;
124 QList<ICNSEntry> m_masks;
125 ScanState m_state;
126};
127
128QT_END_NAMESPACE
129
130#endif // QT_NO_DATASTREAM
131
132#endif /* QICNSHANDLER_P_H */
int imageCount() const override
For image formats that support animation, this function returns the number of images in the animation...
bool write(const QImage &image) override
Writes the image image to the assigned device.
bool read(QImage *image) override
Read an image from the device, and stores it in image.
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool supportsOption(ImageOption option) const override
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
QVariant option(ImageOption option) const override
Returns the value assigned to option as a QVariant.
bool jumpToImage(int imageNumber) override
For image formats that support animation, this function jumps to the image whose sequence number is i...
bool jumpToNextImage() override
For image formats that support animation, this function jumps to the next image.
static bool canRead(QIODevice *device)
QImageIOHandler * create(QIODevice *device, const QByteArray &format=QByteArray()) const override
Creates and returns a QImageIOHandler subclass, with device and format set.
Definition main.cpp:40
#define MAKEOSTYPE(c0, c1, c2, c3)
Q_DECLARE_TYPEINFO(ICNSEntry, Q_RELOCATABLE_TYPE)
quint32 height
quint32 width
qint64 dataOffset
quint32 dataLength
quint32 variant
Format dataFormat
quint32 ostype