summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Tomkins <toby.tomkins@nokia.com>2012-02-06 11:42:06 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-08 11:15:48 +0100
commit2e2fa4802fad88371aaf20a6b83a29a103e88e35 (patch)
tree3b88412ee4fe648fc14f67806f0cc4af910eb0d9
parentf68a3dc48d8fb8c04fe49dd9e5d07d7cdd221ad1 (diff)
Move tga support from Qt3d to QtImageFormats.
Rev-By: Samuel Rodal Fix-for: QTBUG-21955 Part of fix for https://bugreports.qt.nokia.com/browse/QTBUG-21955 Having tga plugin inside a Qt add-on causes packaging problems. There have been many queries over the years for tga support even tho it is a niche image format. It is particularly useful for OpenGL work as a texture format since it is a blittable bitmap, but it is very innefficient compared to png or jpg. For this reason only read support is added, and this is documented. Also add one unit test. (based on cherry picked from Qt 4.8 commit 951a997893407b0a26f21fe0acec4701fa3d4279) Adds code removed from Qt3D. http://codereview.qt-project.org/#change,13898 Conflicts: tests/auto/qimagereader/qimagereader.pro tests/auto/qimagereader/tst_qimagereader.cpp Change-Id: Ia1b7420dd3461cb1d2f1d857d11444a0a533de43 Reviewed-by: Sarah Jane Smith <sarah.j.smith@nokia.com> Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
-rw-r--r--src/plugins/imageformats/imageformats.pro3
-rw-r--r--src/plugins/imageformats/tga/main.cpp95
-rw-r--r--src/plugins/imageformats/tga/qtgafile.cpp266
-rw-r--r--src/plugins/imageformats/tga/qtgafile.h157
-rw-r--r--src/plugins/imageformats/tga/qtgahandler.cpp131
-rw-r--r--src/plugins/imageformats/tga/qtgahandler.h74
-rw-r--r--src/plugins/imageformats/tga/tga.pro15
-rw-r--r--tests/auto/auto.pro3
-rw-r--r--tests/auto/tga/tga.pro11
-rw-r--r--tests/auto/tga/tst_qtga.cpp76
-rw-r--r--tests/shared/images/tga.qrc5
-rw-r--r--tests/shared/images/tga/test-flag.tgabin0 -> 480044 bytes
12 files changed, 834 insertions, 2 deletions
diff --git a/src/plugins/imageformats/imageformats.pro b/src/plugins/imageformats/imageformats.pro
index 793221c..70ee4ae 100644
--- a/src/plugins/imageformats/imageformats.pro
+++ b/src/plugins/imageformats/imageformats.pro
@@ -1,3 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS =
+SUBDIRS = \
+ tga
contains(QT_CONFIG, system-zlib): SUBDIRS += mng tiff
diff --git a/src/plugins/imageformats/tga/main.cpp b/src/plugins/imageformats/tga/main.cpp
new file mode 100644
index 0000000..246c329
--- /dev/null
+++ b/src/plugins/imageformats/tga/main.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the TGA plugin in the Qt ImageFormats module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QImageIOHandler>
+#include <QtCore/QDebug>
+
+#ifndef QT_NO_IMAGEFORMATPLUGIN
+
+#ifdef QT_NO_IMAGEFORMAT_TGA
+#undef QT_NO_IMAGEFORMAT_TGA
+#endif
+
+#include "qtgahandler.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTgaPlugin : public QImageIOPlugin
+{
+public:
+ Capabilities capabilities(QIODevice * device, const QByteArray & format) const;
+ QImageIOHandler * create(QIODevice * device, const QByteArray & format = QByteArray()) const;
+ QStringList keys() const;
+};
+
+QImageIOPlugin::Capabilities QTgaPlugin::capabilities(QIODevice *device, const QByteArray &format) const
+{
+ if (format == "tga")
+ return Capabilities(CanRead);
+ if (!format.isEmpty())
+ return 0;
+ if (!device->isOpen())
+ return 0;
+
+ Capabilities cap;
+ if (device->isReadable() && QTgaHandler::canRead(device))
+ cap |= CanRead;
+ return cap;
+}
+
+QImageIOHandler* QTgaPlugin::create(QIODevice *device, const QByteArray &format) const
+{
+ QImageIOHandler *tgaHandler = new QTgaHandler();
+ tgaHandler->setDevice(device);
+ tgaHandler->setFormat(format);
+ return tgaHandler;
+}
+
+QStringList QTgaPlugin::keys() const
+{
+ return QStringList() << QLatin1String("tga");
+}
+
+Q_EXPORT_PLUGIN2(qtga, QTgaPlugin)
+
+QT_END_NAMESPACE
+
+#endif /* QT_NO_IMAGEFORMATPLUGIN */
diff --git a/src/plugins/imageformats/tga/qtgafile.cpp b/src/plugins/imageformats/tga/qtgafile.cpp
new file mode 100644
index 0000000..98b8852
--- /dev/null
+++ b/src/plugins/imageformats/tga/qtgafile.cpp
@@ -0,0 +1,266 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the TGA plugin in the Qt ImageFormats module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtgafile.h"
+
+#include <QtCore/QIODevice>
+#include <QtCore/QDebug>
+#include <QtCore/QDateTime>
+
+struct TgaReader
+{
+ virtual ~TgaReader() {}
+ virtual QRgb operator()(QIODevice *s) const = 0;
+};
+
+struct Tga16Reader : public TgaReader
+{
+ ~Tga16Reader() {}
+ QRgb operator()(QIODevice *s) const
+ {
+ char ch1, ch2;
+ if (s->getChar(&ch1) && s->getChar(&ch2)) {
+ quint16 d = (int(ch1) & 0xFF) | ((int(ch2) & 0xFF) << 8);
+ QRgb result = (d & 0x8000) ? 0xFF000000 : 0x00000000;
+ result |= (d & 0x7C00 << 6) | (d & 0x03E0 << 3) | (d & 0x001F);
+ return result;
+ } else {
+ return 0;
+ }
+ }
+};
+
+struct Tga24Reader : public TgaReader
+{
+ QRgb operator()(QIODevice *s) const
+ {
+ char r, g, b;
+ if (s->getChar(&b) && s->getChar(&g) && s->getChar(&r))
+ return qRgb(uchar(r), uchar(g), uchar(b));
+ else
+ return 0;
+ }
+};
+
+struct Tga32Reader : public TgaReader
+{
+ QRgb operator()(QIODevice *s) const
+ {
+ char r, g, b, a;
+ if (s->getChar(&b) && s->getChar(&g) && s->getChar(&r) && s->getChar(&a))
+ return qRgba(uchar(r), uchar(g), uchar(b), uchar(a));
+ else
+ return 0;
+ }
+};
+
+/*!
+ \class QTgaFile
+ \since 4.8
+ \internal
+
+ File data container for a TrueVision Graphics format file.
+
+ Format is as described here:
+ http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/
+ http://netghost.narod.ru/gff2/graphics/summary/tga.htm
+
+ Usage is:
+ \code
+ QTgaFile tga(myFile);
+ QImage tgaImage;
+ if (tga.isValid())
+ tgaImage = tga.readImage();
+ \endcode
+
+ The class is designed to handle sequential and non-sequential
+ sources, so during construction the mHeader is read. Then during
+ the readImage() call the rest of the data is read.
+
+ After passing myFile to the constructor, if the QIODevice *myFile
+ is read, or has seek() called, the results are undefined - so don't
+ do that.
+*/
+
+/*!
+ Construct a new QTgaFile object getting data from \a device.
+
+ The object does not take ownership of the \a device, but until the
+ object is destroyed do not do any non-const operations, eg seek or
+ read on the device.
+*/
+QTgaFile::QTgaFile(QIODevice *device)
+ : mDevice(device)
+{
+ ::memset(mHeader, 0, HeaderSize);
+ if (!mDevice->isReadable())
+ {
+ mErrorMessage = QObject::tr("Could not read image data");
+ return;
+ }
+ if (mDevice->isSequential())
+ {
+ mErrorMessage = QObject::tr("Sequential device (eg socket) for image read not supported");
+ return;
+ }
+ if (!mDevice->seek(0))
+ {
+ mErrorMessage = QObject::tr("Seek file/device for image read failed");
+ return;
+ }
+ int bytes = device->read((char*)mHeader, HeaderSize);
+ if (bytes != HeaderSize)
+ {
+ mErrorMessage = QObject::tr("Image mHeader read failed");
+ return;
+ }
+ if (mHeader[ImageType] != 2)
+ {
+ // TODO: should support other image types
+ mErrorMessage = QObject::tr("Image type not supported");
+ return;
+ }
+ int bitsPerPixel = mHeader[PixelDepth];
+ bool validDepth = (bitsPerPixel == 16 || bitsPerPixel == 24 || bitsPerPixel == 32);
+ if (!validDepth)
+ {
+ mErrorMessage = QObject::tr("Image dpeth not valid");
+ }
+ int curPos = mDevice->pos();
+ int fileBytes = mDevice->size();
+ if (!mDevice->seek(fileBytes - FooterSize))
+ {
+ mErrorMessage = QObject::tr("Could not seek to image read footer");
+ return;
+ }
+ char footer[FooterSize];
+ bytes = mDevice->read((char*)footer, FooterSize);
+ if (bytes != FooterSize)
+ {
+ mErrorMessage = QObject::tr("Could not read footer");
+ }
+ if (qstrncmp(&footer[SignatureOffset], "TRUEVISION-XFILE", 16) != 0)
+ {
+ mErrorMessage = QObject::tr("Image type (non-TrueVision 2.0) not supported");
+ }
+ if (!mDevice->seek(curPos))
+ {
+ mErrorMessage = QObject::tr("Could not reset to read data");
+ }
+}
+
+/*!
+ \internal
+ Destroy the device, recovering any resources.
+*/
+QTgaFile::~QTgaFile()
+{
+}
+
+/*!
+ \internal
+ Reads an image file from the QTgaFile's device, and returns it.
+
+ This method seeks to the absolute position of the image data in the file,
+ so no assumptions are made about where the devices read pointer is when this
+ method is called. For this reason only random access devices are supported.
+
+ If the constructor completed successfully, such that isValid() returns true,
+ then this method is likely to succeed, unless the file is somehow corrupted.
+
+ In the case that the read fails, the QImage returned will be null, such that
+ QImage::isNull() will be true.
+*/
+QImage QTgaFile::readImage()
+{
+ if (!isValid())
+ return QImage();
+
+ int offset = mHeader[IdLength]; // Mostly always zero
+
+ // Even in TrueColor files a color pallette may be present
+ if (mHeader[ColorMapType] == 1)
+ offset += littleEndianInt(&mHeader[CMapLength]) * littleEndianInt(&mHeader[CMapDepth]);
+
+ mDevice->seek(HeaderSize + offset);
+
+ char dummy;
+ for (int i = 0; i < offset; ++i)
+ mDevice->getChar(&dummy);
+
+ int bitsPerPixel = mHeader[PixelDepth];
+ int imageWidth = width();
+ int imageHeight = height();
+
+ unsigned char desc = mHeader[ImageDescriptor];
+ //unsigned char xCorner = desc & 0x10; // 0 = left, 1 = right
+ unsigned char yCorner = desc & 0x20; // 0 = lower, 1 = upper
+
+ QImage im(imageWidth, imageHeight, QImage::Format_ARGB32);
+ TgaReader *reader = 0;
+ if (bitsPerPixel == 16)
+ reader = new Tga16Reader();
+ else if (bitsPerPixel == 24)
+ reader = new Tga24Reader();
+ else if (bitsPerPixel == 32)
+ reader = new Tga32Reader();
+ TgaReader &read = *reader;
+
+ // For now only deal with yCorner, since no one uses xCorner == 1
+ // Also this is upside down, since Qt has the origin flipped
+ if (yCorner)
+ {
+ for (int y = 0; y < imageHeight; ++y)
+ for (int x = 0; x < imageWidth; ++x)
+ im.setPixel(x, y, read(mDevice));
+ }
+ else
+ {
+ for (int y = imageHeight - 1; y >= 0; --y)
+ for (int x = 0; x < imageWidth; ++x)
+ im.setPixel(x, y, read(mDevice));
+ }
+
+ delete reader;
+
+ // TODO: add processing of TGA extension information - ie TGA 2.0 files
+ return im;
+}
diff --git a/src/plugins/imageformats/tga/qtgafile.h b/src/plugins/imageformats/tga/qtgafile.h
new file mode 100644
index 0000000..8aaaf1c
--- /dev/null
+++ b/src/plugins/imageformats/tga/qtgafile.h
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the TGA plugin in the Qt ImageFormats module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTGAFILE_H
+#define QTGAFILE_H
+
+#include <QtGui/QColor>
+#include <QtGui/QImage>
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+
+class QTgaFile
+{
+public:
+ enum Compression {
+ NoCompression = 0,
+ RleCompression = 1
+ };
+
+ enum HeaderOffset {
+ IdLength = 0, /* 00h Size of Image ID field */
+ ColorMapType = 1, /* 01h Color map type */
+ ImageType = 2, /* 02h Image type code */
+ CMapStart = 3, /* 03h Color map origin */
+ CMapLength = 5, /* 05h Color map length */
+ CMapDepth = 7, /* 07h Depth of color map entries */
+ XOffset = 8, /* 08h X origin of image */
+ YOffset = 10, /* 0Ah Y origin of image */
+ Width = 12, /* 0Ch Width of image */
+ Height = 14, /* 0Eh Height of image */
+ PixelDepth = 16, /* 10h Image pixel size */
+ ImageDescriptor = 17, /* 11h Image descriptor byte */
+ HeaderSize = 18
+ };
+
+ enum FooterOffset {
+ ExtensionOffset = 0,
+ DeveloperOffset = 4,
+ SignatureOffset = 8,
+ FooterSize = 26
+ };
+
+ QTgaFile(QIODevice *);
+ ~QTgaFile();
+
+ inline bool isValid() const;
+ inline QString errorMessage() const;
+ QImage readImage();
+ inline int xOffset() const;
+ inline int yOffset() const;
+ inline int width() const;
+ inline int height() const;
+ inline QSize size() const;
+ inline Compression compression() const;
+
+private:
+ static inline quint16 littleEndianInt(const unsigned char *d);
+
+ QString mErrorMessage;
+ unsigned char mHeader[HeaderSize];
+ QIODevice *mDevice;
+};
+
+inline bool QTgaFile::isValid() const
+{
+ return mErrorMessage.isEmpty();
+}
+
+inline QString QTgaFile::errorMessage() const
+{
+ return mErrorMessage;
+}
+
+/*!
+ \internal
+ Returns the integer encoded in the two little endian bytes at \a d.
+*/
+inline quint16 QTgaFile::littleEndianInt(const unsigned char *d)
+{
+ return d[0] + d[1] * 256;
+}
+
+inline int QTgaFile::xOffset() const
+{
+ return littleEndianInt(&mHeader[XOffset]);
+}
+
+inline int QTgaFile::yOffset() const
+{
+ return littleEndianInt(&mHeader[YOffset]);
+}
+
+inline int QTgaFile::width() const
+{
+ return littleEndianInt(&mHeader[Width]);
+}
+
+inline int QTgaFile::height() const
+{
+ return littleEndianInt(&mHeader[Height]);
+}
+
+inline QSize QTgaFile::size() const
+{
+ return QSize(width(), height());
+}
+
+inline QTgaFile::Compression QTgaFile::compression() const
+{
+ // TODO: for now, only handle type 2 files, with no color table
+ // and no compression
+ return NoCompression;
+}
+
+QT_END_NAMESPACE
+
+#endif // QTGAFILE_H
diff --git a/src/plugins/imageformats/tga/qtgahandler.cpp b/src/plugins/imageformats/tga/qtgahandler.cpp
new file mode 100644
index 0000000..2fa0530
--- /dev/null
+++ b/src/plugins/imageformats/tga/qtgahandler.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the TGA plugin in the Qt ImageFormats module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtgahandler.h"
+#include "qtgafile.h"
+
+#include <QtCore/QVariant>
+#include <QtCore/QDebug>
+#include <QtGui/QImage>
+
+QT_BEGIN_NAMESPACE
+
+QTgaHandler::QTgaHandler()
+ : QImageIOHandler()
+ , tga(0)
+{
+}
+
+QTgaHandler::~QTgaHandler()
+{
+ delete tga;
+}
+
+bool QTgaHandler::canRead() const
+{
+ if (!tga)
+ tga = new QTgaFile(device());
+ if (tga->isValid())
+ {
+ setFormat("tga");
+ return true;
+ }
+ return false;
+}
+
+bool QTgaHandler::canRead(QIODevice *device)
+{
+ if (!device) {
+ qWarning("QTgaHandler::canRead() called with no device");
+ return false;
+ }
+
+ // TGA reader implementation needs a seekable QIODevice, so
+ // sequential devices are not supported
+ qint64 pos = device->pos();
+ bool isValid;
+ {
+ QTgaFile tga(device);
+ isValid = tga.isValid();
+ }
+ device->seek(pos);
+ return isValid;
+}
+
+bool QTgaHandler::read(QImage *image)
+{
+ if (!canRead())
+ return false;
+ *image = tga->readImage();
+ return !image->isNull();
+}
+
+QByteArray QTgaHandler::name() const
+{
+ return "tga";
+}
+
+QVariant QTgaHandler::option(ImageOption option) const
+{
+ if (option == Size && canRead()) {
+ return tga->size();
+ } else if (option == CompressionRatio) {
+ return tga->compression();
+ } else if (option == ImageFormat) {
+ return QImage::Format_ARGB32;
+ }
+ return QVariant();
+}
+
+void QTgaHandler::setOption(ImageOption option, const QVariant &value)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(value);
+}
+
+bool QTgaHandler::supportsOption(ImageOption option) const
+{
+ return option == CompressionRatio
+ || option == Size
+ || option == ImageFormat;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/imageformats/tga/qtgahandler.h b/src/plugins/imageformats/tga/qtgahandler.h
new file mode 100644
index 0000000..dc7cfe2
--- /dev/null
+++ b/src/plugins/imageformats/tga/qtgahandler.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the TGA plugin in the Qt ImageFormats module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTGAHANDLER_H
+#define QTGAHANDLER_H
+
+#include <QtGui/QImageIOHandler>
+
+QT_BEGIN_NAMESPACE
+
+class QTgaFile;
+
+class QTgaHandler : public QImageIOHandler
+{
+public:
+ QTgaHandler();
+ ~QTgaHandler();
+
+ bool canRead() const;
+ bool read(QImage *image);
+
+ QByteArray name() const;
+
+ static bool canRead(QIODevice *device);
+
+ QVariant option(ImageOption option) const;
+ void setOption(ImageOption option, const QVariant &value);
+ bool supportsOption(ImageOption option) const;
+
+private:
+ mutable QTgaFile *tga;
+};
+
+QT_END_NAMESPACE
+
+#endif // QTGAHANDLER_H
diff --git a/src/plugins/imageformats/tga/tga.pro b/src/plugins/imageformats/tga/tga.pro
new file mode 100644
index 0000000..dc6c965
--- /dev/null
+++ b/src/plugins/imageformats/tga/tga.pro
@@ -0,0 +1,15 @@
+TARGET = qtga
+load(qt_plugin)
+
+HEADERS += qtgahandler.h \
+ qtgafile.h
+SOURCES += qtgahandler.cpp \
+ qtgafile.cpp
+
+SOURCES += main.cpp
+
+DESTDIR = $$QT.gui.plugins/imageformats
+target.path += $$[QT_INSTALL_PLUGINS]/imageformats
+INSTALLS += target
+
+symbian: TARGET.UID3=0x20031E99
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 793221c..70ee4ae 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,3 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS =
+SUBDIRS = \
+ tga
contains(QT_CONFIG, system-zlib): SUBDIRS += mng tiff
diff --git a/tests/auto/tga/tga.pro b/tests/auto/tga/tga.pro
new file mode 100644
index 0000000..3dd9064
--- /dev/null
+++ b/tests/auto/tga/tga.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = tst_qtga
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT = core gui testlib
+CONFIG -= app_bundle
+CONFIG += testcase
+
+SOURCES += tst_qtga.cpp
+RESOURCES += $$PWD/../../shared/images/tga.qrc
diff --git a/tests/auto/tga/tst_qtga.cpp b/tests/auto/tga/tst_qtga.cpp
new file mode 100644
index 0000000..ff53e83
--- /dev/null
+++ b/tests/auto/tga/tst_qtga.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the TGA autotests in the Qt ImageFormats module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtGui/QtGui>
+
+class tst_qtga: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void readImage_data();
+ void readImage();
+};
+
+void tst_qtga::readImage_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QSize>("size");
+
+ QTest::newRow("test-flag") << QString("test-flag.tga") << QSize(400, 400);
+}
+
+void tst_qtga::readImage()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QSize, size);
+
+ QString path = QString(":/tga/") + fileName;
+ QImageReader reader(path);
+ QVERIFY(reader.canRead());
+ QImage image = reader.read();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.size(), size);
+}
+
+QTEST_MAIN(tst_qtga)
+#include "tst_qtga.moc"
diff --git a/tests/shared/images/tga.qrc b/tests/shared/images/tga.qrc
new file mode 100644
index 0000000..1388451
--- /dev/null
+++ b/tests/shared/images/tga.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>tga/test-flag.tga</file>
+ </qresource>
+</RCC>
diff --git a/tests/shared/images/tga/test-flag.tga b/tests/shared/images/tga/test-flag.tga
new file mode 100644
index 0000000..c6d0c89
--- /dev/null
+++ b/tests/shared/images/tga/test-flag.tga
Binary files differ