Commit 877b6f10 authored by Cyrille Berger's avatar Cyrille Berger

* make it possible to have transfer function for different resolution than

255
* use a QVector for the transfer function

svn path=/trunk/koffice/; revision=1080248
parent aa23b78a
......@@ -239,34 +239,30 @@ struct KisCubicCurve::Data : public QSharedData {
Data() {
init();
}
Data(const Data& data) {
Data(const Data& data) : QSharedData() {
init();
points = data.points;
}
void init() {
validSpline = false;
u16Transfer = 0;
validU16Transfer = false;
fTransfer = 0;
validFTransfer = false;
}
~Data() {
delete u16Transfer;
delete fTransfer;
}
mutable KisCubicSpline<QPointF, qreal> spline;
QList<QPointF> points;
mutable bool validSpline;
mutable quint16* u16Transfer;
mutable QVector<quint16> u16Transfer;
mutable bool validU16Transfer;
mutable qreal* fTransfer;
mutable QVector<qreal> fTransfer;
mutable bool validFTransfer;
void updateSpline();
void keepSorted();
qreal value(qreal x);
void invalidate();
template<typename _T_, typename _T2_>
void updateTransfer(_T_** transfer, bool& valid, _T2_ min, _T2_ max);
void updateTransfer(QVector<_T_>* transfer, bool& valid, _T2_ min, _T2_ max, int size);
};
void KisCubicCurve::Data::updateSpline()
......@@ -300,15 +296,16 @@ qreal KisCubicCurve::Data::value(qreal x)
}
template<typename _T_, typename _T2_>
void KisCubicCurve::Data::updateTransfer(_T_** transfer, bool& valid, _T2_ min, _T2_ max)
void KisCubicCurve::Data::updateTransfer(QVector<_T_>* transfer, bool& valid, _T2_ min, _T2_ max, int size)
{
if (!valid) {
if (!*transfer) {
*transfer = new _T_[256];
if (!valid || transfer->size() != size) {
if (transfer->size() != size) {
transfer->resize(size);
}
for (int i = 0; i < 256; ++i) {
qreal end = 1.0 / (size - 1);
for (int i = 0; i < size; ++i) {
/* Direct uncached version */
_T2_ val = value(i / 255.0) * max;
_T2_ val = value(i * end ) * max;
val = qBound(min, val, max);
(*transfer)[i] = val;
}
......@@ -423,14 +420,14 @@ void KisCubicCurve::fromString(const QString& string)
setPoints(points);
}
const quint16* KisCubicCurve::uint16Transfer() const
QVector<quint16> KisCubicCurve::uint16Transfer(int size) const
{
d->data->updateTransfer<quint16, int>(&d->data->u16Transfer, d->data->validU16Transfer, 0x0, 0xFFFF);
d->data->updateTransfer<quint16, int>(&d->data->u16Transfer, d->data->validU16Transfer, 0x0, 0xFFFF, size);
return d->data->u16Transfer;
}
const qreal* KisCubicCurve::floatTransfer() const
QVector<qreal> KisCubicCurve::floatTransfer(int size) const
{
d->data->updateTransfer<qreal, qreal>(&d->data->fTransfer, d->data->validFTransfer, 0.0, 1.0);
d->data->updateTransfer<qreal, qreal>(&d->data->fTransfer, d->data->validFTransfer, 0.0, 1.0, size);
return d->data->fTransfer;
}
......@@ -51,8 +51,8 @@ public:
int addPoint(const QPointF& point);
void removePoint(int idx);
public:
const quint16* uint16Transfer() const;
const qreal* floatTransfer() const;
QVector<quint16> uint16Transfer(int size = 256) const;
QVector<qreal> floatTransfer(int size = 256) const;
public:
QString toString() const;
void fromString(const QString&);
......
......@@ -143,16 +143,19 @@ void KisCubicCurveTest::testValue()
void KisCubicCurveTest::testTransfer()
{
KisCubicCurve cc;
QVERIFY(cc.uint16Transfer());
QCOMPARE(cc.uint16Transfer().size(), 256);
qreal denom = 1 / 255.0;
for(int i = 0; i < 256; ++i)
{
QCOMPARE(cc.uint16Transfer()[i], quint16( cc.value(i / 255.0) * 0xFFFF) );
QCOMPARE(cc.uint16Transfer()[i], quint16( cc.value(i * denom) * 0xFFFF) );
}
QVERIFY(cc.floatTransfer());
QCOMPARE(cc.floatTransfer().size(), 256);
for(int i = 0; i < 256; ++i)
{
QCOMPARE(cc.floatTransfer()[i], i / 255.0);
QCOMPARE(cc.floatTransfer()[i], i * denom);
}
QCOMPARE(cc.uint16Transfer(1024).size(), 1024);
QCOMPARE(cc.floatTransfer(1024).size(), 1024);
}
QTEST_KDEMAIN(KisCubicCurveTest, GUI)
......
......@@ -179,7 +179,7 @@ KoColorTransformation* KisBrightnessContrastFilter::createTransformation(const K
const KisBrightnessContrastFilterConfiguration* configBC = dynamic_cast<const KisBrightnessContrastFilterConfiguration*>(config);
if (!configBC) return 0;
KoColorTransformation * adjustment = cs->createBrightnessContrastAdjustment(configBC->m_curve.uint16Transfer());
KoColorTransformation * adjustment = cs->createBrightnessContrastAdjustment(configBC->m_curve.uint16Transfer().data());
return adjustment;
}
......
......@@ -413,7 +413,7 @@ KoColorTransformation* KisPerChannelFilter::createTransformation(const KoColorSp
const quint16** transfers = new const quint16*[configBC->m_curves.size()];
for(int i = 0; i < configBC->m_curves.size(); ++i)
{
transfers[i] = configBC->m_curves[i].uint16Transfer();
transfers[i] = configBC->m_curves[i].uint16Transfer().data();
}
KoColorTransformation* t = cs->createPerChannelAdjustment(transfers);
delete transfers;
......
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