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
qtgafile.h
Go to the documentation of this file.
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 QTGAFILE_H
6#define QTGAFILE_H
7
8#include <QtGui/QColor>
9#include <QtGui/QImage>
10#include <QtCore/QCoreApplication>
11
12QT_BEGIN_NAMESPACE
13
14class QIODevice;
15
17{
19
20public:
25
27 IdLength = 0, /* 00h Size of Image ID field */
28 ColorMapType = 1, /* 01h Color map type */
29 ImageType = 2, /* 02h Image type code */
30 CMapStart = 3, /* 03h Color map origin */
31 CMapLength = 5, /* 05h Color map length */
32 CMapDepth = 7, /* 07h Depth of color map entries */
33 XOffset = 8, /* 08h X origin of image */
34 YOffset = 10, /* 0Ah Y origin of image */
35 Width = 12, /* 0Ch Width of image */
36 Height = 14, /* 0Eh Height of image */
37 PixelDepth = 16, /* 10h Image pixel size */
38 ImageDescriptor = 17, /* 11h Image descriptor byte */
40 };
41
48
49 QTgaFile(QIODevice *);
50 ~QTgaFile();
51
52 inline bool isValid() const;
53 inline QString errorMessage() const;
55 inline int xOffset() const;
56 inline int yOffset() const;
57 inline int width() const;
58 inline int height() const;
59 inline QSize size() const;
60 inline Compression compression() const;
61
62private:
63 static inline quint16 littleEndianInt(const unsigned char *d);
64
65 QString mErrorMessage;
66 unsigned char mHeader[HeaderSize];
67 QIODevice *mDevice;
68};
69
70inline bool QTgaFile::isValid() const
71{
72 return mErrorMessage.isEmpty();
73}
74
76{
77 return mErrorMessage;
78}
79
80/*!
81 \internal
82 Returns the integer encoded in the two little endian bytes at \a d.
83*/
84inline quint16 QTgaFile::littleEndianInt(const unsigned char *d)
85{
86 return d[0] + d[1] * 256;
87}
88
89inline int QTgaFile::xOffset() const
90{
91 return littleEndianInt(&mHeader[XOffset]);
92}
93
94inline int QTgaFile::yOffset() const
95{
96 return littleEndianInt(&mHeader[YOffset]);
97}
98
99inline int QTgaFile::width() const
100{
101 return littleEndianInt(&mHeader[Width]);
102}
103
104inline int QTgaFile::height() const
105{
106 return littleEndianInt(&mHeader[Height]);
107}
108
109inline QSize QTgaFile::size() const
110{
111 return QSize(width(), height());
112}
113
115{
116 // TODO: for now, only handle type 2 files, with no color table
117 // and no compression
118 return NoCompression;
119}
120
121QT_END_NAMESPACE
122
123#endif // QTGAFILE_H
bool isValid() const
Definition qtgafile.h:70
@ SignatureOffset
Definition qtgafile.h:45
@ DeveloperOffset
Definition qtgafile.h:44
@ FooterSize
Definition qtgafile.h:46
@ ExtensionOffset
Definition qtgafile.h:43
QSize size() const
Definition qtgafile.h:109
int yOffset() const
Definition qtgafile.h:94
int width() const
Definition qtgafile.h:99
QTgaFile(QIODevice *)
Construct a new QTgaFile object getting data from device.
Definition qtgafile.cpp:102
QString errorMessage() const
Definition qtgafile.h:75
int height() const
Definition qtgafile.h:104
@ ColorMapType
Definition qtgafile.h:28
@ CMapDepth
Definition qtgafile.h:32
@ IdLength
Definition qtgafile.h:27
@ CMapLength
Definition qtgafile.h:31
@ ImageDescriptor
Definition qtgafile.h:38
@ YOffset
Definition qtgafile.h:34
@ PixelDepth
Definition qtgafile.h:37
@ CMapStart
Definition qtgafile.h:30
@ HeaderSize
Definition qtgafile.h:39
@ ImageType
Definition qtgafile.h:29
@ XOffset
Definition qtgafile.h:33
Compression compression() const
Definition qtgafile.h:114
QImage readImage()
Definition qtgafile.cpp:186
int xOffset() const
Definition qtgafile.h:89