Compare commits

...

46 Commits

Author SHA1 Message Date
b14ef357e5 GIT_SILENT Upgrade ECM and KF5 version requirements for 5.63.0 release. 2019-10-06 09:35:52 +00:00
bf5502403e Add files for testing bug411327 2019-09-20 23:18:17 +02:00
5c4c05257c xcf: Fix regression when reading files with "unsupported" properties
Summary:
The fact that we don't know the property is most of the times not fatal,
so what we have to do is just "skip" the property and hope for the best

BUGS: 411327

Reviewers: cfeck, apol, vkrause

Reviewed By: vkrause

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D24114
2019-09-20 22:41:26 +02:00
7afaacb093 xcf: Properly read image resolution
Summary:
QDataStream reads 64 bits when reading into a float unless you tell it to use SinglePrecision,
since floats in xcf are 32 bit, do that

Reviewers: cfeck, apol, vkrause

Reviewed By: vkrause

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D24113
2019-09-20 22:41:03 +02:00
68bb1a0ee7 Port HDR (Radiance RGBE) image loader to Qt5
Tested with HDR images from hdrihaven.com
* Loading in KolourPaint works
* Thumbnails in Dolphin work

Reviewed by: aacid

Differential Revision: https://phabricator.kde.org/D23811
2019-09-14 14:05:30 +02:00
9a9ac6e8fe GIT_SILENT Upgrade ECM and KF5 version requirements for 5.62.0 release. 2019-09-07 12:35:26 +00:00
4bf2894bde Fix uninitialized memory read
Summary:
Make sure whole of pixel_size in pixel has data either because it was
read or because we set it to 0

oss-fuzz/14565

Reviewers: dfaure, apol, vkrause

Reviewed By: vkrause

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D23739
2019-09-05 20:05:35 +02:00
40353da5db GIT_SILENT Upgrade ECM and KF5 version requirements for 5.61.0 release. 2019-08-03 19:33:24 +00:00
068e711847 Remove explicit use of ECM_KDE_MODULE_DIR, is part of ECM_MODULE_PATH
GIT_SILENT
2019-08-02 22:54:45 +02:00
90ba55d982 Remove unused pnm.desktop file 2019-07-20 11:29:31 +02:00
e3603bc748 GIT_SILENT Upgrade ECM and KF5 version requirements for 5.60.0 release. 2019-07-06 13:15:48 +00:00
75ef81a109 QImage::byteCount -> QImage::sizeInByes 2019-07-04 22:26:53 +02:00
bff22e2a76 GIT_SILENT Upgrade Qt5 version requirement to 5.11.0. 2019-07-04 19:23:58 +02:00
0196444a99 GIT_SILENT Upgrade ECM and KF5 version requirements for 5.59.0 release. 2019-06-01 16:38:28 +00:00
90f340df24 GIT_SILENT Upgrade ECM and KF5 version requirements for 5.58.0 release. 2019-05-04 22:44:00 +00:00
1a9b5d6cb6 tga: don't try to read more than max_palette_size into palette 2019-05-01 01:51:42 +02:00
96b1d7e7bc tga: memset dst if read fails 2019-05-01 01:51:39 +02:00
bcce48012e tga: memset the whole palette array, not only the palette_size 2019-05-01 01:44:47 +02:00
0db5c89c5f Initialize the unread bits of _starttab
oss-fuzz #14446
2019-04-25 23:08:17 +02:00
6fea48c4ee xcf: Fix uninitialized memory use on broken documents
oss-fuzz #14312
2019-04-17 20:09:49 +02:00
645daec1ef ras: Don't overread input on malformed files 2019-04-17 20:03:52 +02:00
aaa285a3b9 xcf: layer is const in copy and merge, mark it as such 2019-04-17 17:37:28 +02:00
35e64c44d8 No & is a bit faster here 2019-04-17 17:37:28 +02:00
26b796f67d const & is a bit faster here 2019-04-17 17:37:28 +02:00
4692a34a1c QStringLiteral is a bit faster here 2019-04-17 17:37:28 +02:00
c0656c5181 GIT_SILENT Upgrade ECM and KF5 version requirements for 5.57.0 release. 2019-04-07 07:18:46 +00:00
83d1ca90d9 Fix compilation
Summary:
Seems only gcc can do a constexpr with strlen.

This fixes the build with clang, hopefully to with MSVC?

Reviewers: svuorela

Reviewed By: svuorela

Subscribers: svuorela, apol, pino, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D20149
2019-03-31 22:18:16 +02:00
fd4fb6f596 ora:kra: qstrcmp -> memcmp
i..e don't check strings but memory

Makes oss-fuzz happier.

Reviewers: svuorela

Reviewed By: svuorela

Subscribers: apol, pino, security-team, rempt, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D20143
2019-03-31 21:32:07 +02:00
a24ece396a autotests: Also exercise canRead 2019-03-31 20:58:26 +02:00
9fc6967f4f Fix RGBHandler::canRead
Summary:
As one can see in SGIImage::readImage the accepted images are

    _stream >> u16;
    if (u16 != 0x01da) {
        return false;
    }

    _stream >> _rle;
    if (_rle > 1) {
        return false;
    }

so not only \x01\xda\x01 but also \x01\xda\x00

