Commit c2a43637 authored by Emanuele Tamponi's avatar Emanuele Tamponi

The Mixer is back! The paintop too but it doesn't work still.

Going to remove painterlyframework.old directory.
Compare objects, not addresses, in KoColor
Please accept that I comment that code in krita/image and krita/ui
because it's the only way I can avoid the use of a KisImage in the
Mixer, and those checks don't seem to be needed anyway.

svn path=/trunk/koffice/; revision=784544
parent d6c0c00c
......@@ -51,10 +51,11 @@ KisComplexColor::KisComplexColor(const KoColorSpace *colorSpace)
: KisPaintDevice(colorSpace)
{
m_scaling = DEFAULT_SCALE;
m_defaultColor = KoColor(colorSpace);
m_copy = colorSpace->clone();
m_defaultColor = KoColor(m_copy);
m_defaultProperty = 0;
KoColor kc(Qt::black, colorSpace);
KoColor kc(Qt::black, m_copy);
fromKoColor(kc);
}
......@@ -62,9 +63,10 @@ KisComplexColor::KisComplexColor(const KoColorSpace *colorSpace, const KoColor &
: KisPaintDevice(colorSpace)
{
m_scaling = DEFAULT_SCALE;
m_defaultColor = KoColor(colorSpace);
m_copy = colorSpace->clone();
m_defaultColor = KoColor(m_copy);
m_defaultProperty = 0;
fromKoColor(kc);
}
......@@ -72,12 +74,14 @@ KisComplexColor::~KisComplexColor()
{
if (m_defaultProperty)
delete [] m_defaultProperty;
delete m_copy;
}
void KisComplexColor::fromKoColor(const KoColor &kc)
{
if (painterlyOverlay())
removePainterlyOverlay();
createPainterlyOverlay();
clear();
......@@ -126,8 +130,12 @@ KoColor KisComplexColor::simpleColor()
KoColor KisComplexColor::defaultColor()
{
if (!m_defaultColor.colorSpace() || !(*m_defaultColor.colorSpace() == *colorSpace()))
m_defaultColor.convertTo(colorSpace());
if (!m_defaultColor.colorSpace() || !(*m_defaultColor.colorSpace() == *colorSpace())) {
KoColorSpace *oldcopy = m_copy;
m_copy = colorSpace()->clone();
m_defaultColor.convertTo(m_copy);
delete oldcopy;
}
return m_defaultColor;
}
......@@ -138,8 +146,9 @@ quint8 * KisComplexColor::defaultProperty()
void KisComplexColor::setDefaultColor(const KoColor &kc)
{
m_defaultColor = defaultColor();
m_defaultColor = kc;
m_defaultColor.convertTo(colorSpace());
m_defaultColor.convertTo(m_copy);
}
void KisComplexColor::setDefaultProperty(const PropertyCell &pc)
......@@ -173,7 +182,6 @@ void KisComplexColor::setSize(const QSize &rc)
more.setX( ( newleft - oldleft ) );
more.setY( ( newtop - oldtop ) );
// m_center -= more;
m_offset += more;
translate();
......
......@@ -97,6 +97,7 @@ private:
QPoint m_offset;
QSize m_size;
KoColorSpace *m_copy;
KoColor m_defaultColor;
quint8 *m_defaultProperty;
......
......@@ -207,8 +207,10 @@ KisSelectionSP KisLayer::selection() const
KisSelectionMaskSP selMask = selectionMask();
if (selMask && selMask->active())
return selMask->selection();
else
else if (m_d->image)
return m_d->image->globalSelection();
else
return 0;
}
bool KisLayer::hasEffectMasks() const
......
......@@ -82,7 +82,7 @@ KisPaintLayer::KisPaintLayer(KisImageSP img, const QString& name, quint8 opacity
: KisLayer(img, name, opacity)
, m_d( new Private() )
{
Q_ASSERT(img);
// Q_ASSERT(img);
if ( colorSpace == 0 )
colorSpace = img->colorSpace();
Q_ASSERT( colorSpace );
......
......@@ -63,17 +63,16 @@ KisPainterlyMixer::KisPainterlyMixer(QWidget *parent, KisView2 *view)
setupUi(this);
QStringList illuminants;
illuminants += KGlobal::mainComponent().dirs()->findAllResources("kis_profiles", "IlluminantD50.ill");
illuminants += KGlobal::mainComponent().dirs()->findAllResources("kis_profiles", "D65_5_18.ill");
// TODO The Illuminant has to be choosen in runtime
// TODO The Illuminant has to be choosen at runtime
m_illuminant = new KisIlluminantProfile(illuminants[0]);
m_colorspace = new KisKSColorSpace(m_illuminant);
// m_colorspace = new KisRGBKSColorSpace;
m_colorspace = new KisKSColorSpace<5>(m_illuminant);
initCanvas();
initTool();
initSpots();
m_bErase->setIcon(KIcon("edit-delete"));n
m_bErase->setIcon(KIcon("edit-delete"));
connect(m_bErase, SIGNAL(clicked()), m_canvas, SLOT(slotClear()));
}
......
......@@ -25,32 +25,6 @@ extern "C" {
#include <glpk.h>
}namespace maths {
const double MATH_THICKNESS = 1.0;
const double MATH_LIM_SUP = 1.0 - 3.90625e-3;
const double MATH_LIM_SUB = 0.0 + 3.90625e-3;
const double MATH_NORMALIZATION = 65535.0;
double MATH_SUB_BLACK(double) { return 3.90625e-5; }
// double MATH_SUB_BLACK(double R) { return 0.001*R; }
void correctReflectance(double &R)
{
if (R > MATH_LIM_SUP)
R = MATH_LIM_SUP;
if (R < MATH_LIM_SUB)
R = MATH_LIM_SUB;
}
void normalizeReflectance(int num, double *R)
{
double max = 1.0;
for (int i = 0; i < num; i++)
if (R[i] > max)
max = R[i];
for (int i = 0; i < num; i++)
R[i] = R[i] / max;
}
double coth(double z)
{
return 1.0 / tanh(z);
......@@ -61,16 +35,6 @@ double acoth(double z)
return 0.5*log((1.0 + 1.0/z) / (1.0 - 1.0/z));
}
void mult(const int rows, const int cols, double **M, const double *A, double *R)
{
for (int i = 0; i < rows; i++) {
R[i] = 0;
for (int j = 0; j < cols; j++) {
R[i] += M[i][j] * A[j];
}
}
}
double sigmoid(double v)
{
return smoothstep(-0.05, 1.0, v);
......@@ -130,125 +94,4 @@ int sign(double v)
return -1;
}
void computeKS(const int nrefs, const double *vREF, float *vKS)
{
double R, Rb, a, b, K, S;
for (int i = 0, j = 0; j < nrefs; i += 2, j += 1) {
R = vREF[j];
correctReflectance(R);
Rb = R - MATH_SUB_BLACK(R);
a = 0.5 * ( R + ( Rb - R + 1.0) / Rb );
b = sqrt( a*a - 1.0 );
S = (1.0 / b) * acoth( ( b*b - ( a - R ) * ( a - 1.0 ) ) / ( b * ( 1.0 - R ) ) );
K = S * ( a - 1.0 );
vKS[i+0] = K;
vKS[i+1] = log(S);
}
}
// Do not use this anymore
void computeReflectance(const int nrefs, const float *vKS, double *vREF)
{
double a, b, K, S, R;
for (int i = 0, j = 0; j < nrefs; i += 2, j += 1) {
K = vKS[i+0];
S = exp(vKS[i+1]);
a = (S + K) / S;
b = sqrt( a*a - 1 );
R = 1.0 / ( a + b * coth( b * S * MATH_THICKNESS ) );
// correctReflectance(R);
vREF[j] = R;
}
normalizeReflectance(nrefs, vREF);
}
/*
void computeReflectance(const int nrefs, const float *vKS, double *vREF)
{
double K, S, q, R;
for (int i = 0, j = 0; j < nrefs; i += 2, j += 1) {
K = vKS[i+0];
S = vKS[i+1];
q = K / S;
R = 1.0 + q - sqrt( q*q + 2.0*q );
correctReflectance(R);
vREF[j] = R;
}
}
*/
void simplex(const int rows, const int cols, double **M, double *X, const double *B)
{
char name[4];
glp_prob *lp;
glp_smcp parm;
glp_init_smcp(&parm);
parm.msg_lev = GLP_MSG_OFF;
parm.meth = GLP_DUALP;
lp = glp_create_prob();
glp_set_prob_name(lp, "XYZ2REF");
glp_set_obj_dir(lp, GLP_MAX);
glp_add_rows(lp, rows);
for (int i = 0; i < rows; i++) {
sprintf(name, "B%d", i+1);
glp_set_row_name(lp, i+1, name);
glp_set_row_bnds(lp, i+1, GLP_FX, B[i], B[i]);
}
glp_add_cols(lp, cols);
for (int i = 0; i < cols; i++) {
sprintf(name, "R%d", i+1);
glp_set_col_name(lp, i+1, name);
glp_set_col_bnds(lp, i+1, GLP_DB, MATH_LIM_SUB, MATH_LIM_SUP);
glp_set_obj_coef(lp, i+1, 1.0);
}
int ind[cols+1];
for (int i = 1; i <= cols; i++)
ind[i] = i;
for (int i = 0; i < rows; i++) {
double row[cols+1];
for (int j = 0; j < cols; j++) {
row[j+1] = M[i][j];
}
glp_set_mat_row(lp, i+1, cols, ind, row);
}
lpx_scale_prob(lp);
glp_simplex(lp, &parm);
for (int i = 0; i < cols; i++)
X[i] = glp_get_col_prim(lp, i+1);
glp_delete_prob(lp);
}
double convert2f (unsigned short value)
{
return ((double)value)/MATH_NORMALIZATION;
}
unsigned short convert2i (double value)
{
return (unsigned short)(value*MATH_NORMALIZATION);
}
}
......@@ -28,8 +28,6 @@ KRITAPAINTERLYCOMMON_EXPORT double coth(double z);
KRITAPAINTERLYCOMMON_EXPORT double acoth(double z);
KRITAPAINTERLYCOMMON_EXPORT void mult(const int rows, const int cols, double **M, const double *A, double *R);
KRITAPAINTERLYCOMMON_EXPORT double sigmoid(double v);
KRITAPAINTERLYCOMMON_EXPORT double smoothstep(double min, double max, double v);
......@@ -38,16 +36,6 @@ KRITAPAINTERLYCOMMON_EXPORT double clamp(double min, double max, double v);
KRITAPAINTERLYCOMMON_EXPORT int sign(double v);
KRITAPAINTERLYCOMMON_EXPORT void computeKS(const int nrefs, const double *vREF, float *vKS);
KRITAPAINTERLYCOMMON_EXPORT void computeReflectance(const int nrefs, const float *vKS, double *vREF);
KRITAPAINTERLYCOMMON_EXPORT void simplex(const int rows, const int cols, double **M, double *X, const double *B);
KRITAPAINTERLYCOMMON_EXPORT double convert2f (unsigned short value);
KRITAPAINTERLYCOMMON_EXPORT unsigned short convert2i (double value);
}
......
......@@ -42,7 +42,9 @@
#include "kis_resource_provider.h"
#include "colorspot.h"
#include "mixertool.h"MixerCanvas::MixerCanvas(QWidget *parent)
#include "mixertool.h"
MixerCanvas::MixerCanvas(QWidget *parent)
: QFrame(parent), KoCanvasBase(0), m_toolProxy(0)
{
m_dirty = false;
......
......@@ -12,3 +12,39 @@ kde4_add_plugin(kritakscolorspacesplugin ${kritakscolorspacesplugin_PART_SRCS})
target_link_libraries(kritakscolorspacesplugin pigmentcms)
install(TARGETS kritakscolorspacesplugin DESTINATION ${PLUGIN_INSTALL_DIR})
install( FILES kritakscolorspacesplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
#################################################
# Painterly Mixer
set(kritapainterlymixer_PART_SRCS
colorspot.cpp
mixercanvas.cpp
mixertool.cpp
kis_painterlymixer.cpp
kis_painterlymixerdocker.cpp
painterlymixer.cpp
kis_illuminant_profile.cpp
mathematics.cpp
)
kde4_add_ui_files(kritapainterlymixer_PART_SRCS kis_painterlymixer.ui)
kde4_add_plugin(kritapainterlymixer ${kritapainterlymixer_PART_SRCS})
target_link_libraries(kritapainterlymixer kritaui pigmentcms kritaimage)
install(TARGETS kritapainterlymixer DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kritapainterlymixer.desktop DESTINATION ${SERVICES_INSTALL_DIR})
#################################################
# Painterly Complex Paintop
set(kritacomplexbrush_PART_SRCS
complexbrush.cpp
kis_complexop.cpp
mathematics.cpp
)
kde4_add_plugin(kritacomplexbrush ${kritacomplexbrush_PART_SRCS})
target_link_libraries(kritacomplexbrush pigmentcms kritaimage)
install(TARGETS kritacomplexbrush DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kritacomplexbrush.desktop DESTINATION ${SERVICES_INSTALL_DIR})
/*
* Copyright (c) 2007 Emanuele Tamponi <emanuele@valinor.it>
*
*
* 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 "colorspot.h"
#include <QColor>
#include <QToolButton>
#include "KoColor.h"
#include "KoColorSpace.h"
ColorSpot::ColorSpot(QWidget *parent, const KoColor &color) : QToolButton(parent), m_color(color)
{
setPalette(QPalette(color.toQColor().rgba(), color.toQColor().rgba()));
setAutoFillBackground(true);
setAutoRepeat(true);
}
ColorSpot::~ColorSpot()
{
}
void ColorSpot::setColor(const KoColor &color)
{
m_color = color;
}
#include "colorspot.moc"
/*
* Copyright (c) 2007 Emanuele Tamponi <emanuele@valinor.it>
*
*
* 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 COLORSPOT_H_
#define COLORSPOT_H_
#include <QToolButton>
#include "KoColor.h"
class KoColor;
class QColor;
class ColorSpot : public QToolButton {
Q_OBJECT
public:
ColorSpot (QWidget *parent, const KoColor &color);
~ColorSpot();
void setColor(const KoColor &color);
KoColor color() const { return m_color; }
private:
KoColor m_color;
};
#endif // COLORSPOT_H_
/*
* Copyright (c) 2007 Emanuele Tamponi (emanuele@valinor.it)
*
* 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 "complexbrush.h"
#include <klocale.h>
#include <kiconloader.h>
#include <kcomponentdata.h>
#include <kstandarddirs.h>
#include <kis_debug.h>
#include <kgenericfactory.h>
#include "kis_paintop_registry.h"
#include "kis_complexop.h"
typedef KGenericFactory<ComplexBrush> ComplexBrushFactory;
K_EXPORT_COMPONENT_FACTORY(kritacomplexbrush, ComplexBrushFactory("krita"))
ComplexBrush::ComplexBrush(QObject *parent, const QStringList &)
: KParts::Plugin(parent)
{
setComponentData(ComplexBrushFactory::componentData());
KisPaintOpRegistry *r = KisPaintOpRegistry::instance();
r->add(KisPaintOpFactorySP(new KisComplexOpFactory));
}
ComplexBrush::~ComplexBrush()
{
}
#include "complexbrush.moc"
/*
* Copyright (c) 2007 Emanuele Tamponi (emanuele@valinor.it)
*
* 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 COMPLEX_BRUSH_H
#define COMPLEX_BRUSH_H
#include <kparts/plugin.h>
class ComplexBrush : public KParts::Plugin
{
Q_OBJECT
public:
ComplexBrush(QObject *parent, const QStringList &);
virtual ~ComplexBrush();
};
#endif // COMPLEX_BRUSH_H
/***************************************************************************
* Copyright (C) 2004 by Ewgenij Huebner *
* huebner@uni-trier.de *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include "gsl_cqp.h"
gsl_cqpminimizer *
gsl_cqpminimizer_alloc (const gsl_cqpminimizer_type * T, const size_t n, const size_t me, const size_t mi)
{
int status;
gsl_cqpminimizer *minimizer = (gsl_cqpminimizer *) malloc (sizeof (gsl_cqpminimizer));
if (minimizer == 0)
{
GSL_ERROR_VAL ("failed to allocate space for cqpminimizer", GSL_ENOMEM, 0);
}
minimizer->type = T;
if(n <= 0)
{
free (minimizer);
GSL_ERROR_VAL ("the problem dimension n must be greater than 0", GSL_ENOMEM, 0);
}
if(me <= 0)
{
free (minimizer);
GSL_ERROR_VAL ("the number of equality constrains me must be greater or equal to 1", GSL_ENOMEM, 0);
}
if(mi <= 0)
{
free (minimizer);
GSL_ERROR_VAL ("the number of inequality constrains me must be greater or equal to 1", GSL_ENOMEM, 0);
}