Commit 807c4819 authored by Lukáš Tvrdý's avatar Lukáš Tvrdý

Commit initial work on GMIC extension

o Be able to run GMIC command and filter Krita pixels with it
  CurrentColorSpace() converted to Float->filtered with gmic->convert back
o Basics of gmic_def.gmic parser: parse all params of poster edges, easily extensible parser
parent e9675e8f
......@@ -13,6 +13,7 @@ add_subdirectory( separate_channels )
add_subdirectory( shearimage )
add_subdirectory( dockers )
add_subdirectory( layergroupswitcher )
add_subdirectory( gmic )
find_package(OpenShiva)
find_package(QtShiva )
......
This diff is collapsed.
set(kritagmic_PART_SRCS kis_gmic.cpp dlg_gmic.cpp kis_gmic_plugin.cpp gmic.cpp)
set(gmicparser_PART_SRCS kis_gmic_parser.cpp Parameter.cpp)
kde4_add_ui_files(kritagmic_PART_SRCS wdg_gmic.ui )
kde4_add_plugin(kritagmic ${kritagmic_PART_SRCS})
add_definitions(-Dgmic_build )
add_definitions(-Dcimg_use_vt100 )
add_definitions(-Dcimg_use_fftw3 )
add_definitions(-Dcimg_display=0 )
add_definitions(-Dgmic_float_only )
add_definitions(-fexceptions )
target_link_libraries(kritagmic kritaui ${FFTW3_LIBRARIES})
kde4_add_executable(gmicparser ${gmicparser_PART_SRCS})
target_link_libraries(gmicparser ${QT_QTCORE_LIBRARY})
install(TARGETS kritagmic DESTINATION ${PLUGIN_INSTALL_DIR})
install(TARGETS gmicparser ${INSTALL_TARGETS_DEFAULT_ARGS})
########### install files ###############
install( FILES gmic.rc DESTINATION ${DATA_INSTALL_DIR}/kritaplugins)
install( FILES kritagmic.desktop DESTINATION ${SERVICES_INSTALL_DIR})
/*
* Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
*
* 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 <Parameter.h>
#include <QString>
#include <QStringList>
#include <QDebug>
Parameter::Parameter(const QString& name, bool updatePreview)
:m_name(name),
m_type(INVALID_P),
m_updatePreview(updatePreview)
{
}
QString Parameter::toString()
{
return "INVALID";
}
void Parameter::parseValues(const QString& typeDefinition)
{
Q_UNUSED(typeDefinition);
}
QStringList Parameter::getValues(const QString& typeDefinition)
{
QString currentType = PARAMETER_NAMES[m_type];
Q_ASSERT(typeDefinition.startsWith(currentType));
qDebug() << currentType << currentType.size();
// get rid of '(', '{' and '['
QString onlyValues = typeDefinition;
onlyValues = onlyValues.remove(0, currentType.size() + 1);
onlyValues.chop(1);
QStringList result = onlyValues.split(",");
return result;
}
FloatParameter::FloatParameter(const QString& name, bool updatePreview): Parameter(name,updatePreview)
{
m_type = FLOAT_P;
}
// e.g. float(0,0,5) or float[0,0,5] or float{0,0,5}
void FloatParameter::parseValues(const QString& typeDefinition)
{
QStringList values = getValues(typeDefinition);
bool isOk = true;
qDebug() << values;
m_defaultValue = values.at(0).toFloat(&isOk);
Q_ASSERT(isOk);
m_minValue = values.at(1).toFloat(&isOk);
Q_ASSERT(isOk);
m_maxValue = values.at(2).toFloat(&isOk);
Q_ASSERT(isOk);
}
QString FloatParameter::toString()
{
QString result;
result.append(m_name+";");
result.append(PARAMETER_NAMES[m_type]+";");
result.append(QString::number(m_defaultValue)+";");
result.append(QString::number(m_minValue)+";");
result.append(QString::number(m_maxValue)+";");
return result;
}
IntParameter::IntParameter(const QString& name, bool updatePreview): Parameter(name, updatePreview)
{
m_type = INT_P;
}
void IntParameter::parseValues(const QString& typeDefinition)
{
QStringList values = getValues(typeDefinition);
bool isOk = true;
qDebug() << values;
m_defaultValue = values.at(0).toInt(&isOk);
Q_ASSERT(isOk);
m_minValue = values.at(1).toInt(&isOk);
Q_ASSERT(isOk);
m_maxValue = values.at(2).toInt(&isOk);
Q_ASSERT(isOk);
}
QString IntParameter::toString()
{
QString result;
result.append(m_name+";");
result.append(PARAMETER_NAMES[m_type]+";");
result.append(QString::number(m_defaultValue)+";");
result.append(QString::number(m_minValue)+";");
result.append(QString::number(m_maxValue)+";");
return result;
}
SeparatorParameter::SeparatorParameter(const QString& name, bool updatePreview): Parameter(name, updatePreview)
{
m_type = SEPARATOR_P;
}
void SeparatorParameter::parseValues(const QString& typeDefinition)
{
Q_UNUSED(typeDefinition);
}
QString SeparatorParameter::toString()
{
QString result;
result.append(m_name+";");
return result;
}
ChoiceParameter::ChoiceParameter(const QString& name, bool updatePreview): Parameter(name, updatePreview)
{
m_type = CHOICE_P;
}
void ChoiceParameter::parseValues(const QString& typeDefinition)
{
m_choices = getValues(typeDefinition);
}
QString ChoiceParameter::toString()
{
QString result;
result.append(m_name+";");
foreach (QString choice, m_choices)
{
result.append(choice+";");
}
return result;
}
QString ChoiceParameter::defaultChoice() const
{
return m_choices.at(0);
}
NoteParameter::NoteParameter(const QString& name, bool updatePreview): Parameter(name, updatePreview)
{
m_type = NOTE_P;
}
void NoteParameter::parseValues(const QString& typeDefinition)
{
QStringList values = getValues(typeDefinition);
m_label = values.at(0);
}
QString NoteParameter::toString()
{
QString result;
result.append(m_name+";");
result.append(m_label+";");
return result;
}
/*
* Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
*
* 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 PARAMETER_H__
#define PARAMETER_H__
#include <QMap>
#include <QString>
#include <QStringList>
class Parameter
{
public:
enum ParameterType {
INVALID_P,
FLOAT_P,
INT_P,
BOOL_P,
CHOICE_P,
TEXT_P,
FILE_P,
FOLDER_P,
COLOR_P,
NOTE_P,
LINK_P,
SEPARATOR_P
};
Parameter(const QString &name, bool updatePreview = true);
virtual ~Parameter(){}
QString m_name;
ParameterType m_type;
bool m_updatePreview;
virtual QString toString();
virtual void parseValues(const QString& typeDefinition);
protected:
QStringList getValues(const QString& typeDefinition);
};
static QMap<Parameter::ParameterType, QString> initMap()
{
QMap<Parameter::ParameterType, QString> map;
map.insert(Parameter::FLOAT_P,"float");
map.insert(Parameter::INT_P, "int");
map.insert(Parameter::BOOL_P, "bool");
map.insert(Parameter::CHOICE_P, "choice");
map.insert(Parameter::TEXT_P, "text");
map.insert(Parameter::FILE_P, "file");
map.insert(Parameter::FOLDER_P, "folder");
map.insert(Parameter::COLOR_P, "color");
map.insert(Parameter::NOTE_P, "note");
map.insert(Parameter::LINK_P, "link");
map.insert(Parameter::SEPARATOR_P, "separator");
return map;
}
static const QMap<Parameter::ParameterType, QString> PARAMETER_NAMES = initMap();
static const QList<QString> PARAMETER_NAMES_STRINGS = PARAMETER_NAMES.values();
class FloatParameter : public Parameter
{
public:
FloatParameter(const QString& name, bool updatePreview = true);
float m_defaultValue;
float m_minValue;
float m_maxValue;
virtual void parseValues(const QString& typeDefinition);
virtual QString toString();
};
class IntParameter : public Parameter
{
public:
IntParameter(const QString& name, bool updatePreview = true);
int m_defaultValue;
int m_minValue;
int m_maxValue;
virtual void parseValues(const QString& typeDefinition);
virtual QString toString();
};
class SeparatorParameter : public Parameter
{
public:
SeparatorParameter(const QString& name, bool updatePreview = true);
virtual void parseValues(const QString& typeDefinition);
virtual QString toString();
};
class ChoiceParameter : public Parameter
{
public:
ChoiceParameter(const QString& name, bool updatePreview = true);
virtual void parseValues(const QString& typeDefinition);
virtual QString toString();
QStringList m_choices;
QString defaultChoice() const;
};
class NoteParameter : public Parameter
{
public:
NoteParameter(const QString& name, bool updatePreview = true);
virtual void parseValues(const QString& typeDefinition);
virtual QString toString();
QString m_label;
};
#endif
/*
* dlg_gmic.cc - part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2012 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 "dlg_gmic.h"
#include <QRadioButton>
#include <QCheckBox>
#include <QLabel>
#include <QComboBox>
#include <QColor>
#include <kconfig.h>
#include <klocale.h>
#include <knuminput.h>
#include <kis_debug.h>
#include <kcolorbutton.h>
DlgGmic::DlgGmic(const QString & /*imageCS*/,
const QString & /*layerCS*/,
QWidget * parent,
const char * name)
: KDialog(parent)
{
setCaption(i18n("Apply G'Mic Action"));
setButtons(Ok | Cancel);
setDefaultButton(Ok);
setObjectName(name);
m_page = new WdgGmic(this, "gmic");
Q_CHECK_PTR(m_page);
setMainWidget(m_page);
resize(m_page->sizeHint());
connect(this, SIGNAL(okClicked()),
this, SLOT(okClicked()));
}
DlgGmic::~DlgGmic()
{
delete m_page;
}
QString DlgGmic::gmicScript()
{
return m_page->txtGmic->text();
}
void DlgGmic::okClicked()
{
accept();
}
#include "dlg_gmic.moc"
/*
* dlg_gmic.h -- part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2012 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 DLG_GMIC
#define DLG_GMIC
#include <kdialog.h>
#include "kis_gmic.h"
#include "ui_wdg_gmic.h"
class QColor;
class WdgGmic : public QWidget, public Ui::WdgGmic
{
Q_OBJECT
public:
WdgGmic(QWidget *parent, const char *name) : QWidget(parent) {
setObjectName(name); setupUi(this);
}
};
class DlgGmic: public KDialog
{
Q_OBJECT
public:
DlgGmic(const QString & imageCS, const QString & layerCS, QWidget * parent = 0,
const char* name = 0);
~DlgGmic();
QString gmicScript();
private slots:
void okClicked();
private:
WdgGmic * m_page;
};
#endif // DLG_GMIC
This diff is collapsed.
/*
#
# File : gmic.h
# ( C++ header file )
#
# Description : GREYC's Magic for Image Computing
# ( http://gmic.sourceforge.net )
# This file is also a part of the CImg Library project.
# ( http://cimg.sourceforge.net )
#
# Note : Include this file in your C++ source code, if you
# want to use the G'MIC interpreter in your own program.
#
# Copyright : David Tschumperle
# ( http://tschumperle.users.greyc.fr/ )
#
# License : CeCILL v2.0
# ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
#
# This software is governed by the CeCILL license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/ or redistribute the software under the terms of the CeCILL
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
#
*/
#include <locale>
#ifndef gmic_version
#define gmic_version 1551
// Define environment variables.
#ifndef gmic_split_compilation
#define gmic_float
#endif // #ifndef gmic_split_compilation
#ifndef gmic_is_beta
#define gmic_is_beta 0
#endif // #ifndef gmic_is_beta
#ifndef cimg_verbosity
#define cimg_verbosity 1
#endif // #ifndef cimg_verbosity
#if defined(cimg_build)
#define cimg_plugin "examples/gmic.cpp"
#define cimg_include_file "../CImg.h"
#elif defined(gmic_build) // #if defined(cimg_build)
#define cimg_plugin "gmic.cpp"
#define cimg_include_file "./CImg.h"
#endif // #if defined(cimg_build)
#ifdef cimg_include_file
#include cimg_include_file
#if cimg_OS==2
#include <process.h>
#elif cimg_OS==1
#include <cerrno>
#endif // #if cimg_OS==2
// Define some special character codes used for replacement in double quoted strings.
const char _dollar = 23, _lbrace = 24, _rbrace = 25, _comma = 26, _dquote = 28, _arobace = 29,
_newline = 30;
// Replace special characters in a string.
inline char *gmic_strreplace(char *const str) {
for (char *s = str ; *s; ++s) {
const char c = *s;
if (c<' ')
*s = c==_dollar?'$':c==_lbrace?'{':c==_rbrace?'}':c==_comma?',':
c==_dquote?'\"':c==_arobace?'@':c;
}
return str;
}
#else // #ifdef cimg_include_file
#include <cstdio>
#include <cstring>
#ifndef cimg_version
namespace cimg_library {
// Define the G'MIC image structure.
//----------------------------------
template<typename T> struct CImg {
unsigned int _width; // Number of image columns (dimension along the X-axis).
unsigned int _height; // Number of image lines (dimension along the Y-axis)
unsigned int _depth; // Number of image slices (dimension along the Z-axis).
unsigned int _spectrum; // Number of image channels (dimension along the C-axis).
bool _is_shared; // Tells if the data buffer is shared by another structure.
T *_data; // Pointer to the first pixel value.
// Destructor.
~CImg();