Reviewers: svuorela

Reviewed By: svuorela

Subscribers: svuorela, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D20145
2019-03-31 19:44:21 +02:00
bd704045e6 xcf: Don't crash with files with unsupported layer modes 2019-03-31 01:35:33 +01:00
af7a89fea7 GIT_SILENT: add gitignore 2019-03-04 07:03:36 +01:00
5989bba56a GIT_SILENT Upgrade ECM and KF5 version requirements for 5.56.0 release. 2019-03-02 13:27:12 +00:00
20100a1e0e ras: fix crash on broken files
Replace QVector::operator[] with QVector::value() since we can't know for
sure the values will be on range so use value() that gives us a 0 if the
index is not on range

oss-fuzz/13462
2019-03-01 23:33:35 +01:00
297b168a52 Use auto here too 2019-02-28 23:03:25 +01:00
f1c6c15b06 compile without foreach
Summary: compile without foreach

Reviewers: dfaure, apol

Reviewed By: apol

Subscribers: apol, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D19317
2019-02-28 23:02:41 +01:00
156bac5e54 ras: protect the palette QVector too
oss-fuzz/13068
2019-02-13 23:50:36 +01:00
d79c11d280 ras: tweak max file check
better to do - 32 than + 32 otherwise we may overflow

oss-fuzz/13017
2019-02-11 22:57:33 +01:00
aeec934839 xcf: Fix uninitialized memory use on broken documents
oss-fuzz/12871
2019-02-08 23:27:03 +01:00
0c4f2f8e62 add const, helps understand the function better 2019-02-08 23:07:56 +01:00
4a8da73f0e ras: tweak max size that "fits" in a QVector
oss-fuzz/12951
2019-02-07 22:14:22 +01:00
039d7d8fbe ras: don't assert because we try to allicate a huge vector
oss-fuzz/12915
2019-02-06 22:06:58 +01:00
b072484dbb ras: Protect against divide by zero
oss-fuzz/12905
2019-02-05 19:51:24 +01:00
bad90cea4b xcf: Don't divide by 0
oss-fuzz/12815
2019-02-03 14:06:33 +01:00
a51cbd865f tga: fail gracefully if readRawData errors
oss-fuzz/12818
2019-02-03 13:49:11 +01:00
1a31500e55 ras: fail gracefully on height*width*bpp > length
oss-fuzz/12822
2019-02-03 13:38:44 +01:00
26 changed files with 294 additions and 122 deletions

21
.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
# Ignore the following files
*~
*.[oa]
*.diff
*.kate-swp
*.kdev4
.kdev_include_paths
*.kdevelop.pcs
*.moc
*.moc.cpp
*.orig
*.user
.*.swp
.swp.*
Doxyfile
Makefile
avail
random_seed
/build*/
CMakeLists.txt.user*
*.unc-backup*

View File

@ -3,12 +3,12 @@ cmake_minimum_required(VERSION 3.5)
project(KImageFormats)
include(FeatureSummary)
find_package(ECM 5.55.0 NO_MODULE)
find_package(ECM 5.63.0 NO_MODULE)
set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules")
feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(KDEInstallDirs)
include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
@ -17,7 +17,7 @@ include(KDECMakeSettings)
include(CheckIncludeFiles)
set(REQUIRED_QT_VERSION 5.10.0)
set(REQUIRED_QT_VERSION 5.11.0)
find_package(Qt5Gui ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE)
find_package(KF5Archive)
@ -45,7 +45,7 @@ set_package_properties(OpenEXR PROPERTIES
TYPE OPTIONAL
PURPOSE "Required for the QImage plugin for OpenEXR images"
)
add_definitions(-DQT_NO_FOREACH)
add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(autotests)

View File

@ -55,6 +55,7 @@ endmacro()
# Loads each <format> image in read/<format>/, and compares the
# result against the data read from the corresponding png file
kimageformats_read_tests(
hdr
pcx
psd
ras

View File

@ -210,11 +210,11 @@ private Q_SLOTS:
QFile picDumpFile(fileNameBase + QStringLiteral("-expected.data"));
QVERIFY2(picDumpFile.open(QIODevice::WriteOnly), qPrintable(picDumpFile.errorString()));
picDumpFile.write(reinterpret_cast<const char *>(inputImage.bits()),
inputImage.byteCount());
inputImage.sizeInBytes());
QFile pngDumpFile(fileNameBase + QStringLiteral("-actual.data"));
QVERIFY2(pngDumpFile.open(QIODevice::WriteOnly), qPrintable(pngDumpFile.errorString()));
pngDumpFile.write(reinterpret_cast<const char *>(expImage.bits()),
expImage.byteCount());
expImage.sizeInBytes());
QString msg = QStringLiteral("Read image (")
+ picDumpFile.fileName()
+ QStringLiteral(") differed from expected image (")

BIN
autotests/read/hdr/rgb.hdr Normal file

Binary file not shown.

BIN
autotests/read/hdr/rgb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

View File

