| 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 | #include <QtGui/QImageIOHandler> | 
| 5 | #include <QtCore/QDebug> | 
| 6 | |
| 7 | #ifndef QT_NO_IMAGEFORMATPLUGIN | 
| 8 | |
| 9 | #ifdef QT_NO_IMAGEFORMAT_TGA | 
| 10 | #undef QT_NO_IMAGEFORMAT_TGA | 
| 11 | #endif | 
| 12 | |
| 13 | #include "qtgahandler.h" | 
| 14 | |
| 15 | QT_BEGIN_NAMESPACE | 
| 16 | |
| 17 | class QTgaPlugin : public QImageIOPlugin | 
| 18 | { | 
| 19 | Q_OBJECT | 
| 20 |     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface"FILE "tga.json")  | 
| 21 | |
| 22 | public: | 
| 23 | Capabilities capabilities(QIODevice * device, const QByteArray & format) const override; | 
| 24 | QImageIOHandler * create(QIODevice * device, const QByteArray & format = QByteArray()) const override; | 
| 25 | }; | 
| 26 | |
| 27 | QImageIOPlugin::Capabilities QTgaPlugin::capabilities(QIODevice *device, const QByteArray &format) const | 
| 28 | { | 
| 29 |     if (format == "tga")  | 
| 30 | return Capabilities(CanRead); | 
| 31 | Capabilities cap; | 
| 32 | if (!format.isEmpty()) | 
| 33 | return cap; | 
| 34 | if (!device->isOpen()) | 
| 35 | return cap; | 
| 36 | |
| 37 | if (device->isReadable() && QTgaHandler::canRead(device)) | 
| 38 | cap |= CanRead; | 
| 39 | return cap; | 
| 40 | } | 
| 41 | |
| 42 | QImageIOHandler* QTgaPlugin::create(QIODevice *device, const QByteArray &format) const | 
| 43 | { | 
| 44 | QImageIOHandler *tgaHandler = new QTgaHandler(); | 
| 45 | tgaHandler->setDevice(device); | 
| 46 | tgaHandler->setFormat(format); | 
| 47 | return tgaHandler; | 
| 48 | } | 
| 49 | |
| 50 | QT_END_NAMESPACE | 
| 51 | |
| 52 | #include "main.moc" | 
| 53 | |
| 54 | #endif /* QT_NO_IMAGEFORMATPLUGIN */ | 
| 55 | 
