mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-07-18 03:54:18 -04:00
* speeds up incremental builds as changes to a header will not always
need the full mocs_compilation.cpp for all the target's headers rebuild,
while having a moc file sourced into a source file only adds minor
extra costs, due to small own code and the used headers usually
already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
resulting in those quickly processed, while the minor extra cost of the
sourced moc files does not outweigh that in summary.
Measured times actually improved by some percent points.
(ideally CMake would just skip empty mocs_compilation.cpp & its object
file one day)
* enables compiler to see all methods of a class in same compilation unit
to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
moc code being sourced into the cpp file there definitions can be ensured
and often are already for the needs of the normal class methods
(cherry picked from commit 34ed3bad27
)
99 lines
2.2 KiB
C++
99 lines
2.2 KiB
C++
/*
|
|
This file is part of the KDE project
|
|
SPDX-FileCopyrightText: 2013 Boudewijn Rempt <boud@valdyas.org>
|
|
|
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
This code is based on Thacher Ulrich PSD loading code released
|
|
on public domain. See: http://tulrich.com/geekstuff/
|
|
*/
|
|
|
|
#include "ora.h"
|
|
|
|
#include <QImage>
|
|
#include <QScopedPointer>
|
|
|
|
#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()
|
|
{
|
|
}
|
|
|
|
bool OraHandler::canRead() const
|
|
{
|
|
if (canRead(device())) {
|
|
setFormat("ora");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool OraHandler::read(QImage *image)
|
|
{
|
|
KZip zip(device());
|
|
if (!zip.open(QIODevice::ReadOnly)) {
|
|
return false;
|
|
}
|
|
|
|
const KArchiveEntry *entry = zip.directory()->entry(QStringLiteral("mergedimage.png"));
|
|
if (!entry || !entry->isFile()) {
|
|
return false;
|
|
}
|
|
|
|
const KZipFileEntry *fileZipEntry = static_cast<const KZipFileEntry *>(entry);
|
|
|
|
image->loadFromData(fileZipEntry->data(), "PNG");
|
|
|
|
return true;
|
|
}
|
|
|
|
bool OraHandler::canRead(QIODevice *device)
|
|
{
|
|
if (!device) {
|
|
qWarning("OraHandler::canRead() called with no device");
|
|
return false;
|
|
}
|
|
if (device->isSequential()) {
|
|
return false;
|
|
}
|
|
|
|
char buff[54];
|
|
if (device->peek(buff, sizeof(buff)) == sizeof(buff)) {
|
|
return memcmp(buff + 0x26, s_magic, s_magic_size) == 0;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
QImageIOPlugin::Capabilities OraPlugin::capabilities(QIODevice *device, const QByteArray &format) const
|
|
{
|
|
if (format == "ora" || format == "ORA") {
|
|
return Capabilities(CanRead);
|
|
}
|
|
if (!format.isEmpty()) {
|
|
return {};
|
|
}
|
|
if (!device->isOpen()) {
|
|
return {};
|
|
}
|
|
|
|
Capabilities cap;
|
|
if (device->isReadable() && OraHandler::canRead(device)) {
|
|
cap |= CanRead;
|
|
}
|
|
return cap;
|
|
}
|
|
|
|
QImageIOHandler *OraPlugin::create(QIODevice *device, const QByteArray &format) const
|
|
{
|
|
QImageIOHandler *handler = new OraHandler;
|
|
handler->setDevice(device);
|
|
handler->setFormat(format);
|
|
return handler;
|
|
}
|
|
|
|
#include "moc_ora.cpp"
|