@ -35,8 +35,8 @@ static void writeImageData(const char *name, const QString &filename, const QIma
{
QFile file(filename);
if (file.open(QIODevice::WriteOnly)) {
qint64 written = file.write(reinterpret_cast<const char *>(image.bits()), image.byteCount());
if (written == image.byteCount()) {
qint64 written = file.write(reinterpret_cast<const char *>(image.bits()), image.sizeInBytes());
if (written == image.sizeInBytes()) {
QTextStream(stdout) << " " << name
<< " written to " << filename << "\n";
} else {
@ -127,7 +127,8 @@ int main(int argc, char ** argv)
<< "Starting basic read tests for "
<< suffix << " images *********\n";
foreach (QFileInfo fi, imgdir.entryInfoList()) {
const QFileInfoList lstImgDir = imgdir.entryInfoList();
for (const QFileInfo &fi : lstImgDir) {
int suffixPos = fi.filePath().count() - suffix.count();
QString inputfile = fi.filePath();
QString expfile = fi.filePath().replace(suffixPos, suffix.count(), QStringLiteral("png"));
@ -147,6 +148,14 @@ int main(int argc, char ** argv)
++failed;
continue;
}
if (!inputReader.canRead()) {
QTextStream(stdout) << "FAIL : " << fi.fileName()
<< ": failed can read: "
<< inputReader.errorString()
<< "\n";
++failed;
continue;
}
if (!inputReader.read(&inputImage)) {
QTextStream(stdout) << "FAIL : " << fi.fileName()
<< ": failed to load: "

View File

@ -73,8 +73,8 @@ int main(int argc, char ** argv)
QTextStream(stdout) << "********* "
<< "Starting basic write tests for "
<< suffix << " images *********\n";
foreach (QFileInfo fi, imgdir.entryInfoList()) {
const QFileInfoList lstImgDir = imgdir.entryInfoList();
for (const QFileInfo &fi : lstImgDir) {
int suffixPos = fi.filePath().count() - suffix.count();
QString pngfile = fi.filePath().replace(suffixPos, suffix.count(), QStringLiteral("png"));
QString pngfilename = QFileInfo(pngfile).fileName();

View File

@ -53,6 +53,11 @@ endif()
##################################
kimageformats_add_plugin(kimg_hdr JSON "hdr.json" SOURCES hdr.cpp)
install(FILES hdr.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/qimageioplugins/)
##################################
kimageformats_add_plugin(kimg_pcx JSON "pcx.json" SOURCES pcx.cpp)
install(FILES pcx.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/qimageioplugins/)

View File

@ -82,7 +82,7 @@ void K_IStream::clear()
* format into the normal 32 bit pixel format. Process is from the
* ILM code.
*/
QRgb RgbaToQrgba(struct Imf::Rgba imagePixel)
QRgb RgbaToQrgba(struct Imf::Rgba &imagePixel)
{
float r, g, b, a;

View File

@ -15,7 +15,7 @@
#include <QDebug>
typedef Q_UINT8 uchar;
typedef unsigned char uchar;
namespace // Private.
{
@ -93,19 +93,22 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i
uchar val, code;
// Create dst image.
if (!img.create(width, height, 32)) {
img = QImage(width, height, QImage::Format_RGB32);
if (img.isNull()) {
return false;
}
QMemArray<uchar> image(width * 4);
QByteArray lineArray;
lineArray.resize(4 * width);
uchar *image = (uchar *) lineArray.data();
for (int cline = 0; cline < height; cline++) {
QRgb *scanline = (QRgb *) img.scanLine(cline);
// determine scanline type
if ((width < MINELEN) || (MAXELEN < width)) {
Read_Old_Line(image.data(), width, s);
RGBE_To_QRgbLine(image.data(), scanline, width);
Read_Old_Line(image, width, s);
RGBE_To_QRgbLine(image, scanline, width);
continue;
}
@ -116,9 +119,9 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i
}
if (val != 2) {
s.device()->at(s.device()->at() - 1);
Read_Old_Line(image.data(), width, s);
RGBE_To_QRgbLine(image.data(), scanline, width);
s.device()->ungetChar(val);
Read_Old_Line(image, width, s);
RGBE_To_QRgbLine(image, scanline, width);
continue;
}
@ -132,8 +135,8 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i
if ((image[1] != 2) || (image[2] & 128)) {
image[0] = 2;
Read_Old_Line(image.data() + 4, width - 1, s);
RGBE_To_QRgbLine(image.data(), scanline, width);
Read_Old_Line(image + 4, width - 1, s);
RGBE_To_QRgbLine(image, scanline, width);
continue;
}
@ -168,7 +171,7 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i
}
}
RGBE_To_QRgbLine(image.data(), scanline, width);
RGBE_To_QRgbLine(image, scanline, width);
}
return true;
@ -176,7 +179,7 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i
} // namespace
Q_DECL_EXPORT void kimgio_hdr_read(QImageIO *io)
bool HDRHandler::read(QImage *outImage)
{
int len;
char line[MAXLINE];
@ -185,7 +188,7 @@ Q_DECL_EXPORT void kimgio_hdr_read(QImageIO *io)
// Parse header
do {
len = io->ioDevice()->readLine(line, MAXLINE);
len = device()->readLine(line, MAXLINE);
/*if (strcmp(line, "#?RADIANCE\n") == 0 || strcmp(line, "#?RGBE\n") == 0)
{
@ -199,12 +202,10 @@ Q_DECL_EXPORT void kimgio_hdr_read(QImageIO *io)
if (/*!validHeader ||*/ !validFormat) {
// qDebug() << "Unknown HDR format.";
io->setImage(0);
io->setStatus(-1);
return;
return false;
}
io->ioDevice()->readLine(line, MAXLINE);
device()->readLine(line, MAXLINE);
char s1[3], s2[3];
int width, height;
@ -212,27 +213,67 @@ Q_DECL_EXPORT void kimgio_hdr_read(QImageIO *io)
//if( sscanf(line, "-Y %d +X %d", &height, &width) < 2 )
{
// qDebug() << "Invalid HDR file.";
io->setImage(0);
io->setStatus(-1);
return;
return false;
}
QDataStream s(io->ioDevice());
QDataStream s(device());
QImage img;
if (!LoadHDR(s, width, height, img)) {
// qDebug() << "Error loading HDR file.";
io->setImage(0);
io->setStatus(-1);
return;
return false;
}
io->setImage(img);
io->setStatus(0);
*outImage = img;
return true;
}
Q_DECL_EXPORT void kimgio_hdr_write(QImageIO *)
HDRHandler::HDRHandler()
{
// intentionally not implemented (since writing low dynamic range data to a HDR file is nonsense.)
}
bool HDRHandler::canRead() const
{
if (canRead(device())) {
setFormat("hdr");
return true;
}
return false;
}
bool HDRHandler::canRead(QIODevice *device)
{
if (!device) {
qWarning("HDRHandler::canRead() called with no device");
return false;
}
return device->peek(11) == "#?RADIANCE\n" || device->peek(7) == "#?RGBE\n";
}
QImageIOPlugin::Capabilities HDRPlugin::capabilities(QIODevice *device, const QByteArray &format) const
{
if (format == "hdr") {
return Capabilities(CanRead);
}
if (!format.isEmpty()) {
return {};
}
if (!device->isOpen()) {
return {};
}
Capabilities cap;
if (device->isReadable() && HDRHandler::canRead(device)) {
cap |= CanRead;
}
return cap;
}
QImageIOHandler *HDRPlugin::create(QIODevice *device, const QByteArray &format) const
{
QImageIOHandler *handler = new HDRHandler;
handler->setDevice(device);
handler->setFormat(format);
return handler;
}

View File

@ -0,0 +1,4 @@
{
"Keys": [ "hdr" ],
"MimeTypes": [ "image/x-hdr", "image/vnd.radiance" ]
}

View File

@ -10,12 +10,27 @@
#ifndef KIMG_HDR_P_H
#define KIMG_HDR_P_H
class QImageIO;
#include <QImageIOPlugin>
extern "C" {
void kimgio_hdr_read(QImageIO *);
void kimgio_hdr_write(QImageIO *);
}
class HDRHandler : public QImageIOHandler
{
public:
HDRHandler();
#endif
bool canRead() const override;
bool read(QImage *outImage) override;
static bool canRead(QIODevice *device);
};
class HDRPlugin : public QImageIOPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "hdr.json")
public:
Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
};
#endif // KIMG_HDR_P_H

View File

@ -18,6 +18,9 @@
#include <QIODevice>
#include <QFile>
static constexpr char s_magic[] = "application/x-krita";
static constexpr int s_magic_size = sizeof(s_magic) - 1; // -1 to remove the last \0
KraHandler::KraHandler()
{
}
@ -36,7 +39,7 @@ bool KraHandler::read(QImage *image)
KZip zip(device());
if (!zip.open(QIODevice::ReadOnly)) return false;
const KArchiveEntry *entry = zip.directory()->entry(QLatin1String("mergedimage.png"));
const KArchiveEntry *entry = zip.directory()->entry(QStringLiteral("mergedimage.png"));
if (!entry || !entry->isFile()) return false;
const KZipFileEntry* fileZipEntry = static_cast<const KZipFileEntry*>(entry);
@ -55,7 +58,7 @@ bool KraHandler::canRead(QIODevice *device)
char buff[57];
if (device->peek(buff, sizeof(buff)) == sizeof(buff))
return qstrcmp(buff + 0x26, "application/x-krita") == 0;
return memcmp(buff + 0x26, s_magic, s_magic_size) == 0;
return false;
}

View File

@ -17,6 +17,9 @@
#include <kzip.h>
static constexpr char s_magic[] = "image/openraster";
static constexpr int s_magic_size = sizeof(s_magic) - 1; // -1 to remove the last \0
OraHandler::OraHandler()
{
}
@ -35,7 +38,7 @@ bool OraHandler::read(QImage *image)
KZip zip(device());
if (!zip.open(QIODevice::ReadOnly)) return false;
const KArchiveEntry *entry = zip.directory()->entry(QLatin1String("mergedimage.png"));
const KArchiveEntry *entry = zip.directory()->entry(QStringLiteral("mergedimage.png"));
if (!entry || !entry->isFile()) return false;
const KZipFileEntry* fileZipEntry = static_cast<const KZipFileEntry*>(entry);
@ -54,7 +57,7 @@ bool OraHandler::canRead(QIODevice *device)
char buff[54];
if (device->peek(buff, sizeof(buff)) == sizeof(buff))
return qstrcmp(buff + 0x26, "image/openraster") == 0;
return memcmp(buff + 0x26, s_magic, s_magic_size) == 0;
return false;
}

View File

@ -23,7 +23,7 @@ public:
quint8 g;
quint8 b;
static RGB from(const QRgb &color)
static RGB from(const QRgb color)
{
RGB c;
c.r = qRed(color);
@ -169,7 +169,7 @@ static QDataStream &operator>>(QDataStream &s, PCXHEADER &ph)
return s;
}
static QDataStream &operator<<(QDataStream &s, const RGB &rgb)
static QDataStream &operator<<(QDataStream &s, const RGB rgb)
{
s << rgb.r << rgb.g << rgb.b;

View File

@ -173,9 +173,9 @@ static QDataStream &operator<< (QDataStream &s, const QList<PicChannel> &channel
return s;
}
static bool readRow(QDataStream &stream, QRgb *row, quint16 width, QList<PicChannel> channels)
static bool readRow(QDataStream &stream, QRgb *row, quint16 width, const QList<PicChannel> &channels)
{
Q_FOREACH(const PicChannel &channel, channels) {
for(const PicChannel &channel : channels) {
auto readPixel = [&] (QDataStream &str) -> QRgb {
quint8 red = 0;
if (channel.code & RED) {
@ -242,7 +242,7 @@ bool SoftimagePICHandler::read(QImage *image)
}
QImage::Format fmt = QImage::Format_RGB32;
Q_FOREACH(const PicChannel &channel, m_channels) {
for (const PicChannel &channel : qAsConst(m_channels)) {
if (channel.size != 8) {
// we cannot read images that do not come in bytes
qDebug() << "Channel size was" << channel.size;
@ -388,8 +388,8 @@ void SoftimagePICHandler::setOption(ImageOption option, const QVariant &value)
break;
case Description: {
m_description.clear();
QStringList entries = value.toString().split(QStringLiteral("\n\n"));
Q_FOREACH(const QString entry, entries) {
const QStringList entries = value.toString().split(QStringLiteral("\n\n"));
for (const QString &entry : entries) {
if (entry.startsWith(QStringLiteral("Description: "))) {
m_description = entry.mid(13).simplified().toUtf8();
}
@ -425,7 +425,7 @@ QVariant SoftimagePICHandler::option(ImageOption option) const
return QString();
case ImageFormat:
if (const_cast<SoftimagePICHandler*>(this)->readChannels()) {
Q_FOREACH (const PicChannel &channel, m_channels) {
for (const PicChannel &channel : qAsConst(m_channels)) {
if (channel.code & ALPHA) {
return QImage::Format_ARGB32;
}

View File

@ -1,7 +0,0 @@
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=QImageIOPlugins
X-KDE-ImageFormat=pnm
X-KDE-MimeType=image/x-portable-anymap
X-KDE-Read=true
X-KDE-Write=false

View File

@ -102,6 +102,13 @@ static bool IsSupported(const RasHeader &head)
static bool LoadRAS(QDataStream &s, const RasHeader &ras, QImage &img)
{
s.device()->seek(RasHeader::SIZE);
// QVector uses some extra space for stuff, hence the 32 here suggested by thiago
if (ras.ColorMapLength > std::numeric_limits<int>::max() - 32) {
qWarning() << "LoadRAS() unsupported image color map length in file header" << ras.ColorMapLength;
return false;
}
// Read palette if needed.
QVector<quint8> palette(ras.ColorMapLength);
if (ras.ColorMapType == 1) {
@ -110,19 +117,36 @@ static bool LoadRAS(QDataStream &s, const RasHeader &ras, QImage &img)
}
}
const int bpp = ras.Depth / 8;
if (ras.Height == 0) {
return false;
}
if (bpp == 0) {
return false;
}
if (ras.Length / ras.Height / bpp < ras.Width) {
qWarning() << "LoadRAS() mistmatch between height and width" << ras.Width << ras.Height << ras.Length << ras.Depth;
return false;
}
// QVector uses some extra space for stuff, hence the 32 here suggested by thiago
if (ras.Length > std::numeric_limits<int>::max() - 32) {
qWarning() << "LoadRAS() unsupported image length in file header" << ras.Length;
return false;
}
// each line must be a factor of 16 bits, so they may contain padding
// this will be 1 if padding required, 0 otherwise
int paddingrequired = (ras.Width * (ras.Depth / 8) % 2);
const int paddingrequired = (ras.Width * bpp % 2);
// qDebug() << "paddingrequired: " << paddingrequired;
// don't trust ras.Length
QVector<quint8> input(ras.Length);
int i = 0;
while (! s.atEnd()) {
while (! s.atEnd() && i < input.size()) {
s >> input[i];
// I guess we need to find out if we're at the end of a line
if (paddingrequired && i != 0 && !(i % (ras.Width * (ras.Depth / 8)))) {
if (paddingrequired && i != 0 && !(i % (ras.Width * bpp))) {
s >> input[i];
}
i++;
@ -140,9 +164,9 @@ static bool LoadRAS(QDataStream &s, const RasHeader &ras, QImage &img)
quint8 red, green, blue;
for (quint32 y = 0; y < ras.Height; y++) {
for (quint32 x = 0; x < ras.Width; x++) {
red = palette[(int)input[y * ras.Width + x]];
green = palette[(int)input[y * ras.Width + x] + (ras.ColorMapLength / 3)];
blue = palette[(int)input[y * ras.Width + x] + 2 * (ras.ColorMapLength / 3)];
red = palette.value((int)input[y * ras.Width + x]);
green = palette.value((int)input[y * ras.Width + x] + (ras.ColorMapLength / 3));
blue = palette.value((int)input[y * ras.Width + x] + 2 * (ras.ColorMapLength / 3));
img.setPixel(x, y, qRgb(red, green, blue));
}
}

View File

@ -336,6 +336,9 @@ bool SGIImage::readImage(QImage &img)
_stream >> _starttab[l];
_starttab[l] -= 512 + _numrows * 2 * sizeof(quint32);
}
for (; l < _numrows; l++) {
_starttab[l] = 0;
}
_lengthtab = new quint32[_numrows];
for (l = 0; l < _numrows; l++) {
@ -709,7 +712,7 @@ bool RGBHandler::canRead(QIODevice *device)
device->seek(oldPos);
}
return head.size() >= 4 && head.startsWith("\x01\xda\x01") && (head[3] == 1 || head[3] == 2);
return head.size() >= 4 && head.startsWith("\x01\xda") && (head[2] == 0 || head[2] == 1) && (head[3] == 1 || head[3] == 2);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -201,13 +201,20 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
}
// Read palette.
char palette[768];
static const int max_palette_size = 768;
char palette[max_palette_size];
if (info.pal) {
// @todo Support palettes in other formats!
const int size = 3 * tga.colormap_length;
const int dataRead = s.readRawData(palette, size);
if (dataRead < size) {
memset(&palette[dataRead], 0, size - dataRead);
const int palette_size = 3 * tga.colormap_length;
if (palette_size > max_palette_size) {
return false;
}
const int dataRead = s.readRawData(palette, palette_size);
if (dataRead < 0) {
return false;
}
if (dataRead < max_palette_size) {
memset(&palette[dataRead], 0, max_palette_size - dataRead);
}
}
@ -245,7 +252,10 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
// RLE pixels.
assert(pixel_size <= 8);
char pixel[8];
s.readRawData(pixel, pixel_size);
const int dataRead = s.readRawData(pixel, pixel_size);
if (dataRead < (int)pixel_size) {
memset(&pixel[dataRead], 0, pixel_size - dataRead);
}
do {
memcpy(dst, pixel, pixel_size);
dst += pixel_size;
@ -253,13 +263,24 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
} else {
// Raw pixels.
count *= pixel_size;
s.readRawData(dst, count);
const int dataRead = s.readRawData(dst, count);
if (dataRead < 0) {
free(image);
return false;
}
if ((uint)dataRead < count) {
memset(&dst[dataRead], 0, count - dataRead);
}
dst += count;
}
}
} else {
// Read raw image.
const int dataRead = s.readRawData((char *)image, size);
if (dataRead < 0) {
free(image);
return false;
}
if (dataRead < size) {
memset(&image[dataRead], 0, size - dataRead);
}

View File

@ -167,11 +167,11 @@ private:
//! The bottom-most layer is copied into the final QImage by this
//! routine.
typedef void (*PixelCopyOperation)(Layer &layer, uint i, uint j, int k, int l,
typedef void (*PixelCopyOperation)(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
//! Higher layers are merged into the final QImage by this routine.
typedef void (*PixelMergeOperation)(Layer &layer, uint i, uint j, int k, int l,
typedef void (*PixelMergeOperation)(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
//! Layer mode static data.
@ -201,37 +201,37 @@ private:
int data_length, qint32 bpp);
static void copyLayerToImage(XCFImage &xcf_image);
static void copyRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
static void copyRGBToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void copyGrayToGray(Layer &layer, uint i, uint j, int k, int l,
static void copyGrayToGray(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void copyGrayToRGB(Layer &layer, uint i, uint j, int k, int l,
static void copyGrayToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void copyGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
static void copyGrayAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void copyIndexedToIndexed(Layer &layer, uint i, uint j, int k, int l,
static void copyIndexedToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void copyIndexedAToIndexed(Layer &layer, uint i, uint j, int k, int l,
static void copyIndexedAToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void copyIndexedAToRGB(Layer &layer, uint i, uint j, int k, int l,
static void copyIndexedAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeLayerIntoImage(XCFImage &xcf_image);
static void mergeRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
static void mergeRGBToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeGrayToGray(Layer &layer, uint i, uint j, int k, int l,
static void mergeGrayToGray(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeGrayAToGray(Layer &layer, uint i, uint j, int k, int l,
static void mergeGrayAToGray(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeGrayToRGB(Layer &layer, uint i, uint j, int k, int l,
static void mergeGrayToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
static void mergeGrayAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeIndexedToIndexed(Layer &layer, uint i, uint j, int k, int l,
static void mergeIndexedToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeIndexedAToIndexed(Layer &layer, uint i, uint j, int k, int l,
static void mergeIndexedAToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void mergeIndexedAToRGB(Layer &layer, uint i, uint j, int k, int l,
static void mergeIndexedAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n);
static void initializeRandomTable();
@ -244,6 +244,12 @@ bool XCFImageFormat::random_table_initialized;
QVector<QRgb> XCFImageFormat::grayTable;
template <typename T, size_t N>
constexpr size_t countof(T(&)[N])
{
return N;
}
const XCFImageFormat::LayerModes XCFImageFormat::layer_modes[] = {
{true}, // NORMAL_MODE
{true}, // DISSOLVE_MODE
@ -270,7 +276,7 @@ const XCFImageFormat::LayerModes XCFImageFormat::layer_modes[] = {
};
//! Change a QRgb value's alpha only.
inline QRgb qRgba(const QRgb &rgb, int a)
inline QRgb qRgba(const QRgb rgb, int a)
{
return ((a & 0xff) << 24 | (rgb & RGB_MASK));
}
@ -408,6 +414,7 @@ bool XCFImageFormat::loadImageProperties(QDataStream &xcf_io, XCFImage &xcf_imag
break;
case PROP_RESOLUTION:
property.setFloatingPointPrecision(QDataStream::SinglePrecision);
property >> xcf_image.x_resolution >> xcf_image.y_resolution;
break;
@ -478,9 +485,15 @@ bool XCFImageFormat::loadImageProperties(QDataStream &xcf_io, XCFImage &xcf_imag
* \return true if there were no IO errors. */
bool XCFImageFormat::loadProperty(QDataStream &xcf_io, PropType &type, QByteArray &bytes, quint32 &rawType)
{
quint32 size;
xcf_io >> rawType;
if (rawType >= MAX_SUPPORTED_PROPTYPE) {
type = MAX_SUPPORTED_PROPTYPE;
// we don't support the property, but we still need to read from the device, assume it's like all the
// non custom properties that is data_length + data
xcf_io >> size;
xcf_io.skipRawData(size);
// return true because we don't really want to totally fail on an unsupported property since it may not be fatal
return true;
}
@ -488,7 +501,6 @@ bool XCFImageFormat::loadProperty(QDataStream &xcf_io, PropType &type, QByteArra
type = PropType(rawType);
char *data = nullptr;
quint32 size;
// The colormap property size is not the correct number of bytes:
// The GIMP source xcf.c has size = 4 + ncolors, but it should be
@ -709,6 +721,10 @@ bool XCFImageFormat::loadLayerProperties(QDataStream &xcf_io, Layer &layer)
case PROP_MODE:
property >> layer.mode;
if (layer.mode >= countof(layer_modes)) {
qWarning() << "Found layer with unsupported mode" << layer.mode << "Defaulting to mode 0";
layer.mode = 0;
}
break;
case PROP_TATTOO:
@ -901,7 +917,7 @@ void XCFImageFormat::setPalette(XCFImage &xcf_image, QImage &image)
void XCFImageFormat::assignImageBytes(Layer &layer, uint i, uint j)
{
QImage &image = layer.image_tiles[j][i];
uchar *tile = layer.tile;
const uchar *tile = layer.tile;
const int width = image.width();
const int height = image.height();
const int bytesPerLine = image.bytesPerLine();
@ -1063,6 +1079,16 @@ bool XCFImageFormat::loadLevel(QDataStream &xcf_io, Layer &layer, qint32 bpp)
xcf_io >> width >> height >> offset;
if (offset == 0) {
// offset 0 with rowsxcols != 0 is probably an error since it means we have tiles
// without data but just clear the bits for now instead of returning false
for (uint j = 0; j < layer.nrows; j++) {
for (uint i = 0; i < layer.ncols; i++) {
layer.image_tiles[j][i].fill(Qt::transparent);
if (layer.type == GRAYA_GIMAGE || layer.type == INDEXEDA_GIMAGE) {
layer.alpha_tiles[j][i].fill(Qt::transparent);
}
}
}
return true;
}
@ -1623,7 +1649,7 @@ void XCFImageFormat::copyLayerToImage(XCFImage &xcf_image)
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyRGBToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);
@ -1654,7 +1680,7 @@ void XCFImageFormat::copyRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyGrayToGray(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyGrayToGray(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
int src = layer.image_tiles[j][i].pixelIndex(k, l);
@ -1674,7 +1700,7 @@ void XCFImageFormat::copyGrayToGray(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyGrayToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyGrayToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);
@ -1695,7 +1721,7 @@ void XCFImageFormat::copyGrayToRGB(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyGrayAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);
@ -1723,7 +1749,7 @@ void XCFImageFormat::copyGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyIndexedToIndexed(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyIndexedToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
int src = layer.image_tiles[j][i].pixelIndex(k, l);
@ -1741,7 +1767,7 @@ void XCFImageFormat::copyIndexedToIndexed(Layer &layer, uint i, uint j, int k, i
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyIndexedAToIndexed(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyIndexedAToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
uchar src = layer.image_tiles[j][i].pixelIndex(k, l);
@ -1776,7 +1802,7 @@ void XCFImageFormat::copyIndexedAToIndexed(Layer &layer, uint i, uint j, int k,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::copyIndexedAToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::copyIndexedAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);
@ -1913,7 +1939,7 @@ void XCFImageFormat::mergeLayerIntoImage(XCFImage &xcf_image)
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeRGBToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);
@ -2214,7 +2240,7 @@ void XCFImageFormat::mergeRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
uchar new_r, new_g, new_b, new_a;
new_a = dst_a + INT_MULT(OPAQUE_OPACITY - dst_a, src_a);
float src_ratio = (float)src_a / new_a;
const float src_ratio = new_a == 0 ? 1.0 : (float)src_a / new_a;
float dst_ratio = 1.0 - src_ratio;
new_r = (uchar)(src_ratio * src_r + dst_ratio * dst_r + EPSILON);
@ -2239,7 +2265,7 @@ void XCFImageFormat::mergeRGBToRGB(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeGrayToGray(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeGrayToGray(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
int src = layer.image_tiles[j][i].pixelIndex(k, l);
@ -2257,7 +2283,7 @@ void XCFImageFormat::mergeGrayToGray(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeGrayAToGray(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeGrayAToGray(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
int src = qGray(layer.image_tiles[j][i].pixel(k, l));
@ -2373,7 +2399,7 @@ void XCFImageFormat::mergeGrayAToGray(Layer &layer, uint i, uint j, int k, int l
uchar new_a = OPAQUE_OPACITY;
float src_ratio = (float)src_a / new_a;
const float src_ratio = new_a == 0 ? 1.0 : (float)src_a / new_a;
float dst_ratio = 1.0 - src_ratio;
uchar new_g = (uchar)(src_ratio * src + dst_ratio * dst + EPSILON);
@ -2394,7 +2420,7 @@ void XCFImageFormat::mergeGrayAToGray(Layer &layer, uint i, uint j, int k, int l
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeGrayToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeGrayToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);
@ -2415,7 +2441,7 @@ void XCFImageFormat::mergeGrayToRGB(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeGrayAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
int src = qGray(layer.image_tiles[j][i].pixel(k, l));
@ -2546,7 +2572,7 @@ void XCFImageFormat::mergeGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
uchar new_a = dst_a + INT_MULT(OPAQUE_OPACITY - dst_a, src_a);
float src_ratio = (float)src_a / new_a;
const float src_ratio = new_a == 0 ? 1.0 : (float)src_a / new_a;
float dst_ratio = 1.0 - src_ratio;
uchar new_g = (uchar)(src_ratio * src + dst_ratio * dst + EPSILON);
@ -2569,7 +2595,7 @@ void XCFImageFormat::mergeGrayAToRGB(Layer &layer, uint i, uint j, int k, int l,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeIndexedToIndexed(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeIndexedToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
int src = layer.image_tiles[j][i].pixelIndex(k, l);
@ -2587,7 +2613,7 @@ void XCFImageFormat::mergeIndexedToIndexed(Layer &layer, uint i, uint j, int k,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeIndexedAToIndexed(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeIndexedAToIndexed(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
uchar src = layer.image_tiles[j][i].pixelIndex(k, l);
@ -2619,7 +2645,7 @@ void XCFImageFormat::mergeIndexedAToIndexed(Layer &layer, uint i, uint j, int k,
* \param m x pixel of destination image.
* \param n y pixel of destination image.
*/
void XCFImageFormat::mergeIndexedAToRGB(Layer &layer, uint i, uint j, int k, int l,
void XCFImageFormat::mergeIndexedAToRGB(const Layer &layer, uint i, uint j, int k, int l,
QImage &image, int m, int n)
{
QRgb src = layer.image_tiles[j][i].pixel(k, l);

View File

@ -64,11 +64,13 @@ int main(int argc, char **argv)
if (parser.isSet(listformats)) {
QTextStream out(stdout);
out << "Input formats:\n";
foreach (const QByteArray &fmt, QImageReader::supportedImageFormats()) {
const auto lstReaderSupportedFormats = QImageReader::supportedImageFormats();
for (const QByteArray &fmt : lstReaderSupportedFormats) {
out << " " << fmt << '\n';
}
out << "Output formats:\n";
foreach (const QByteArray &fmt, QImageWriter::supportedImageFormats()) {
const auto lstWriterSupportedFormats = QImageWriter::supportedImageFormats();
for (const QByteArray &fmt : lstWriterSupportedFormats) {
out << " " << fmt << '\n';
}
return 0;

View File

@ -72,7 +72,8 @@ int main(int argc, char **argv)
if (parser.isSet(listformats)) {
QTextStream out(stdout);
out << "File formats:\n";
foreach (const QByteArray &fmt, QImageReader::supportedImageFormats()) {
const auto lstSupportedFormats = QImageReader::supportedImageFormats();
for (const auto &fmt : lstSupportedFormats) {
out << " " << fmt << '\n';
}
return 0;
@ -115,8 +116,8 @@ int main(int argc, char **argv)
}
img = img.convertToFormat(qformat);
}
qint64 written = output.write(reinterpret_cast<const char *>(img.bits()), img.byteCount());
if (written != img.byteCount()) {
qint64 written = output.write(reinterpret_cast<const char *>(img.bits()), img.sizeInBytes());
if (written != img.sizeInBytes()) {
QTextStream(stderr) << "Could not write image data to " << files.at(1)
<< ":" << output.errorString() << "\n";
return 5;