Commit 465cbe5f authored by Mathias Wein's avatar Mathias Wein

Extend Lab test with reversing normalization

parent 99a77e9e
...@@ -37,7 +37,7 @@ template<typename T> void loadZeroColor(T *values) ...@@ -37,7 +37,7 @@ template<typename T> void loadZeroColor(T *values)
values[CHANNEL_L] = KoLabColorSpaceMathsTraits<T>::zeroValueL; values[CHANNEL_L] = KoLabColorSpaceMathsTraits<T>::zeroValueL;
values[CHANNEL_A] = KoLabColorSpaceMathsTraits<T>::zeroValueAB; values[CHANNEL_A] = KoLabColorSpaceMathsTraits<T>::zeroValueAB;
values[CHANNEL_B] = KoLabColorSpaceMathsTraits<T>::zeroValueAB; values[CHANNEL_B] = KoLabColorSpaceMathsTraits<T>::zeroValueAB;
values[CHANNEL_ALPHA] = KoColorSpaceMathsTraits<T>::zeroValue; values[CHANNEL_ALPHA] = KoLabColorSpaceMathsTraits<T>::zeroValue;
} }
template<typename T> void loadUnitColor(T *values) template<typename T> void loadUnitColor(T *values)
...@@ -45,7 +45,24 @@ template<typename T> void loadUnitColor(T *values) ...@@ -45,7 +45,24 @@ template<typename T> void loadUnitColor(T *values)
values[CHANNEL_L] = KoLabColorSpaceMathsTraits<T>::unitValueL; values[CHANNEL_L] = KoLabColorSpaceMathsTraits<T>::unitValueL;
values[CHANNEL_A] = KoLabColorSpaceMathsTraits<T>::unitValueAB; values[CHANNEL_A] = KoLabColorSpaceMathsTraits<T>::unitValueAB;
values[CHANNEL_B] = KoLabColorSpaceMathsTraits<T>::unitValueAB; values[CHANNEL_B] = KoLabColorSpaceMathsTraits<T>::unitValueAB;
values[CHANNEL_ALPHA] = KoColorSpaceMathsTraits<T>::unitValue; values[CHANNEL_ALPHA] = KoLabColorSpaceMathsTraits<T>::unitValue;
}
template<typename T> void loadHalfColor(T *values)
{
values[CHANNEL_L] = KoLabColorSpaceMathsTraits<T>::halfValueL;
values[CHANNEL_A] = KoLabColorSpaceMathsTraits<T>::halfValueAB;
values[CHANNEL_B] = KoLabColorSpaceMathsTraits<T>::halfValueAB;
values[CHANNEL_ALPHA] = KoLabColorSpaceMathsTraits<T>::halfValue;
}
// L* and a* are 75%, b* is 25%
template<typename T> void loadMixedColor(T *values)
{
values[CHANNEL_L] = (KoLabColorSpaceMathsTraits<T>::unitValueL + KoLabColorSpaceMathsTraits<T>::halfValueL)/2;
values[CHANNEL_A] = (KoLabColorSpaceMathsTraits<T>::unitValueAB + KoLabColorSpaceMathsTraits<T>::halfValueAB)/2;
values[CHANNEL_B] = (KoLabColorSpaceMathsTraits<T>::zeroValueAB + KoLabColorSpaceMathsTraits<T>::halfValueAB)/2;
values[CHANNEL_ALPHA] = KoLabColorSpaceMathsTraits<T>::halfValue;
} }
void TestLabColorSpaces::verifyNormalisedZero(const QVector<float> &values) void TestLabColorSpaces::verifyNormalisedZero(const QVector<float> &values)
...@@ -64,58 +81,74 @@ void TestLabColorSpaces::verifyNormalisedUnitValue(const QVector<float> &values) ...@@ -64,58 +81,74 @@ void TestLabColorSpaces::verifyNormalisedUnitValue(const QVector<float> &values)
QCOMPARE(values[CHANNEL_ALPHA], 1.f); QCOMPARE(values[CHANNEL_ALPHA], 1.f);
} }
void TestLabColorSpaces::testNormalisation() template<typename T> void verifyValueIdentity(T *values, T *expected)
{
QCOMPARE(values[CHANNEL_L], expected[CHANNEL_L]);
QCOMPARE(values[CHANNEL_A], expected[CHANNEL_A]);
QCOMPARE(values[CHANNEL_B], expected[CHANNEL_B]);
QCOMPARE(values[CHANNEL_ALPHA], expected[CHANNEL_ALPHA]);
}
template<typename Traits> void TestLabColorSpaces::testNormalisationForType()
{ {
QVector<float> normalized(4); QVector<float> normalized(4);
quint8 testData[MAX_PIXEL_SIZE]; quint8 testData[MAX_PIXEL_SIZE];
quint8 resultData[MAX_PIXEL_SIZE];
typename Traits::channels_type *originalValues = Traits::nativeArray(testData);
typename Traits::channels_type *resultValues = Traits::nativeArray(resultData);
// Minimum // Mimimum test:
// 8-bit int loadZeroColor(originalValues);
loadZeroColor(testData); Traits::normalisedChannelsValue(testData, normalized);
KoLabU8Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedZero(normalized); verifyNormalisedZero(normalized);
// 16-bit int Traits::fromNormalisedChannelsValue(resultData, normalized);
loadZeroColor(KoLabU16Traits::nativeArray(testData)); verifyValueIdentity(resultValues, originalValues);
KoLabU16Traits::normalisedChannelsValue(testData, normalized); // Maximum test:
verifyNormalisedZero(normalized); loadUnitColor(originalValues);
#if HAVE_OPENEXR Traits::normalisedChannelsValue(testData, normalized);
// 16-bit float (half)
loadZeroColor(KoLabF16Traits::nativeArray(testData));
KoLabF16Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedZero(normalized);
#endif
// 32-bit float
loadZeroColor(KoLabF32Traits::nativeArray(testData));
KoLabF32Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedZero(normalized);
// 64-bit float
loadZeroColor(KoLabF64Traits::nativeArray(testData));
KoLabF64Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedZero(normalized);
// Maximum
// 8-bit int
loadUnitColor(testData);
KoLabU8Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedUnitValue(normalized);
// 16-bit int
loadUnitColor(KoLabU16Traits::nativeArray(testData));
KoLabU16Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedUnitValue(normalized); verifyNormalisedUnitValue(normalized);
Traits::fromNormalisedChannelsValue(resultData, normalized);
verifyValueIdentity(resultValues, originalValues);
// Half-value test:
// only tests identity after normalization + de-normalization
loadHalfColor(originalValues);
Traits::normalisedChannelsValue(testData, normalized);
Traits::fromNormalisedChannelsValue(resultData, normalized);
verifyValueIdentity(resultValues, originalValues);
// Mixed values test:
loadMixedColor(originalValues);
Traits::normalisedChannelsValue(testData, normalized);
Traits::fromNormalisedChannelsValue(resultData, normalized);
verifyValueIdentity(resultValues, originalValues);
}
void TestLabColorSpaces::testU8LabTraits()
{
// 8-bit unsigned integer test
testNormalisationForType<KoLabU8Traits>();
}
void TestLabColorSpaces::testU16LabTraits()
{
// 16-bit unsigned integer test
testNormalisationForType<KoLabU16Traits>();
}
void TestLabColorSpaces::testF16LabTraits()
{
#if HAVE_OPENEXR #if HAVE_OPENEXR
// 16-bit float (half) // 16-bit float (half) test
loadUnitColor(KoLabF16Traits::nativeArray(testData)); testNormalisationForType<KoLabF16Traits>();
KoLabF16Traits::normalisedChannelsValue(testData, normalized); #else
verifyNormalisedUnitValue(normalized); qDebug() << "16-bit float requires OpenEXR; test skipped";
#endif #endif
// 32-bit float }
loadUnitColor(KoLabF32Traits::nativeArray(testData));
KoLabF32Traits::normalisedChannelsValue(testData, normalized); void TestLabColorSpaces::testF32LabTraits()
verifyNormalisedUnitValue(normalized); {
// 64-bit float // 8-bit unsigned integer test
loadUnitColor(KoLabF64Traits::nativeArray(testData)); testNormalisationForType<KoLabF32Traits>();
KoLabF64Traits::normalisedChannelsValue(testData, normalized);
verifyNormalisedUnitValue(normalized);
} }
QTEST_GUILESS_MAIN(TestLabColorSpaces) QTEST_GUILESS_MAIN(TestLabColorSpaces)
...@@ -29,8 +29,12 @@ class TestLabColorSpaces : public QObject ...@@ -29,8 +29,12 @@ class TestLabColorSpaces : public QObject
Q_OBJECT Q_OBJECT
void verifyNormalisedZero(const QVector<float> &values); void verifyNormalisedZero(const QVector<float> &values);
void verifyNormalisedUnitValue(const QVector<float> &values); void verifyNormalisedUnitValue(const QVector<float> &values);
template<typename Traits> void testNormalisationForType();
private Q_SLOTS: private Q_SLOTS:
void testNormalisation(); void testU8LabTraits();
void testU16LabTraits();
void testF16LabTraits();
void testF32LabTraits();
}; };
#endif // TESTLABCOLORSPACES_H #endif // TESTLABCOLORSPACES_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