Commit 86abb9fb authored by Halla Rempt's avatar Halla Rempt
Browse files

Add qimageio plugins for kra and ora files

BUG:290528
parent 432cbe53
......@@ -6,3 +6,4 @@ add_subdirectory( generators )
add_subdirectory( paintops )
add_subdirectory( formats )
add_subdirectory( colorspaces )
add_subdirectory( kimgio )
......@@ -3,8 +3,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/krita/ui/ora ${CMAKE_SOURCE_DIR}/krita/
set(libkritaconverter_LIB_SRCS
ora_converter.cc
ora_load_context.cc
ora_save_context.cc
)
set(kritaoraimport_PART_SRCS
......
......@@ -57,6 +57,7 @@ KisImageBuilder_Result OraConverter::buildImage(const KUrl& uri)
KoStore* store = KoStore::createStore(QApplication::activeWindow(), uri, KoStore::Read, "image/openraster", KoStore::Zip);
if (!store) {
delete store;
return KisImageBuilder_RESULT_FAILURE;
}
store->disallowNameExpansion();
......
include_directories( ${CMAKE_SOURCE_DIR}/krita/ui/ora ${CMAKE_SOURCE_DIR}/krita/image/metadata)
set(kimg_kra_LIB_SRCS kra.cpp)
kde4_add_plugin(kimg_kra ${kimg_kra_LIB_SRCS})
target_link_libraries(kimg_kra kritaui)
set(kimg_ora_LIB_SRCS ora.cpp)
kde4_add_plugin(kimg_ora ${kimg_ora_LIB_SRCS})
target_link_libraries(kimg_ora kritaui)
install(TARGETS kimg_ora DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/imageformats/ )
install(TARGETS kimg_kra DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/imageformats/ )
install( FILES
ora.desktop
kra.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/qimageioplugins/ )
/* 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 <QImage>
#include <kdebug.h>
#include <kis_doc2.h>
#include <kis_image.h>
KraHandler::KraHandler()
{
}
bool KraHandler::canRead() const
{
if (canRead(device())) {
setFormat("kra");
return true;
}
return false;
}
bool KraHandler::read(QImage *image)
{
KisDoc2 doc;
bool retval = doc.load(device());
if (!retval) return false;
*image = doc.image()->projection()->convertToQImage(0);
return true;
}
bool KraHandler::write(const QImage &)
{
// TODO Stub!
return false;
}
QByteArray KraHandler::name() const
{
return "kra";
}
bool KraHandler::canRead(QIODevice *device)
{
if (!device) {
qWarning("KraHandler::canRead() called with no device");
return false;
}
return true;
}
class KraPlugin : public QImageIOPlugin
{
public:
QStringList keys() const;
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
};
QStringList KraPlugin::keys() const
{
return QStringList() << "kra" << "KRA";
}
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;
}
Q_EXPORT_STATIC_PLUGIN(KraPlugin)
Q_EXPORT_PLUGIN2(Kra, KraPlugin)
[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
/* 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;
bool read(QImage *image);
bool write(const QImage &image);
QByteArray name() const;
static bool canRead(QIODevice *device);
};
#endif
/* 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 <KoStore.h>
#include <kis_image.h>
#include <kis_doc2.h>
#include <kis_group_layer.h>
#include <kis_image.h>
#include <kis_open_raster_stack_load_visitor.h>
#include "ora_load_context.h"
#include <kis_paint_layer.h>
#include <kdebug.h>
OraHandler::OraHandler()
{
}
bool OraHandler::canRead() const
{
if (canRead(device())) {
setFormat("ora");
return true;
}
return false;
}
bool OraHandler::read(QImage *image)
{
KoStore *store = KoStore::createStore(device(), KoStore::Read, "image/openraster", KoStore::Zip);
if (!store || store->bad()) {
delete store;
return false;
}
store->disallowNameExpansion();
KisDoc2 doc;
OraLoadContext olc(store);
KisOpenRasterStackLoadVisitor orslv(&doc, &olc);
orslv.loadImage();
KisImageWSP img = orslv.image();
img->initialRefreshGraph();
*image = img->projection()->convertToQImage(0);
delete store;
return true;
}
bool OraHandler::write(const QImage &)
{
// TODO Stub!
return false;
}
QByteArray OraHandler::name() const
{
return "ora";
}
bool OraHandler::canRead(QIODevice *device)
{
if (!device) {
qWarning("OraHandler::canRead() called with no device");
return false;
}
return true;
}
class OraPlugin : public QImageIOPlugin
{
public:
QStringList keys() const;
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
};
QStringList OraPlugin::keys() const
{
return QStringList() << "ora" << "ORA";
}
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;
}
Q_EXPORT_STATIC_PLUGIN(OraPlugin)
Q_EXPORT_PLUGIN2(Ora, OraPlugin)
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=QImageIOPlugins
X-KDE-ImageFormat=ora
X-KDE-MimeType=image/openraster
X-KDE-Read=true
X-KDE-Write=true
/* 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;
bool read(QImage *image);
bool write(const QImage &image);
QByteArray name() const;
static bool canRead(QIODevice *device);
};
#endif
......@@ -144,6 +144,8 @@ set(kritaui_LIB_SRCS
opengl/kis_texture_tile.cpp
ora/kis_open_raster_stack_load_visitor.cpp
ora/kis_open_raster_stack_save_visitor.cpp
ora/ora_load_context.cc
ora/ora_save_context.cc
recorder/kis_node_query_path_editor.cc
recorder/kis_recorded_action_creator.cc
recorder/kis_recorded_action_creator_factory.cc
......
......@@ -69,6 +69,7 @@
#include <KoShape.h>
#include <KoToolManager.h>
#include <KoPart.h>
#include <KoStore.h>
// Krita Image
#include <kis_config.h>
......@@ -182,6 +183,36 @@ KisDoc2::~KisDoc2()
delete m_d;
}
bool KisDoc2::load(QIODevice *dev)
{
prepareForImport();
KoStore *store = KoStore::createStore(dev, KoStore::Read);
if (store->bad()) {
delete store;
return false;
}
KoXmlDocument doc = KoXmlDocument(true);
if (!oldLoadAndParse(store, "root", doc)) {
delete store;
return false;
}
if (!loadXML(doc, store)) {
delete store;
return false;
}
if (!completeLoading(store)) {
delete store;
return false;
}
delete store;
return true;
}
QByteArray KisDoc2::mimeType() const
{
return KIS_MIME_TYPE;
......
......@@ -76,6 +76,9 @@ public:
virtual ~KisDoc2();
public:
bool load(QIODevice *dev);
virtual bool completeLoading(KoStore *store);
virtual bool completeSaving(KoStore*);
virtual int supportedSpecialFormats() const;
......
......@@ -19,10 +19,11 @@
#define _ORA_LOAD_CONTEXT_H_
#include <kis_open_raster_load_context.h>
#include <krita_export.h>
class KoStore;
class OraLoadContext : public KisOpenRasterLoadContext
class KRITAUI_EXPORT OraLoadContext : public KisOpenRasterLoadContext
{
public:
OraLoadContext(KoStore* _store);
......
......@@ -22,8 +22,9 @@ class KoStore;
#include <kis_meta_data_entry.h>
#include "kis_open_raster_save_context.h"
#include <krita_export.h>
class OraSaveContext : public KisOpenRasterSaveContext
class KRITAUI_EXPORT OraSaveContext : public KisOpenRasterSaveContext
{
public:
OraSaveContext(KoStore* _store);
......
......@@ -768,13 +768,13 @@ private slots:
/// Called by the undo stack when undo or redo is called
void slotUndoStackIndexChanged(int idx);
protected:
bool oldLoadAndParse(KoStore *store, const QString& filename, KoXmlDocument& doc);
private:
bool saveToStream(QIODevice *dev);
QString checkImageMimeTypes(const QString &mimeType, const KUrl& url) const;
bool oldLoadAndParse(KoStore *store, const QString& filename, KoXmlDocument& doc);
bool loadNativeFormatFromStore(const QString& file);
bool loadNativeFormatFromStoreInternal(KoStore *store);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment