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
qtgahandler.cpp
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#include "qtgahandler.h"
6#include "qtgafile.h"
7
8#include <QtCore/QVariant>
9#include <QtCore/QDebug>
10#include <QtGui/QImage>
11
13
14QTgaHandler::QTgaHandler()
15 : QImageIOHandler()
16 , tga(0)
17{
18}
19
21{
22 delete tga;
23}
24
25bool QTgaHandler::canRead() const
26{
27 if (!tga)
28 tga = new QTgaFile(device());
29 if (tga->isValid())
30 {
31 setFormat("tga");
32 return true;
33 }
34 qWarning("QTgaHandler::canRead(): %s", qPrintable(tga->errorMessage()));
35 return false;
36}
37
38bool QTgaHandler::canRead(QIODevice *device)
39{
40 if (!device) {
41 qWarning("QTgaHandler::canRead() called with no device");
42 return false;
43 }
44
45 // TGA reader implementation needs a seekable QIODevice, so
46 // sequential devices are not supported
47 if (device->isSequential())
48 return false;
49 qint64 pos = device->pos();
50 bool isValid;
51 {
52 QTgaFile tga(device);
53 isValid = tga.isValid();
54 }
55 device->seek(pos);
56 return isValid;
57}
58
59bool QTgaHandler::read(QImage *image)
60{
61 if (!canRead())
62 return false;
63 *image = tga->readImage();
64 return !image->isNull();
65}
66
67QVariant QTgaHandler::option(ImageOption option) const
68{
69 if (option == Size && canRead()) {
70 return tga->size();
71 } else if (option == CompressionRatio) {
72 return tga->compression();
73 } else if (option == ImageFormat) {
74 return QImage::Format_ARGB32;
75 }
76 return QVariant();
77}
78
79void QTgaHandler::setOption(ImageOption option, const QVariant &value)
80{
81 Q_UNUSED(option);
82 Q_UNUSED(value);
83}
84
85bool QTgaHandler::supportsOption(ImageOption option) const
86{
87 return option == CompressionRatio
88 || option == Size
89 || option == ImageFormat;
90}
91
92QT_END_NAMESPACE
bool isValid() const
Definition qtgafile.h:70
QTgaFile(QIODevice *)
Construct a new QTgaFile object getting data from device.
Definition qtgafile.cpp:102
void setOption(ImageOption option, const QVariant &value) override
Sets the option option with the value value.
QVariant option(ImageOption option) const override
Returns the value assigned to option as a QVariant.
bool read(QImage *image) override
Read an image from the device, and stores it in image.
bool supportsOption(ImageOption option) const override
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...