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
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
4#include "qtgahandler.h"
5#include "qtgafile.h"
6
7#include <QtCore/QVariant>
8#include <QtCore/QDebug>
9#include <QtGui/QImage>
10
12
15 , tga(0)
16{
17}
18
20{
21 delete tga;
22}
23
25{
26 if (!tga)
27 tga = new QTgaFile(device());
28 if (tga->isValid())
29 {
30 setFormat("tga");
31 return true;
32 }
33 qWarning("QTgaHandler::canRead(): %s", qPrintable(tga->errorMessage()));
34 return false;
35}
36
38{
39 if (!device) {
40 qWarning("QTgaHandler::canRead() called with no device");
41 return false;
42 }
43
44 // TGA reader implementation needs a seekable QIODevice, so
45 // sequential devices are not supported
46 if (device->isSequential())
47 return false;
48 qint64 pos = device->pos();
49 bool isValid;
50 {
51 QTgaFile tga(device);
52 isValid = tga.isValid();
53 }
54 device->seek(pos);
55 return isValid;
56}
57
59{
60 if (!canRead())
61 return false;
62 *image = tga->readImage();
63 return !image->isNull();
64}
65
67{
68 if (option == Size && canRead()) {
69 return tga->size();
70 } else if (option == CompressionRatio) {
71 return tga->compression();
72 } else if (option == ImageFormat) {
74 }
75 return QVariant();
76}
77
83
85{
86 return option == CompressionRatio
87 || option == Size
88 || option == ImageFormat;
89}
90
IOBluetoothDevice * device
\inmodule QtCore \reentrant
Definition qiodevice.h:34
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.
ImageOption
This enum describes the different options supported by QImageIOHandler.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32
Definition qimage.h:47
bool isValid() const
Definition qtgafile.h:69
QSize size() const
Definition qtgafile.h:108
QString errorMessage() const
Definition qtgafile.h:74
Compression compression() const
Definition qtgafile.h:113
QImage readImage()
Definition qtgafile.cpp:181
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,...
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
Definition image.cpp:4
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
GLuint GLenum option
#define qPrintable(string)
Definition qstring.h:1531
#define Q_UNUSED(x)
long long qint64
Definition qtypes.h:60