Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
12
QT_BEGIN_NAMESPACE
13
14
QTgaHandler::QTgaHandler()
15
: QImageIOHandler()
16
, tga(0)
17
{
18
}
19
20
QTgaHandler
::~
QTgaHandler
()
21
{
22
delete
tga;
23
}
24
25
bool
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
38
bool
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
59
bool
QTgaHandler
::
read
(QImage *image)
60
{
61
if
(!
canRead
(
)
)
62
return
false
;
63
*image = tga->readImage();
64
return
!image->isNull();
65
}
66
67
QVariant
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
79
void
QTgaHandler
::
setOption
(ImageOption option,
const
QVariant &value)
80
{
81
Q_UNUSED(option);
82
Q_UNUSED(value);
83
}
84
85
bool
QTgaHandler
::
supportsOption
(ImageOption option)
const
86
{
87
return
option == CompressionRatio
88
|| option == Size
89
|| option == ImageFormat;
90
}
91
92
QT_END_NAMESPACE
QTgaFile
Definition
qtgafile.h:17
QTgaFile::isValid
bool isValid() const
Definition
qtgafile.h:70
QTgaFile::QTgaFile
QTgaFile(QIODevice *)
Construct a new QTgaFile object getting data from device.
Definition
qtgafile.cpp:102
QTgaHandler
Definition
qtgahandler.h:16
QTgaHandler::~QTgaHandler
~QTgaHandler()
Definition
qtgahandler.cpp:20
QTgaHandler::setOption
void setOption(ImageOption option, const QVariant &value) override
Sets the option option with the value value.
Definition
qtgahandler.cpp:79
QTgaHandler::option
QVariant option(ImageOption option) const override
Returns the value assigned to option as a QVariant.
Definition
qtgahandler.cpp:67
QTgaHandler::read
bool read(QImage *image) override
Read an image from the device, and stores it in image.
Definition
qtgahandler.cpp:59
QTgaHandler::supportsOption
bool supportsOption(ImageOption option) const override
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
Definition
qtgahandler.cpp:85
QTgaHandler::canRead
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
Definition
qtgahandler.cpp:25
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtimageformats
src
plugins
imageformats
tga
qtgahandler.cpp
Generated on
for Qt by
1.18.0