Qt 4.8
qtgafile.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQuick3D module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTGAFILE_H
43 #define QTGAFILE_H
44 
45 #include <QtGui/QColor>
46 #include <QtGui/QImage>
47 
49 
50 class QIODevice;
51 
52 class QTgaFile
53 {
54 public:
55  enum Compression {
58  };
59 
60  enum HeaderOffset {
61  IdLength = 0, /* 00h Size of Image ID field */
62  ColorMapType = 1, /* 01h Color map type */
63  ImageType = 2, /* 02h Image type code */
64  CMapStart = 3, /* 03h Color map origin */
65  CMapLength = 5, /* 05h Color map length */
66  CMapDepth = 7, /* 07h Depth of color map entries */
67  XOffset = 8, /* 08h X origin of image */
68  YOffset = 10, /* 0Ah Y origin of image */
69  Width = 12, /* 0Ch Width of image */
70  Height = 14, /* 0Eh Height of image */
71  PixelDepth = 16, /* 10h Image pixel size */
72  ImageDescriptor = 17, /* 11h Image descriptor byte */
74  };
75 
76  enum FooterOffset {
81  };
82 
84  ~QTgaFile();
85 
86  inline bool isValid() const;
87  inline QString errorMessage() const;
88  QImage readImage();
89  inline int xOffset() const;
90  inline int yOffset() const;
91  inline int width() const;
92  inline int height() const;
93  inline QSize size() const;
94  inline Compression compression() const;
95 
96 private:
97  static inline quint16 littleEndianInt(const unsigned char *d);
98 
100  unsigned char mHeader[HeaderSize];
102 };
103 
104 inline bool QTgaFile::isValid() const
105 {
106  return mErrorMessage.isEmpty();
107 }
108 
110 {
111  return mErrorMessage;
112 }
113 
121 inline quint16 QTgaFile::littleEndianInt(const unsigned char *d)
122 {
123  return d[0] + d[1] * 256;
124 }
125 
126 inline int QTgaFile::xOffset() const
127 {
128  return littleEndianInt(&mHeader[XOffset]);
129 }
130 
131 inline int QTgaFile::yOffset() const
132 {
133  return littleEndianInt(&mHeader[YOffset]);
134 }
135 
136 inline int QTgaFile::width() const
137 {
138  return littleEndianInt(&mHeader[Width]);
139 }
140 
141 inline int QTgaFile::height() const
142 {
143  return littleEndianInt(&mHeader[Height]);
144 }
145 
146 inline QSize QTgaFile::size() const
147 {
148  return QSize(width(), height());
149 }
150 
152 {
153  // TODO: for now, only handle type 2 files, with no color table
154  // and no compression
155  return NoCompression;
156 }
157 
159 
160 #endif // QTGAFILE_H
double d
Definition: qnumeric_p.h:62
Compression compression() const
Definition: qtgafile.h:151
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
FooterOffset
Definition: qtgafile.h:76
QTgaFile(QIODevice *)
Construct a new QTgaFile object getting data from device.
Definition: qtgafile.cpp:130
The QString class provides a Unicode character string.
Definition: qstring.h:83
HeaderOffset
Definition: qtgafile.h:60
QImage readImage()
Reads an image file from the QTgaFile&#39;s device, and returns it.
Definition: qtgafile.cpp:220
QString mErrorMessage
Definition: qtgafile.h:99
QIODevice * mDevice
Definition: qtgafile.h:101
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString errorMessage() const
Definition: qtgafile.h:109
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned char mHeader[HeaderSize]
Definition: qtgafile.h:100
int xOffset() const
Definition: qtgafile.h:126
bool isValid() const
Definition: qtgafile.h:104
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
Compression
Definition: qtgafile.h:55
static quint16 littleEndianInt(const unsigned char *d)
Returns the integer encoded in the two little endian bytes at d.
Definition: qtgafile.h:121
~QTgaFile()
Destroy the device, recovering any resources.
Definition: qtgafile.cpp:199
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
int width() const
Definition: qtgafile.h:136
int height() const
Definition: qtgafile.h:141
int yOffset() const
Definition: qtgafile.h:131
QSize size() const
Definition: qtgafile.h:146