Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a4cef6af authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add saving and loading of GIF files

This re-uses Shawn Rutledge's gif qimageio plugin
(https://github.com/ec1oud/qt-gif-plugin) and adds an optional dependency
on giflib.

In the future, we could extend this to save layers as frames
and stuff like that, but for now, it simply saves the projection.

BUG:390614
parent 67db51b6
......@@ -208,3 +208,5 @@ endif (MSVC OR MINGW)
if (NOT APPLE)
add_subdirectory( ext_gmic )
endif (NOT APPLE)
add_subdirectory(ext_giflib)
SET(PREFIX_ext_giflib "${EXTPREFIX}" )
if (MINGW OR MSVC)
ExternalProject_Add(
ext_giflib
DOWNLOAD_DIR ${EXTERNALS_DOWNLOAD_DIR}
URL http://files.kde.org/krita/build/dependencies/giflib-5.0.5.tar.gz
URL_MD5 7c1c9434ce892d57a78c63cf15bbfbcc
ATCH_COMMAND ${PATCH_COMMAND} -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/giflib-5.0.5-20130916.diff
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${PREFIX_ext_giflib} -DCMAKE_BUILD_TYPE=${GLOBAL_BUILD_TYPE} ${GLOBAL_PROFILE}
UPDATE_COMMAND ""
)
else()
ExternalProject_Add(
ext_giflib
DOWNLOAD_DIR ${EXTERNALS_DOWNLOAD_DIR}
URL http://files.kde.org/krita/build/dependencies/giflib-5.0.5.tar.gz
URL_MD5 7c1c9434ce892d57a78c63cf15bbfbcc
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${PREFIX_ext_giflib} ${GLOBAL_AUTOMAKE_PROFILE}
BUILD_COMMAND make
INSTALL_COMMAND make install
UPDATE_COMMAND ""
)
endif()
This diff is collapsed.
......@@ -515,6 +515,13 @@ set_package_properties(JPEG PROPERTIES
TYPE OPTIONAL
PURPOSE "Required by the Krita JPEG filter")
find_package(GIF)
set_package_properties(GIF PROPERTIES
DESCRIPTION "Library for loading and saving gif files."
URL "http://giflib.sourceforge.net/"
TYPE OPTIONAL
PURPOSE "Required by the Krita GIF filter")
set(LIBRAW_MIN_VERSION "0.16")
find_package(LibRaw ${LIBRAW_MIN_VERSION})
set_package_properties(LibRaw PROPERTIES
......
......@@ -32,7 +32,6 @@ if(LIBRAW_FOUND)
endif()
add_subdirectory(svg)
add_subdirectory(qimageio)
add_subdirectory(ora)
add_subdirectory(ppm)
......@@ -45,3 +44,7 @@ add_subdirectory(brush)
add_subdirectory(spriter)
add_subdirectory(video)
add_subdirectory(kra)
if (GIF_FOUND)
add_subdirectory(gif)
endif()
set(kritagifexport_SOURCES
kis_gif_export.cpp
qgiflibhandler.cpp
)
ki18n_wrap_ui(kritagifexport_SOURCES )
add_library(kritagifexport MODULE ${kritagifexport_SOURCES})
target_link_libraries(kritagifexport kritaui kritaimpex gif)
install(TARGETS kritagifexport DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
set(kritagifimport_SOURCES
kis_gif_import.cpp
qgiflibhandler.cpp
)
ki18n_wrap_ui(kritagifimport_SOURCES )
add_library(kritagifimport MODULE ${kritagifimport_SOURCES})
target_link_libraries(kritagifimport kritaui gif)
install(TARGETS kritagifimport DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
install( PROGRAMS krita_gif.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
/*
* Copyright (c) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 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 program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kis_gif_export.h"
#include <QCheckBox>
#include <QSlider>
#include <kpluginfactory.h>
#include <QFileInfo>
#include <QApplication>
#include <KoColorModelStandardIds.h>
#include <KisExportCheckRegistry.h>
#include <KisImportExportManager.h>
#include <kis_paint_device.h>
#include <KisDocument.h>
#include <kis_image.h>
#include <kis_paint_layer.h>
#include "qgiflibhandler.h"
K_PLUGIN_FACTORY_WITH_JSON(KisGIFExportFactory, "krita_gif_export.json", registerPlugin<KisGIFExport>();)
KisGIFExport::KisGIFExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisGIFExport::~KisGIFExport()
{
}
KisImportExportFilter::ConversionStatus KisGIFExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
qDebug() << "GIF export";
Q_UNUSED(configuration);
QRect rc = document->savingImage()->bounds();
QImage image = document->savingImage()->projection()->convertToQImage(0, 0, 0, rc.width(), rc.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
QGIFLibHandler handler;
handler.setDevice(io);
bool result = handler.write(image);
qDebug() << ">>>>>>>>>>>>>" << result;
return (result ? KisImportExportFilter::OK : KisImportExportFilter::InternalError);
}
void KisGIFExport::initializeCapabilities()
{
QList<QPair<KoID, KoID> > supportedColorModels;
supportedColorModels << QPair<KoID, KoID>()
<< QPair<KoID, KoID>(RGBAColorModelID, Integer8BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "GIF");
}
#include "kis_gif_export.moc"
/*
* Copyright (c) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 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 program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_GIF_EXPORT_H_
#define _KIS_GIF_EXPORT_H_
#include <QVariant>
#include <KisImportExportFilter.h>
class KisGIFExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisGIFExport(QObject *parent, const QVariantList &);
~KisGIFExport() override;
public:
KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
void initializeCapabilities() override;
};
#endif
/*
* Copyright (c) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 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 program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kis_gif_import.h"
#include <QCheckBox>
#include <QBuffer>
#include <QSlider>
#include <QApplication>
#include <kpluginfactory.h>
#include <QFileInfo>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <kis_transaction.h>
#include <kis_paint_device.h>
#include <kis_image.h>
#include <kis_paint_layer.h>
#include <kis_node.h>
#include <kis_group_layer.h>
#include <KisDocument.h>
#include "qgiflibhandler.h"
K_PLUGIN_FACTORY_WITH_JSON(KisGIFImportFactory, "krita_gif_import.json", registerPlugin<KisGIFImport>();)
KisGIFImport::KisGIFImport(QObject *parent, const QVariantList &)
: KisImportExportFilter(parent)
{
}
KisGIFImport::~KisGIFImport()
{
}
KisImportExportFilter::ConversionStatus KisGIFImport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
Q_UNUSED(configuration);
QImage img;
bool result = false;
QGIFLibHandler handler;
handler.setDevice(io);
if (handler.canRead()) {
result = handler.read(&img);
}
if (result == false) {
return KisImportExportFilter::CreationError;
}
const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP image = new KisImage(document->createUndoStore(), img.width(), img.height(), colorSpace, "imported from gif");
KisPaintLayerSP layer = new KisPaintLayer(image, image->nextLayerName(), 255);
layer->paintDevice()->convertFromQImage(img, 0, 0, 0);
image->addNode(layer.data(), image->rootLayer().data());
document->setCurrentImage(image);
return KisImportExportFilter::OK;
}
#include "kis_gif_import.moc"
/*
* Copyright (c) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 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 program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_GIF_IMPORT_H_
#define _KIS_GIF_IMPORT_H_
#include <QVariant>
#include <KisImportExportFilter.h>
class KisGIFImport : public KisImportExportFilter
{
Q_OBJECT
public:
KisGIFImport(QObject *parent, const QVariantList &);
~KisGIFImport() override;
public:
KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
};
#endif
[Desktop Entry]
Name=Krita
Name[af]=Krita
Name[ar]=كريتا
Name[bg]=Krita
Name[br]=Krita
Name[bs]=Krita
Name[ca]=Krita
Name[ca@valencia]=Krita
Name[cs]=Krita
Name[cy]=Krita
Name[da]=Krita
Name[de]=Krita
Name[el]=Krita
Name[en_GB]=Krita
Name[eo]=Krita
Name[es]=Krita
Name[et]=Krita
Name[eu]=Krita
Name[fi]=Krita
Name[fr]=Krita
Name[fy]=Krita
Name[ga]=Krita
Name[gl]=Krita
Name[he]=Krita
Name[hi]=केरिता
Name[hne]=केरिता
Name[hr]=Krita
Name[hu]=Krita
Name[ia]=Krita
Name[is]=Krita
Name[it]=Krita
Name[ja]=Krita
Name[kk]=Krita
Name[ko]=Krita
Name[lt]=Krita
Name[lv]=Krita
Name[mr]=क्रिटा
Name[ms]=Krita
Name[nb]=Krita
Name[nds]=Krita
Name[ne]=क्रिता
Name[nl]=Krita
Name[pl]=Krita
Name[pt]=Krita
Name[pt_BR]=Krita
Name[ro]=Krita
Name[ru]=Krita
Name[se]=Krita
Name[sk]=Krita
Name[sl]=Krita
Name[sv]=Krita
Name[ta]=கிரிட்டா
Name[tg]=Krita
Name[tr]=Krita
Name[ug]=Krita
Name[uk]=Krita
Name[uz]=Krita
Name[uz@cyrillic]=Krita
Name[wa]=Krita
Name[xh]=Krita
Name[x-test]=xxKritaxx
Name[zh_CN]=Krita
Name[zh_TW]=Krita
Exec=krita %u
MimeType=image/gif;
Type=Application
Icon=calligrakrita
Categories=Qt;KDE;Office;Graphics;
StartupNotify=true
NoDisplay=true
{
"Id": "Krita GIF Export Filter",
"NoDisplay": "true",
"Type": "Service",
"X-KDE-Export": "image/gif",
"X-KDE-Library": "kritagifexport",
"X-KDE-ServiceTypes": [
"Krita/FileFilter"
],
"X-KDE-Weight": "1",
"X-KDE-Extensions" : "gif"
}
{
"Id": "Krita GIF Import Filter",
"NoDisplay": "true",
"Type": "Service",
"X-KDE-Import": "image/gif",
"X-KDE-Library": "kritagifimport",
"X-KDE-ServiceTypes": [
"Krita/FileFilter"
],
"X-KDE-Weight": "1",
"X-KDE-Extensions" : "gif"
}
This diff is collapsed.
/*
* Copyright (C) 2009 Shawn T. Rutledge (shawn.t.rutledge@gmail.com)
* Copyright (c) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 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 program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*
*/
#ifndef QGIFLIBHANDLER_H
#define QGIFLIBHANDLER_H
#include <QImageIOHandler>
#include <QImage>
#include <QVariant>
class QGIFLibHandler : public QImageIOHandler
{
public:
QGIFLibHandler();
bool canRead () const;
bool read ( QImage * image );
bool write ( const QImage & image );
static bool canRead(QIODevice *device);
bool supportsOption ( ImageOption option ) const;
void setOption ( ImageOption option, const QVariant & value );
QVariant option( ImageOption option ) const;
private:
QString m_description;
};
#endif // QGIFLIBHANDLER_H
Markdown is supported
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