Commit 2d9e9d46 authored by Emanuele Tamponi's avatar Emanuele Tamponi

Various changes. Most important:

- now the color space loading code is much cleaner
- the tests have been rewritted in order to do some checks and they works great
- the mixing test has been disabled (completely removed) because I need to rewrite
  it as it will be the base upon which I'll draw all the graphs I'll need in future
  works.

svn path=/trunk/koffice/; revision=757448
parent 417c04b7
......@@ -73,6 +73,13 @@ bool KisIlluminantProfile::load()
QDataStream data(&file);
{
// Clear previous data
if (m_T)
gsl_matrix_free(m_T);
if (m_P)
gsl_vector_free(m_P);
}
{
// Profile name
QString name;
......
......@@ -45,6 +45,11 @@ struct KisKSColorSpaceTrait : public KoColorSpaceTrait<_TYPE_, 2*_wavelen_number
return d[2*wavelen+1];
}
inline static _TYPE_ &nativealpha(quint8* data)
{
return reinterpret_cast<_TYPE_ *>(data)[2*_wavelen_number_];
}
inline static const _TYPE_ &K(const quint8* data, const quint32 wavelen)
{
const _TYPE_ *d = reinterpret_cast<const _TYPE_ *>(data);
......@@ -56,6 +61,11 @@ struct KisKSColorSpaceTrait : public KoColorSpaceTrait<_TYPE_, 2*_wavelen_number
const _TYPE_ *d = reinterpret_cast<const _TYPE_ *>(data);
return d[2*wavelen+1];
}
inline static const _TYPE_ &nativealpha(const quint8* data)
{
return reinterpret_cast<const _TYPE_ *>(data)[2*_wavelen_number_];
}
};
#endif // KIS_KS_COLORSPACE_TRAITS_H_
......@@ -77,7 +77,7 @@ public:
for (int i = 0; i < 3; i++)
dst[2-i] = KoColorSpaceMaths<double,quint16>::scaleToA(gsl_vector_get(m_rgbvec, i));
dst[3] = KoColorSpaceMaths<_TYPE_,quint16>::scaleToA(CSTrait::alpha(src));
dst[3] = KoColorSpaceMaths<_TYPE_,quint16>::scaleToA(CSTrait::nativealpha(src));
src += CSTrait::pixelSize;
dst += 4;
......
......@@ -134,7 +134,7 @@ public:
memmove(m_cache.value(m_lookup), dst, pixelSize-4);
}
CSTrait::setAlpha(dst, KoColorSpaceMaths<quint16,quint8>::scaleToA(src[3]), 1);
CSTrait::nativealpha(dst) = KoColorSpaceMaths<quint16,float>::scaleToA(src[3]);
src += 4;
dst += pixelSize;
......
......@@ -42,114 +42,42 @@ KSColorSpacesPlugin::KSColorSpacesPlugin(QObject *parent, const QStringList &)
: QObject(parent)
{
QStringList list;
QString curr;
KisIlluminantProfile *ill;
KoColorSpaceRegistry *f = KoColorSpaceRegistry::instance();
KGlobal::mainComponent().dirs()->addResourceType("illuminant_profiles", 0, "share/apps/krita/illuminants");
list = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "*.ill", KStandardDirs::Recursive);
foreach(curr, list) {
ill = new KisIlluminantProfile(curr);
f->addProfile(ill);
}
foreach(QString curr, list)
f->addProfile(new KisIlluminantProfile(curr));
curr = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "D65_6_high.ill", KStandardDirs::Recursive)[0];
ill = new KisIlluminantProfile(curr);
{
KoColorSpace *colorSpaceKSQP = new KisKSQPColorSpace<float,6>(ill->clone());
KoColorSpaceFactory *csf = new KisKSQPColorSpaceFactory<float,6>();
Q_CHECK_PTR(colorSpaceKSQP);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSQP6F32HISTO", i18n("6-pairs KS QP F32 Histogram")), colorSpaceKSQP) );
}
f->add(new KisKSLCColorSpaceFactory<float,6>);
f->add(new KisKSLCColorSpaceFactory<float,9>);
f->add(new KisKSQPColorSpaceFactory<float,6>);
f->add(new KisKSQPColorSpaceFactory<float,9>);
#ifdef HAVE_OPENEXR
{
KoColorSpace *colorSpaceKSQP = new KisKSQPColorSpace<half,6>(ill->clone());
KoColorSpaceFactory *csf = new KisKSQPColorSpaceFactory<half,6>();
Q_CHECK_PTR(colorSpaceKSQP);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSQP6F16HISTO", i18n("6-pairs KS QP Half Histogram")), colorSpaceKSQP) );
}
f->add(new KisKSLCColorSpaceFactory<half,6>);
f->add(new KisKSLCColorSpaceFactory<half,9>);
f->add(new KisKSQPColorSpaceFactory<half,6>);
f->add(new KisKSQPColorSpaceFactory<half,9>);
#endif
delete ill;
curr = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "D65_6_high.ill", KStandardDirs::Recursive)[0];
ill = new KisIlluminantProfile(curr);
{
KoColorSpace *colorSpaceKS = new KisKSLCColorSpace<float,6>(ill->clone());
KoColorSpaceFactory *csf = new KisKSLCColorSpaceFactory<float,6>();
Q_CHECK_PTR(colorSpaceKS);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSLC6F32HISTO", i18n("6-pairs KS LC F32 Histogram")), colorSpaceKS) );
}
QVector<const KoColorSpace *> css;
css.append(f->colorSpace(KisKSLCColorSpace<float,6>::ColorSpaceId().id(),0));
css.append(f->colorSpace(KisKSLCColorSpace<float,9>::ColorSpaceId().id(),0));
css.append(f->colorSpace(KisKSQPColorSpace<float,6>::ColorSpaceId().id(),0));
css.append(f->colorSpace(KisKSQPColorSpace<float,9>::ColorSpaceId().id(),0));
#ifdef HAVE_OPENEXR
{
KoColorSpace *colorSpaceKS = new KisKSLCColorSpace<half,6>(ill->clone());
KoColorSpaceFactory *csf = new KisKSLCColorSpaceFactory<half,6>();
Q_CHECK_PTR(colorSpaceKS);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSLC6F16HISTO", i18n("6-pairs KS LC Half Histogram")), colorSpaceKS) );
}
css.append(f->colorSpace(KisKSLCColorSpace<half,6>::ColorSpaceId().id(),0));
css.append(f->colorSpace(KisKSLCColorSpace<half,9>::ColorSpaceId().id(),0));
css.append(f->colorSpace(KisKSQPColorSpace<half,6>::ColorSpaceId().id(),0));
css.append(f->colorSpace(KisKSQPColorSpace<half,9>::ColorSpaceId().id(),0));
#endif
delete ill;
curr = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "D65_9_high.ill", KStandardDirs::Recursive)[0];
ill = new KisIlluminantProfile(curr);
{
KoColorSpace *colorSpaceKS = new KisKSLCColorSpace<float,9>(ill->clone());
KoColorSpaceFactory *csf = new KisKSLCColorSpaceFactory<float,9>();
Q_CHECK_PTR(colorSpaceKS);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSLC9F32HISTO", i18n("9-pairs KS LC F32 Histogram")), colorSpaceKS) );
}
#ifdef HAVE_OPENEXR
{
KoColorSpace *colorSpaceKS = new KisKSLCColorSpace<half,9>(ill->clone());
KoColorSpaceFactory *csf = new KisKSLCColorSpaceFactory<half,9>();
Q_CHECK_PTR(colorSpaceKS);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSLC9F16HISTO", i18n("9-pairs KS LC Half Histogram")), colorSpaceKS) );
}
#endif
delete ill;
/*
curr = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "D65_12_high.ill", KStandardDirs::Recursive)[0];
ill = new KisIlluminantProfile(curr);
{
KoColorSpace *colorSpaceKS = new KisKSLCColorSpace<float,12>(ill->clone());
KoColorSpaceFactory *csf = new KisKSLCColorSpaceFactory<float,12>();
Q_CHECK_PTR(colorSpaceKS);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSLC12F32HISTO", i18n("12-pairs KS LC F32 Histogram")), colorSpaceKS) );
}
#ifdef HAVE_OPENEXR
{
KoColorSpace *colorSpaceKS = new KisKSLCColorSpace<half,12>(ill->clone());
KoColorSpaceFactory *csf = new KisKSLCColorSpaceFactory<half,12>();
Q_CHECK_PTR(colorSpaceKS);
f->add(csf);
foreach(const KoColorSpace *cs, css) {
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID("KSLC12F16HISTO", i18n("12-pairs KS LC Half Histogram")), colorSpaceKS) );
new KoBasicHistogramProducerFactory<KoBasicF32HistogramProducer>
(KoID(cs->id()+"HISTO", i18n(QString("%1 Histogram").arg(cs->name()).toUtf8().data())), cs->clone()));
}
#endif
delete ill;
*/
}
KSColorSpacesPlugin::~KSColorSpacesPlugin()
......
......@@ -29,7 +29,6 @@ class ChannelConverterTest : public QObject
private slots:
void testKSReflectance();
// void testRGBsRGB();
};
......
......@@ -18,14 +18,17 @@
*/
#include <qtest_kde.h>
#include "kis_illuminant_profile_test.h"
#include "kis_illuminant_profile.h"
#include <KGlobal>
#include <KLocale>
#include <KStandardDirs>
#include <QString>
#include <QStringList>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
......@@ -59,44 +62,77 @@ void gsl_print(const gsl_vector *V, const char *name)
cout << endl;
}
void KisIlluminantProfileTest::testLoading()
void KisIlluminantProfileTest::initTestCase()
{
KGlobal::mainComponent().dirs()->addResourceType("illuminant_profiles", 0, "share/apps/krita/illuminants");
QString d659 = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "D65_9_low.ill", KStandardDirs::Recursive)[0];
list = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "*.ill", KStandardDirs::Recursive);
}
KisIlluminantProfile *p = new KisIlluminantProfile;
QVERIFY(p->valid() == false);
p->setFileName(d659);
QVERIFY(p->valid() == false);
p->load();
QVERIFY(p->valid() == true);
qDebug() << "Profile name: " << p->name();
QVERIFY(p->wavelenghts() == 9);
QCOMPARE(p->Kblack(), 4.3);
QCOMPARE(p->Sblack(), 0.14);
gsl_print(p->T(), "Transformation matrix: ");
gsl_print(p->P(), "Positions vector: ");
delete p;
void KisIlluminantProfileTest::testLoading()
{
QString d9low = list.filter("9_low")[0];
QString d9high = list.filter("9_high")[0];
KisIlluminantProfile *p1 = new KisIlluminantProfile;
QVERIFY(p1->valid() == false);
p1->setFileName(d9low);
QVERIFY(p1->valid() == false);
p1->load();
QVERIFY(p1->valid() == true);
QVERIFY(p1->wavelenghts() == 9);
QCOMPARE(p1->Kblack(), 4.3);
QCOMPARE(p1->Sblack(), 0.14);
gsl_print(p1->T(), "Transformation matrix: ");
gsl_print(p1->P(), "Positions vector: ");
KisIlluminantProfile *p2 = dynamic_cast<KisIlluminantProfile*>(p1->clone());
delete p1;
QVERIFY(p2->valid() == true);
QVERIFY(p2->wavelenghts() == 9);
QCOMPARE(p2->Kblack(), 4.3);
QCOMPARE(p2->Sblack(), 0.14);
gsl_print(p2->T(), "Transformation matrix: ");
gsl_print(p2->P(), "Positions vector: ");
p2->setFileName(d9high);
QVERIFY(p2->valid() == true);
p2->load();
QVERIFY(p2->valid() == true);
QVERIFY(p2->wavelenghts() == 9);
QCOMPARE(p2->Kblack(), 11.0);
QCOMPARE(p2->Sblack(), 0.35);
gsl_print(p2->T(), "Transformation matrix: ");
gsl_print(p2->P(), "Positions vector: ");
delete p2;
p1 = new KisIlluminantProfile(d9low);
QVERIFY(p2->valid() == true);
QVERIFY(p2->wavelenghts() == 9);
QCOMPARE(p2->Kblack(), 4.3);
QCOMPARE(p2->Sblack(), 0.14);
gsl_print(p2->T(), "Transformation matrix: ");
gsl_print(p2->P(), "Positions vector: ");
delete p1;
}
void KisIlluminantProfileTest::testSaving()
{
QString d659 = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "D65_9_low.ill", KStandardDirs::Recursive)[0];
QString d659 = list.filter("9_low")[0];
KisIlluminantProfile *p = new KisIlluminantProfile(d659);
p->save("D659Save.ill");
delete p;
p = new KisIlluminantProfile("D659Save.ill");
p = new KisIlluminantProfile("D659Save.ill");
QVERIFY(p->valid() == true);
// QVERIFY(p->name() == "D65 9 Test Profile");
qDebug() << "Profile name: " << p->name();
QVERIFY(p->wavelenghts() == 9);
QCOMPARE(p->Kblack(), 4.3);
QCOMPARE(p->Sblack(), 0.14);
gsl_print(p->T(), "Transformation matrix: ");
gsl_print(p->P(), "Positions vector: ");
delete p;
}
......
......@@ -21,15 +21,21 @@
#define KIS_ILLUMINANT_PROFILE_TEST_H_
#include <QtTest/QtTest>
#include <QStringList>
class KisIlluminantProfileTest : public QObject
{
Q_OBJECT
private slots:
private slots:
void testLoading();
void testSaving();
void initTestCase();
void testLoading();
void testSaving();
private:
QStringList list;
};
......
......@@ -21,16 +21,22 @@
#define KIS_KS_COLORSPACE_TEST_H_
#include <QtTest/QtTest>
#include <QStringList>
class KisKSColorSpaceTest : public QObject
{
Q_OBJECT
private slots:
private slots:
void testConstructor();
void testToFromRgbA16();
void testMixing();
void initTestCase();
void testConstructor();
void testRegistry();
void testToFromRgbA16();
private:
QStringList list;
};
......
......@@ -18,12 +18,12 @@
*/
#include <qtest_kde.h>
#include <cmath>
#include "mixing_test.h"
#include "kis_illuminant_profile.h"
#include "kis_kslc_colorspace.h"
#include "kis_ksqp_colorspace.h"
#include <KGlobal>
#include <KLocale>
......@@ -31,147 +31,30 @@
#include <QImage>
#include <QPainter>
#include <QPicture>
#include <QString>
#include <QStringList>
// Stress test, it doesn't do compares and the like... if you come to an end, then probably everything works ;-)
void MixingTest::testMixing()
{
// These values are tied for blue - yellow mixing.
const int T1 = 0;
const int T2 = 16;
const int T = 16;
const int step = 2;
const int base = 256/T;
const int basewidth = 16;
const int ncolor1 = (int)pow((T2-T1)/step+1,2);
const int ncolor2 = (int)pow((T2-T1)/step+1,2);
KGlobal::mainComponent().dirs()->addResourceType("illuminant_profiles", 0, "share/apps/krita/illuminants");
QString d65 = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", illuminant, KStandardDirs::Recursive)[0];
const KisIlluminantProfile *profile = new KisIlluminantProfile(d65);
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(KisKSLCColorSpace<float,N>::ColorSpaceId().id(), profile);
QVERIFY2(cs != 0, "Created colorspace");
QVERIFY(cs->profileIsCompatible(profile));
QColor color1, color2, colorm;
quint8 *data1 = new quint8[cs->pixelSize()];
quint8 *data2 = new quint8[cs->pixelSize()];
quint8 *datam = new quint8[cs->pixelSize()];
QBrush b;
QPainter p;
int currx, curry = 0;
QImage image(basewidth*3*ncolor2, basewidth*ncolor1, QImage::Format_ARGB32);
for (int i1 = T1; i1 <= T1; i1+=step) {
for (int j1 = T1; j1 <= T2; j1+=step) {
for (int k1 = T1; k1 <= T2; k1+=step) {
currx = 0;
for (int i2 = T1; i2 <= T2; i2+=step) {
for (int j2 = T1; j2 <= T2; j2+=step) {
for (int k2 = T1; k2 <= T1; k2+=step) {
color1 = QColor(base*i1?base*i1-1:0,base*j1?base*j1-1:0,base*k1?base*k1-1:0);
color2 = QColor(base*i2?base*i2-1:0,base*j2?base*j2-1:0,base*k2?base*k2-1:0);
cs->fromQColor(color1, data1);
cs->fromQColor(color2, data2);
for (uint i = 0; i < 2*N+1; i++)
reinterpret_cast<float*>(datam)[i] =
(reinterpret_cast<float*>(data1)[i] +
reinterpret_cast<float*>(data2)[i]) / 2.0;
cs->toQColor(datam, &colorm);
p.begin(&image);
b = QBrush(color1);
p.fillRect(currx+0*basewidth, curry, basewidth,basewidth, b);
b = QBrush(color2);
p.fillRect(currx+1*basewidth, curry, basewidth,basewidth, b);
b = QBrush(colorm);
p.fillRect(currx+2*basewidth, curry, basewidth,basewidth, b);
p.end();
currx += basewidth*3;
}
}
}
curry += basewidth;
}
}
}
image.save("table.jpg");
delete [] datam;
delete [] data2;
delete [] data1;
delete profile;
}
template< quint32 N >
void mix(const float *data1, float c1, const float *data2, float c2, float *datam)
void mix(const quint32 N, const float *data1, float c1, const float *data2, float c2, float *datam)
{
for (uint i = 0; i < 2*N; i++)
datam[i] = c1*data1[i] + c2*data2[i];
datam[2*N] = 1;
}
void MixingTest::testMixing2()
void MixingTest::initTestCase()
{
KGlobal::mainComponent().dirs()->addResourceType("illuminant_profiles", 0, "share/apps/krita/illuminants");
QString d65 = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", illuminant, KStandardDirs::Recursive)[0];
const KisIlluminantProfile *profile = new KisIlluminantProfile(d65);
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(KisKSLCColorSpace<float,N>::ColorSpaceId().id(), profile);
QVERIFY2(cs != 0, "Created colorspace");
QVERIFY(cs->profileIsCompatible(profile));
QColor red(255,0,0), green(0,255,0), blue(0,0,255), yellow(255,255,0), colorm;
float *datared = new float[cs->pixelSize()/4];
float *datagreen = new float[cs->pixelSize()/4];
float *datablue = new float[cs->pixelSize()/4];
float *datayellow = new float[cs->pixelSize()/4];
float *datam = new float[cs->pixelSize()/4];
cs->fromQColor(red, reinterpret_cast<quint8*>(datared));
cs->fromQColor(green, reinterpret_cast<quint8*>(datagreen));
cs->fromQColor(blue, reinterpret_cast<quint8*>(datablue));
cs->fromQColor(yellow, reinterpret_cast<quint8*>(datayellow));
QImage image(600, 600, QImage::Format_ARGB32);
QPainter p(&image);
for (int x = 0; x <= 599; x++) {
float cright = ((float)x)/599.0f;
float cleft = 1.0f - cright;
mix<N>(datared, cleft, datagreen, cright, datam);
cs->toQColor(reinterpret_cast<quint8*>(datam), &colorm);
p.fillRect(x, 0, 1, 100, colorm);
mix<N>(datared, cleft, datablue, cright, datam);
cs->toQColor(reinterpret_cast<quint8*>(datam), &colorm);
p.fillRect(x, 100, 1, 100, QBrush(colorm));
mix<N>(datared, cleft, datayellow, cright, datam);
cs->toQColor(reinterpret_cast<quint8*>(datam), &colorm);
p.fillRect(x, 200, 1, 100, QBrush(colorm));
list = KGlobal::mainComponent().dirs()->findAllResources("illuminant_profiles", "*.ill", KStandardDirs::Recursive);
}
mix<N>(datagreen, cleft, datablue, cright, datam);
cs->toQColor(reinterpret_cast<quint8*>(datam), &colorm);
p.fillRect(x, 300, 1, 100, QBrush(colorm));
void MixingTest::testMixing1()
{
mix<N>(datagreen, cleft, datayellow, cright, datam);
cs->toQColor(reinterpret_cast<quint8*>(datam), &colorm);
p.fillRect(x, 400, 1, 100, QBrush(colorm));
}
mix<N>(datablue, cleft, datayellow, cright, datam);
cs->toQColor(reinterpret_cast<quint8*>(datam), &colorm);
p.fillRect(x, 500, 1, 100, QBrush(colorm));
}
p.end();
image.save("tableaveraged_"+illuminant+".jpg");
void MixingTest::testMixing2()
{
delete [] datam;
delete [] datared;
delete [] datagreen;
delete [] datablue;
delete [] datayellow;
delete profile;
}
QTEST_KDEMAIN(MixingTest, NoGUI)
......
......@@ -21,7 +21,7 @@
#define MIXING_TEST_H_
#include <QtTest/QtTest>
#include <QString>
#include <QStringList>
class MixingTest : public QObject
{
......@@ -30,18 +30,12 @@ class MixingTest : public QObject
private slots:
void initTestCase();
void testMixing();
void testMixing1();
void testMixing2();
private:
QString illuminant;
static const quint32 N = 9;
QStringList list;
};
void MixingTest::initTestCase()
{
illuminant = "D65_9_low.ill";
}
#endif // MIXING_TEST_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