mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 17:08:08 -04:00
Add kra and ora imageio plugins (read-only)
kra is the native format for Krita and ora the interchange format for krita, gimp and mypaint (it's also mypaint's native format). Both formats are simply zip containers with an embedded png. REVIEW:126675
This commit is contained in:
parent
5d7ef7c38e
commit
6934d54417
@ -20,6 +20,12 @@ include(CheckIncludeFiles)
|
||||
set(REQUIRED_QT_VERSION 5.3.0)
|
||||
find_package(Qt5Gui ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE)
|
||||
|
||||
find_package(KF5Archive)
|
||||
set_package_properties(KF5Archive PROPERTIES
|
||||
TYPE OPTIONAL
|
||||
PURPOSE "Required for the QImage plugin for Krita and OpenRaster images"
|
||||
)
|
||||
|
||||
# EPS support depends on the gs utility; non-UNIX systems are unlikely to have
|
||||
# this available in PATH
|
||||
set(BUILD_EPS_PLUGIN FALSE)
|
||||
|
@ -61,6 +61,14 @@ kimageformats_read_tests(
|
||||
rgb
|
||||
tga
|
||||
)
|
||||
|
||||
if (KF5Archive_FOUND)
|
||||
kimageformats_read_tests(
|
||||
kra
|
||||
ora
|
||||
)
|
||||
endif()
|
||||
|
||||
# Allow some fuzziness when reading this formats, to allow for
|
||||
# rounding errors (eg: in alpha blending).
|
||||
kimageformats_read_tests(FUZZ 1
|
||||
|
BIN
autotests/read/kra/src.kra
Normal file
BIN
autotests/read/kra/src.kra
Normal file
Binary file not shown.
BIN
autotests/read/kra/src.png
Normal file
BIN
autotests/read/kra/src.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
autotests/read/ora/src.ora
Normal file
BIN
autotests/read/ora/src.ora
Normal file
Binary file not shown.
BIN
autotests/read/ora/src.png
Normal file
BIN
autotests/read/ora/src.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
@ -89,3 +89,20 @@ target_link_libraries(kimg_xcf Qt5::Gui)
|
||||
install(TARGETS kimg_xcf DESTINATION ${KDE_INSTALL_QTPLUGINDIR}/imageformats/)
|
||||
install(FILES xcf.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/qimageioplugins/)
|
||||
|
||||
##################################
|
||||
|
||||
if (KF5Archive_FOUND)
|
||||
|
||||
add_library(kimg_kra MODULE kra.cpp)
|
||||
target_link_libraries(kimg_kra Qt5::Gui KF5::Archive)
|
||||
|
||||
install(TARGETS kimg_kra DESTINATION ${KDE_INSTALL_QTPLUGINDIR}/imageformats/)
|
||||
install(FILES kra.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/qimageioplugins/)
|
||||
|
||||
add_library(kimg_ora MODULE ora.cpp)
|
||||
target_link_libraries(kimg_ora Qt5::Gui KF5::Archive)
|
||||
|
||||
install(TARGETS kimg_ora DESTINATION ${KDE_INSTALL_QTPLUGINDIR}/imageformats/)
|
||||
install(FILES ora.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}/qimageioplugins/)
|
||||
|
||||
endif()
|
||||
|
88
src/imageformats/kra.cpp
Normal file
88
src/imageformats/kra.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* This file is part of the KDE project
|
||||
Copyright (C) 2013 Boudewijn Rempt <boud@valdyas.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the Lesser GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This code is based on Thacher Ulrich PSD loading code released
|
||||
on public domain. See: http://tulrich.com/geekstuff/
|
||||
*/
|
||||
|
||||
#include "kra.h"
|
||||
|
||||
#include <kzip.h>
|
||||
|
||||
#include <QImage>
|
||||
#include <QIODevice>
|
||||
#include <QFile>
|
||||
|
||||
KraHandler::KraHandler()
|
||||
{
|
||||
}
|
||||
|
||||
bool KraHandler::canRead() const
|
||||
{
|
||||
if (canRead(device())) {
|
||||
setFormat("kra");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool KraHandler::read(QImage *image)
|
||||
{
|
||||
KZip zip(device());
|
||||
if (!zip.open(QIODevice::ReadOnly)) return false;
|
||||
|
||||
const KArchiveEntry *entry = zip.directory()->entry(QLatin1String("mergedimage.png"));
|
||||
if (!entry || !entry->isFile()) return false;
|
||||
|
||||
const KZipFileEntry* fileZipEntry = static_cast<const KZipFileEntry*>(entry);
|
||||
|
||||
image->loadFromData(fileZipEntry->data(), "PNG");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KraHandler::canRead(QIODevice *device)
|
||||
{
|
||||
if (!device) {
|
||||
qWarning("KraHandler::canRead() called with no device");
|
||||
return false;
|
||||
}
|
||||
|
||||
char buff[57];
|
||||
if (device->peek(buff, sizeof(buff)) == sizeof(buff))
|
||||
return qstrcmp(buff + 0x26, "application/x-krita") == 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QImageIOPlugin::Capabilities KraPlugin::capabilities(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
if (format == "kra" || format == "KRA") {
|
||||
return Capabilities(CanRead);
|
||||
}
|
||||
if (!format.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
if (!device->isOpen()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Capabilities cap;
|
||||
if (device->isReadable() && KraHandler::canRead(device)) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
QImageIOHandler *KraPlugin::create(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
QImageIOHandler *handler = new KraHandler;
|
||||
handler->setDevice(device);
|
||||
handler->setFormat(format);
|
||||
return handler;
|
||||
}
|
7
src/imageformats/kra.desktop
Normal file
7
src/imageformats/kra.desktop
Normal file
@ -0,0 +1,7 @@
|
||||
[Desktop Entry]
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=QImageIOPlugins
|
||||
X-KDE-ImageFormat=kra
|
||||
X-KDE-MimeType=application/x-krita
|
||||
X-KDE-Read=true
|
||||
X-KDE-Write=false
|
39
src/imageformats/kra.h
Normal file
39
src/imageformats/kra.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* This file is part of the KDE project
|
||||
Copyright (c) 2013 Boudewijn Rempt <boud@valdyas.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the Lesser GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef KIMG_KRA_H
|
||||
#define KIMG_KRA_H
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
|
||||
class KraHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
KraHandler();
|
||||
|
||||
bool canRead() const Q_DECL_OVERRIDE;
|
||||
bool read(QImage *image) Q_DECL_OVERRIDE;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
};
|
||||
|
||||
class KraPlugin : public QImageIOPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "kra.json")
|
||||
|
||||
public:
|
||||
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
|
||||
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
5
src/imageformats/kra.json
Normal file
5
src/imageformats/kra.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"Keys": [ "kra" ],
|
||||
"MimeTypes": [ "application/x-krita", "application/x-krita" ]
|
||||
}
|
||||
|
87
src/imageformats/ora.cpp
Normal file
87
src/imageformats/ora.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/* This file is part of the KDE project
|
||||
Copyright (C) 2013 Boudewijn Rempt <boud@valdyas.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the Lesser GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
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>
|
||||
|
||||
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(QLatin1String("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;
|
||||
}
|
||||
|
||||
char buff[54];
|
||||
if (device->peek(buff, sizeof(buff)) == sizeof(buff))
|
||||
return qstrcmp(buff + 0x26, "image/openraster") == 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 0;
|
||||
}
|
||||
if (!device->isOpen()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
7
src/imageformats/ora.desktop
Normal file
7
src/imageformats/ora.desktop
Normal file
@ -0,0 +1,7 @@
|
||||
[Desktop Entry]
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=QImageIOPlugins
|
||||
X-KDE-ImageFormat=ora
|
||||
X-KDE-MimeType=image/openraster
|
||||
X-KDE-Read=true
|
||||
X-KDE-Write=false
|
38
src/imageformats/ora.h
Normal file
38
src/imageformats/ora.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* This file is part of the KDE project
|
||||
Copyright (c) 2013 Boudewijn Rempt <boud@valdyas.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the Lesser GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef KIMG_ORA_H
|
||||
#define KIMG_ORA_H
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
|
||||
class OraHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
OraHandler();
|
||||
|
||||
bool canRead() const Q_DECL_OVERRIDE;
|
||||
bool read(QImage *image) Q_DECL_OVERRIDE;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
};
|
||||
|
||||
|
||||
class OraPlugin : public QImageIOPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "ora.json")
|
||||
public:
|
||||
Capabilities capabilities(QIODevice *device, const QByteArray &format) const Q_DECL_OVERRIDE;
|
||||
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
5
src/imageformats/ora.json
Normal file
5
src/imageformats/ora.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"Keys": [ "ora" ],
|
||||
"MimeTypes": [ "image/openraster", "image/openraster" ]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user