Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QTGAFILE_H
5#define QTGAFILE_H
6
7#include <QtGui/QColor>
8#include <QtGui/QImage>
9#include <QtCore/QCoreApplication>
10
12
13class QIODevice;
14
16{
18
19public:
24
26 IdLength = 0, /* 00h Size of Image ID field */
27 ColorMapType = 1, /* 01h Color map type */
28 ImageType = 2, /* 02h Image type code */
29 CMapStart = 3, /* 03h Color map origin */
30 CMapLength = 5, /* 05h Color map length */
31 CMapDepth = 7, /* 07h Depth of color map entries */
32 XOffset = 8, /* 08h X origin of image */
33 YOffset = 10, /* 0Ah Y origin of image */
34 Width = 12, /* 0Ch Width of image */
35 Height = 14, /* 0Eh Height of image */
36 PixelDepth = 16, /* 10h Image pixel size */
37 ImageDescriptor = 17, /* 11h Image descriptor byte */
38 HeaderSize = 18
39 };
40
47
49 ~QTgaFile();
50
51 inline bool isValid() const;
52 inline QString errorMessage() const;
54 inline int xOffset() const;
55 inline int yOffset() const;
56 inline int width() const;
57 inline int height() const;
58 inline QSize size() const;
59 inline Compression compression() const;
60
61private:
62 static inline quint16 littleEndianInt(const unsigned char *d);
63
64 QString mErrorMessage;
65 unsigned char mHeader[HeaderSize];
66 QIODevice *mDevice;
67};
68
69inline bool QTgaFile::isValid() const
70{
71 return mErrorMessage.isEmpty();
72}
73
75{
76 return mErrorMessage;
77}
78
83inline quint16 QTgaFile::littleEndianInt(const unsigned char *d)
84{
85 return d[0] + d[1] * 256;
86}
87
88inline int QTgaFile::xOffset() const
89{
90 return littleEndianInt(&mHeader[XOffset]);
91}
92
93inline int QTgaFile::yOffset() const
94{
95 return littleEndianInt(&mHeader[YOffset]);
96}
97
98inline int QTgaFile::width() const
99{
100 return littleEndianInt(&mHeader[Width]);
101}
102
103inline int QTgaFile::height() const
104{
105 return littleEndianInt(&mHeader[Height]);
106}
107
108inline QSize QTgaFile::size() const
109{
110 return QSize(width(), height());
111}
112
114{
115 // TODO: for now, only handle type 2 files, with no color table
116 // and no compression
117 return NoCompression;
118}
119
121
122#endif // QTGAFILE_H
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
bool isValid() const
Definition qtgafile.h:69
@ RleCompression
Definition qtgafile.h:22
@ NoCompression
Definition qtgafile.h:21
@ SignatureOffset
Definition qtgafile.h:44
@ DeveloperOffset
Definition qtgafile.h:43
@ FooterSize
Definition qtgafile.h:45
@ ExtensionOffset
Definition qtgafile.h:42
QSize size() const
Definition qtgafile.h:108
int yOffset() const
Definition qtgafile.h:93
int width() const
Definition qtgafile.h:98
QTgaFile(QIODevice *)
Construct a new QTgaFile object getting data from device.
Definition qtgafile.cpp:97
QString errorMessage() const
Definition qtgafile.h:74
int height() const
Definition qtgafile.h:103
@ ColorMapType
Definition qtgafile.h:27
@ CMapDepth
Definition qtgafile.h:31
@ IdLength
Definition qtgafile.h:26
@ CMapLength
Definition qtgafile.h:30
@ ImageDescriptor
Definition qtgafile.h:37
@ YOffset
Definition qtgafile.h:33
@ PixelDepth
Definition qtgafile.h:36
@ CMapStart
Definition qtgafile.h:29
@ HeaderSize
Definition qtgafile.h:38
@ ImageType
Definition qtgafile.h:28
@ XOffset
Definition qtgafile.h:32
Compression compression() const
Definition qtgafile.h:113
QImage readImage()
Definition qtgafile.cpp:181
int xOffset() const
Definition qtgafile.h:88
Combined button and popup list for selecting options.
#define Q_DECLARE_TR_FUNCTIONS(context)
unsigned short quint16
Definition qtypes.h:48