Commit f243e50c authored by Cyrille Berger's avatar Cyrille Berger

add a test for CtlChannel and add specialization for half/float to qstring

svn path=/trunk/koffice/; revision=952776
parent f2b8e665
......@@ -22,3 +22,32 @@
KoCtlChannel::~KoCtlChannel()
{
}
template<>
QString KoCtlChannelImpl<float>::channelValueText(const quint8* pixel) const
{
return QString::number(double(*channel(pixel)));
}
template<>
QString KoCtlChannelImpl<float>::normalisedChannelValueText(const quint8* pixel) const
{
return QString::number(double(scaleToF32(pixel)));
}
#include <config-openexr.h>
#ifdef HAVE_OPENEXR
template<>
QString KoCtlChannelImpl<half>::channelValueText(const quint8* pixel) const
{
return QString::number(double(*channel(pixel)));
}
template<>
QString KoCtlChannelImpl<half>::normalisedChannelValueText(const quint8* pixel) const
{
return QString::number(double(scaleToF32(pixel)));
}
#endif
......@@ -76,7 +76,7 @@ private:
}
inline _ChannelType_* channel(quint8* pixel) const
{
return reinterpret_cast<const _ChannelType_*>( pixel + m_pos );
return reinterpret_cast<_ChannelType_*>( pixel + m_pos );
}
private:
quint32 m_pos;
......
......@@ -9,3 +9,10 @@ kde4_add_unit_test(ko_ctl_color_space_info_test TESTNAME krita-cs-ko_ctl_color_s
target_link_libraries(ko_ctl_color_space_info_test ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY} pigmentcms)
########### next target ###############
set(ko_ctl_channel_test_SRCS KoCtlChannelTest.cpp ../KoCtlChannel.cpp )
kde4_add_unit_test(ko_ctl_channel_test TESTNAME krita-cs-ko_ctl_channel_test ${ko_ctl_channel_test_SRCS})
target_link_libraries(ko_ctl_channel_test ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY} pigmentcms)
/*
* Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoCtlChannelTest.h"
#include <qtest_kde.h>
#include "../KoCtlChannel.h"
#include <KoID.h>
void KoCtlChannelTest::test()
{
quint8 rgbu8[] = { 100, 50, 200 };
KoCtlChannelImpl<quint8> c8(1);
QCOMPARE(c8.channelValueText(rgbu8), QString("50"));
QCOMPARE(c8.normalisedChannelValueText(rgbu8), QString("0.196078"));
QCOMPARE(c8.scaleToU8(rgbu8), quint8(50));
QCOMPARE(c8.scaleToU16(rgbu8), quint16(12850));
QCOMPARE(c8.scaleToF32(rgbu8), 50.0f/255);
quint8 rgbu81[3];
c8.singleChannelPixel(rgbu81, rgbu8);
QCOMPARE( rgbu81[1], rgbu8[1] );
c8.scaleFromF32(rgbu8, 0.5);
QCOMPARE( rgbu8[0], quint8(100) );
QCOMPARE( rgbu8[1], quint8(127) );
QCOMPARE( rgbu8[2], quint8(200) );
float rgbf32[] = { 1.0, 0.12, -1.0 };
quint8* rgbf32_ptr= reinterpret_cast<quint8*>(rgbf32);
KoCtlChannelImpl<float> c32(4);
QCOMPARE(c32.channelValueText(rgbf32_ptr), QString("0.12"));
QCOMPARE(c32.normalisedChannelValueText(rgbf32_ptr), QString("0.12"));
QCOMPARE(c32.scaleToU8(rgbf32_ptr), quint8(0.12 * 0xFF));
QCOMPARE(c32.scaleToU16(rgbf32_ptr), quint16(0.12 * 0xFFFF));
QCOMPARE(c32.scaleToF32(rgbf32_ptr), 0.12f);
float rgbf321[3];
c32.singleChannelPixel((quint8*)rgbf321, rgbf32_ptr);
QCOMPARE( rgbf321[1], rgbf32[1] );
c32.scaleFromF32(rgbf32_ptr, 3.0f);
QCOMPARE( rgbf32[0], 1.0f );
QCOMPARE( rgbf32[1], 3.0f );
QCOMPARE( rgbf32[2], -1.0f );
}
QTEST_KDEMAIN(KoCtlChannelTest, NoGUI)
#include "KoCtlChannelTest.moc"
/*
* Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KOCTLCHANNELTEST_H_
#define _KOCTLCHANNELTEST_H_
#include <QtTest/QtTest>
class KoCtlChannelTest : public QObject
{
Q_OBJECT
private slots:
void test();
};
#endif
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