summaryrefslogtreecommitdiffstats
path: root/chalk/colorspaces/rgb_f16half
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/colorspaces/rgb_f16half
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/colorspaces/rgb_f16half')
-rw-r--r--chalk/colorspaces/rgb_f16half/Makefile.am35
-rw-r--r--chalk/colorspaces/rgb_f16half/chalk_rgb_f16half_plugin.desktop76
-rw-r--r--chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cc952
-rw-r--r--chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.h144
-rw-r--r--chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc63
-rw-r--r--chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.h39
-rw-r--r--chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.rc9
-rw-r--r--chalk/colorspaces/rgb_f16half/tests/Makefile.am19
-rw-r--r--chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cc545
-rw-r--r--chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.h47
10 files changed, 1929 insertions, 0 deletions
diff --git a/chalk/colorspaces/rgb_f16half/Makefile.am b/chalk/colorspaces/rgb_f16half/Makefile.am
new file mode 100644
index 00000000..2c3bbfa1
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/Makefile.am
@@ -0,0 +1,35 @@
+# Install the desktop file needed to detect the plugin
+kde_services_DATA = chalk_rgb_f16half_plugin.desktop
+
+INCLUDES = \
+ -I$(srcdir)/../../sdk \
+ -I$(srcdir)/../../chalkcolor/color_strategy/ \
+ -I$(srcdir)/../../chalkcolor/ \
+ $(OPENEXR_CFLAGS) \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+
+lib_LTLIBRARIES = libchalk_rgb_f16half.la
+libchalk_rgb_f16half_la_SOURCES = kis_rgb_f16half_colorspace.cc
+libchalk_rgb_f16half_la_LDFLAGS = $(all_libraries)
+libchalk_rgb_f16half_la_LIBADD = ../../chalkcolor/libchalkcolor.la
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = chalk_rgb_f16half_plugin.la
+
+# Srcs for the plugin
+chalk_rgb_f16half_plugin_la_SOURCES = rgb_f16half_plugin.cc
+noinst_HEADERS = rgb_f16half_plugin.h kis_rgb_f16half_colorspace.h
+
+chalk_rgb_f16half_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) -lkdecore -lkdeui -lkjs -lkdefx -lkio -lkparts -llcms
+chalk_rgb_f16half_plugin_la_LIBADD = libchalk_rgb_f16half.la ../../chalkcolor/libchalkcolor.la
+
+chalk_rgb_f16half_plugin_la_METASOURCES = AUTO
+
+if include_kunittest_tests
+TESTSDIR = tests
+endif
+
+SUBDIRS = . $(TESTSDIR)
+
diff --git a/chalk/colorspaces/rgb_f16half/chalk_rgb_f16half_plugin.desktop b/chalk/colorspaces/rgb_f16half/chalk_rgb_f16half_plugin.desktop
new file mode 100644
index 00000000..523903bf
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/chalk_rgb_f16half_plugin.desktop
@@ -0,0 +1,76 @@
+[Desktop Entry]
+Name=RGB Color Model (16-bit float 'half')
+Name[bg]=Цветови модел RGB (16-bit float 'half')
+Name[ca]=Model de color RGB (paleta 'mitja' de 16 bits)
+Name[cy]=Model Lliw RGB (arnawf 16-did 'hanner')
+Name[da]=RGB-farvemodel (16-bit heltal 'halv')
+Name[de]=RGB-Farbmodell (16-bit Fließkomma 'Halb')
+Name[el]=Χρωματικό μοντέλο RGB (16 bit μισοί δεκαδικοί)
+Name[en_GB]=RGB Colour Model (16-bit float 'half')
+Name[es]=Modelo de color RGB (decimal «medio» de 16 bits)
+Name[et]=RGB värvimudel (16-bitine murdarv 'half')
+Name[fa]=مدل رنگ RGB )»نیمه« شناور ۱۶ بیتی(
+Name[fr]=Modèle de couleurs RVB (demi flottants 16 bits)
+Name[fy]=RGB-kleurmodel (16-bit float 'heal')
+Name[gl]=Modelo de Cores RGB (vírgula flutuante 16-bit 'half')
+Name[he]=מודל צבעים RGB (16 סיביות)
+Name[hu]=RGB színmodell (16 bites lebegőpontos - 'feles')
+Name[is]=RGB litategund (16-bita fleytitala)
+Name[it]=Modello di colore RGB (semi-virgola mobile a 16 bit)
+Name[ja]=RGB カラーモデル (16-bit float 'half')
+Name[km]=ម៉ូដែល​ពណ៌​RGB (ចំនួន​ទសភាគ 16 ប៊ីត​ 'ពាក់​កណ្ដាល')
+Name[nb]=RGB-fargemodell (16-bit flytende 'halv')
+Name[nds]=RGB-Klöörmodell (16-Bit Fleetkomma "half")
+Name[ne]=RGB रङ मोडेल (१६-बिट उत्प्लावन 'आधा')
+Name[nl]=RGB-kleurmodel (16-bit float 'half')
+Name[pl]=Przestrzeń barw RGB ("połowa" 16-bitowej liczby zmiennoprzecinkowej)
+Name[pt]=Modelo de Cor RGB (v. flutuante de 16-bits 'half')
+Name[pt_BR]=Modelo de Cor RGB (ponto flutuante de 16-bits 'half')
+Name[ru]=RGB (16-бит с плавающей точкой)
+Name[sk]=Model farieb RGB (16-bitové reálne čísla 'half')
+Name[sl]=Barvni model RGB (16-bitno celo število, »polovica«)
+Name[sr]=RGB модел боја (16-битно реално „полу“)
+Name[sr@Latn]=RGB model boja (16-bitno realno „polu“)
+Name[sv]=RGB-färgmodell (16-bitars flyttal 'halva')
+Name[uk]=Модель кольору RGB (16-бітне дробове число "half")
+Name[uz]=RGB rang usuli (16-bit 'yarim' kasr)
+Name[uz@cyrillic]=RGB ранг усули (16-бит 'ярим' каср)
+Name[zh_TW]=RGB 色彩模型 (32-bit 浮點數「半」)
+Comment=Color model for 16-bit floating point 'half' per channel RGB images
+Comment[bg]=Цветови модел за 16 битови изображения RGB за полуканал
+Comment[ca]=Model de color per a paleta 'mitja' de 16 bits-canal d'imatges RGB
+Comment[da]=Farvemodel for 16-bit decimaltal 'halvdel' pr kanal RGB-billeder
+Comment[de]=Farbmodell für 16-bit Fließkomma 'Halb' pro Kanal RGB-Bilder
+Comment[el]=Χρωματικό μοντέλο για 16-bit μισούς δεκαδικούς ανά κανάλι RGB εικόνες
+Comment[en_GB]=Colour model for 16-bit floating point 'half' per channel RGB images
+Comment[es]=Modelo de color decimal «medio» de 16 bits por canal para imágenes RGB
+Comment[et]=16-bitiste murdarvuliste ('half') kanalitega RGB-piltide värvimudel
+Comment[fa]=مدل رنگ برای ممیز »نیمه« شناور برای هر تصویر RGB مجرا
+Comment[fi]=Värimalli 16-bittisille/kanavaisille RGB-kuville
+Comment[fr]=Modèle de couleurs pour des images RVB en 16 bits flottants (demi) par canal
+Comment[fy]=Kleurmodel foar RGB-ôfbeeldings mei 16-bit driuwende komma 'heal' de kanaal
+Comment[gl]=Espazo de cores para imaxes RGB de 16-bit de vírgula flutuante 'half' por canal
+Comment[he]=מודל צבעים עבור תמונות RGB של 16 סיביות/ערוצים
+Comment[hu]=Színmodell 16 bit (lebegőpontos, 'feles')/csatorna RGB képekhez
+Comment[is]=Litategund fyrir 16-bita fleytitölu á rás RGB myndir
+Comment[it]=Modello di colore per immagini RGB in semi-virgola mobile a canale di 16 bit
+Comment[km]=ម៉ូលដែល​ពណ៌​ 16 ប៊ីត​ចំណុច​ដែល​អណ្ដែត​ 'ពាក្យ​កណ្ដាល' ក្នុង​ឆានែល​រូបភាព​ RGB
+Comment[nb]=Fargemodell for RGB-bilde med 16 bit flyttall 'halv' per kanal
+Comment[nds]=Klöörmodell för RGB-Biller mit 16-Bit Fleetkomma "half" per Kanaal
+Comment[ne]='आधा' प्रति च्यानल RGB छविहरूको १६-बिट उत्प्लावन बिन्दुका लागि रङ मोडेल
+Comment[nl]=Kleurmodel voor RGB-afbeeldingen met 16-bit drijvende komma 'half' per kanaal
+Comment[pl]=Przestrzeń barw dla obrazków RGB z "połową" 16-bitowej liczby zmiennoprzecinkowej na kanał
+Comment[pt]=Modelo de cor para imagens RGB com 16 bits de vírgula flutuante 'half' por canal
+Comment[pt_BR]=Modelo de cor para imagens RGB com 16 bits de ponto flutuante 'half' por canal
+Comment[ru]=Цветовое пространство RGB (16-бит/канал с плавающей точкой)
+Comment[sk]=Model farieb pre RGB obrázky so 16-bitovými reálnymi číslami 'half' na kanál
+Comment[sl]=Barvni model za slike RGB s 16-bitno plavajočo vejico na kanal
+Comment[sr]=Модел боја за RGB слике, 16-битно реално „полу“ по каналу
+Comment[sr@Latn]=Model boja za RGB slike, 16-bitno realno „polu“ po kanalu
+Comment[sv]=Färgmodell för 16-bitars flyttal 'halva' per kanal RGB-bilder
+Comment[uk]=Модель кольорів для 16-бітних зображень RGB, з плаваючою комою, "половина" на канал
+Comment[zh_TW]=每色頻 16-bit 半浮點 RGB 圖片的色彩模型
+ServiceTypes=Chalk/ColorSpace
+Type=Service
+X-KDE-Library=chalk_rgb_f16half_plugin
+X-Chalk-Version=2
diff --git a/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cc b/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cc
new file mode 100644
index 00000000..fb2df8c1
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cc
@@ -0,0 +1,952 @@
+/*
+ * Copyright (c) 2005 Adrian Page <[email protected]>
+ *
+ * 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 <config.h>
+#include <limits.h>
+#include <stdlib.h>
+#include LCMS_HEADER
+
+#include <tqimage.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "kis_rgb_f16half_colorspace.h"
+#include "kis_f32_base_colorspace.h"
+#include "kis_color_conversions.h"
+
+namespace {
+ const TQ_INT32 MAX_CHANNEL_RGB = 3;
+ const TQ_INT32 MAX_CHANNEL_RGBA = 4;
+}
+
+#include "kis_integer_maths.h"
+
+#ifndef HAVE_POWF
+#undef powf
+#define powf pow
+#endif
+
+//#define HALF_MAX ((half)1.0f) //temp
+
+#define EPSILON HALF_EPSILON
+
+// FIXME: lcms doesn't support 16-bit float
+#define RGBAF16HALF_LCMS_TYPE TYPE_BGRA_16
+
+KisRgbF16HalfColorSpace::KisRgbF16HalfColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile *p) :
+ KisF16HalfBaseColorSpace(KisID("RGBAF16HALF", i18n("RGB (16-bit float/channel)")), RGBAF16HALF_LCMS_TYPE, icSigRgbData, tqparent, p)
+{
+ m_channels.push_back(new KisChannelInfo(i18n("Red"), i18n("R"), PIXEL_RED * sizeof(half), KisChannelInfo::COLOR, KisChannelInfo::FLOAT16, sizeof(half)));
+ m_channels.push_back(new KisChannelInfo(i18n("Green"), i18n("G"), PIXEL_GREEN * sizeof(half), KisChannelInfo::COLOR, KisChannelInfo::FLOAT16, sizeof(half)));
+ m_channels.push_back(new KisChannelInfo(i18n("Blue"), i18n("B"), PIXEL_BLUE * sizeof(half), KisChannelInfo::COLOR, KisChannelInfo::FLOAT16, sizeof(half)));
+ m_channels.push_back(new KisChannelInfo(i18n("Alpha"), i18n("A"), PIXEL_ALPHA * sizeof(half), KisChannelInfo::ALPHA, KisChannelInfo::FLOAT16, sizeof(half)));
+
+ //cmsHPROFILE hProfile = cmsCreate_sRGBProfile();
+ //setDefaultProfile( new KisProfile(hProfile, RGBAF16HALF_LCMS_TYPE) );
+
+ m_alphaPos = PIXEL_ALPHA * sizeof(half);
+}
+
+KisRgbF16HalfColorSpace::~KisRgbF16HalfColorSpace()
+{
+}
+
+void KisRgbF16HalfColorSpace::setPixel(TQ_UINT8 *dst, half red, half green, half blue, half alpha) const
+{
+ Pixel *dstPixel = reinterpret_cast<Pixel *>(dst);
+
+ dstPixel->red = red;
+ dstPixel->green = green;
+ dstPixel->blue = blue;
+ dstPixel->alpha = alpha;
+}
+
+void KisRgbF16HalfColorSpace::getPixel(const TQ_UINT8 *src, half *red, half *green, half *blue, half *alpha) const
+{
+ const Pixel *srcPixel = reinterpret_cast<const Pixel *>(src);
+
+ *red = srcPixel->red;
+ *green = srcPixel->green;
+ *blue = srcPixel->blue;
+ *alpha = srcPixel->alpha;
+}
+
+void KisRgbF16HalfColorSpace::fromTQColor(const TQColor& c, TQ_UINT8 *dstU8, KisProfile *)
+{
+ Pixel *dst = reinterpret_cast<Pixel *>(dstU8);
+
+ dst->red = UINT8_TO_HALF(c.red());
+ dst->green = UINT8_TO_HALF(c.green());
+ dst->blue = UINT8_TO_HALF(c.blue());
+}
+
+void KisRgbF16HalfColorSpace::fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dstU8, KisProfile *)
+{
+ Pixel *dst = reinterpret_cast<Pixel *>(dstU8);
+
+ dst->red = UINT8_TO_HALF(c.red());
+ dst->green = UINT8_TO_HALF(c.green());
+ dst->blue = UINT8_TO_HALF(c.blue());
+ dst->alpha = UINT8_TO_HALF(opacity);
+}
+
+void KisRgbF16HalfColorSpace::toTQColor(const TQ_UINT8 *srcU8, TQColor *c, KisProfile *)
+{
+ const Pixel *src = reinterpret_cast<const Pixel *>(srcU8);
+
+ c->setRgb(HALF_TO_UINT8(src->red), HALF_TO_UINT8(src->green), HALF_TO_UINT8(src->blue));
+}
+
+void KisRgbF16HalfColorSpace::toTQColor(const TQ_UINT8 *srcU8, TQColor *c, TQ_UINT8 *opacity, KisProfile *)
+{
+ const Pixel *src = reinterpret_cast<const Pixel *>(srcU8);
+
+ c->setRgb(HALF_TO_UINT8(src->red), HALF_TO_UINT8(src->green), HALF_TO_UINT8(src->blue));
+ *opacity = HALF_TO_UINT8(src->alpha);
+}
+
+TQ_UINT8 KisRgbF16HalfColorSpace::difference(const TQ_UINT8 *src1U8, const TQ_UINT8 *src2U8)
+{
+ const Pixel *src1 = reinterpret_cast<const Pixel *>(src1U8);
+ const Pixel *src2 = reinterpret_cast<const Pixel *>(src2U8);
+
+ return HALF_TO_UINT8(TQMAX(TQABS(src2->red - src1->red),
+ TQMAX(TQABS(src2->green - src1->green),
+ TQABS(src2->blue - src1->blue))));
+}
+
+void KisRgbF16HalfColorSpace::mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const
+{
+ half totalRed = 0, totalGreen = 0, totalBlue = 0, newAlpha = 0;
+
+ while (nColors--)
+ {
+ const Pixel *pixel = reinterpret_cast<const Pixel *>(*colors);
+
+ half alpha = pixel->alpha;
+ half alphaTimesWeight = alpha * UINT8_TO_HALF(*weights);
+
+ totalRed += pixel->red * alphaTimesWeight;
+ totalGreen += pixel->green * alphaTimesWeight;
+ totalBlue += pixel->blue * alphaTimesWeight;
+ newAlpha += alphaTimesWeight;
+
+ weights++;
+ colors++;
+ }
+
+ Q_ASSERT(newAlpha <= F16HALF_OPACITY_OPAQUE);
+
+ Pixel *dstPixel = reinterpret_cast<Pixel *>(dst);
+
+ dstPixel->alpha = newAlpha;
+
+ if (newAlpha > EPSILON) {
+ totalRed = totalRed / newAlpha;
+ totalGreen = totalGreen / newAlpha;
+ totalBlue = totalBlue / newAlpha;
+ }
+
+ dstPixel->red = totalRed;
+ dstPixel->green = totalGreen;
+ dstPixel->blue = totalBlue;
+}
+
+void KisRgbF16HalfColorSpace::convolveColors(TQ_UINT8** colors, TQ_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, TQ_UINT8 *dst, TQ_INT32 factor, TQ_INT32 offset, TQ_INT32 nColors) const
+{
+ half totalRed = 0, totalGreen = 0, totalBlue = 0, totalAlpha = 0;
+
+ while (nColors--)
+ {
+ const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
+
+ half weight = *kernelValues;
+
+ if (weight != 0) {
+ totalRed += pixel->red * UINT8_TO_HALF(weight);
+ totalGreen += pixel->green * UINT8_TO_HALF(weight);
+ totalBlue += pixel->blue * UINT8_TO_HALF(weight);
+ totalAlpha += pixel->alpha * UINT8_TO_HALF(weight);
+ }
+ colors++;
+ kernelValues++;
+ }
+
+ Pixel * p = reinterpret_cast< Pixel *>( dst );
+
+ if (channelFlags & KisChannelInfo::FLAG_COLOR) {
+ p->red = CLAMP( ( totalRed / factor) + offset, 0, HALF_MAX);
+ p->green = CLAMP( ( totalGreen / factor) + offset, 0, HALF_MAX);
+ p->blue = CLAMP( ( totalBlue / factor) + offset, 0, HALF_MAX);
+ }
+ if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
+ p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, HALF_MAX);
+ }
+}
+
+
+void KisRgbF16HalfColorSpace::invertColor(TQ_UINT8 * src, TQ_INT32 nPixels)
+{
+ TQ_UINT32 psize = pixelSize();
+
+ while (nPixels--)
+ {
+ Pixel * p = reinterpret_cast< Pixel *>( src );
+ p->red = 1.0 - p->red;
+ p->green = 1.0 - p->green;
+ p->blue = 1.0 - p->blue;
+ src += psize;
+ }
+
+}
+
+
+TQ_UINT8 KisRgbF16HalfColorSpace::intensity8(const TQ_UINT8 * src) const
+{
+ const Pixel * p = reinterpret_cast<const Pixel *>( src );
+
+ return HALF_TO_UINT8((p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) + 0.5);
+}
+
+
+TQValueVector<KisChannelInfo *> KisRgbF16HalfColorSpace::channels() const
+{
+ return m_channels;
+}
+
+TQ_UINT32 KisRgbF16HalfColorSpace::nChannels() const
+{
+ return MAX_CHANNEL_RGBA;
+}
+
+TQ_UINT32 KisRgbF16HalfColorSpace::nColorChannels() const
+{
+ return MAX_CHANNEL_RGB;
+}
+
+TQ_UINT32 KisRgbF16HalfColorSpace::pixelSize() const
+{
+ return MAX_CHANNEL_RGBA * sizeof(half);
+}
+
+TQ_UINT8 convertToDisplay(float value, float exposureFactor, float gamma)
+{
+ //value *= pow(2, exposure + 2.47393);
+ value *= exposureFactor;
+
+ value = powf(value, gamma);
+
+ // scale middle gray to the target framebuffer value
+
+ value *= 84.66f;
+
+ int valueInt = (int)(value + 0.5);
+
+ return CLAMP(valueInt, 0, 255);
+}
+
+TQImage KisRgbF16HalfColorSpace::convertToTQImage(const TQ_UINT8 *dataU8, TQ_INT32 width, TQ_INT32 height,
+ KisProfile * /*dstProfile*/,
+ TQ_INT32 /*renderingIntent*/, float exposure)
+
+{
+ const half *data = reinterpret_cast<const half *>(dataU8);
+
+ TQImage img = TQImage(width, height, 32, 0, TQImage::LittleEndian);
+ img.setAlphaBuffer(true);
+
+ TQ_INT32 i = 0;
+ uchar *j = img.bits();
+
+ // XXX: For now assume gamma 2.2.
+ float gamma = 1 / 2.2;
+ float exposureFactor = powf(2, exposure + 2.47393);
+
+ while ( i < width * height * MAX_CHANNEL_RGBA) {
+ *( j + 3) = HALF_TO_UINT8(*( data + i + PIXEL_ALPHA ));
+ *( j + 2 ) = convertToDisplay(*( data + i + PIXEL_RED ), exposureFactor, gamma);
+ *( j + 1 ) = convertToDisplay(*( data + i + PIXEL_GREEN ), exposureFactor, gamma);
+ *( j + 0 ) = convertToDisplay(*( data + i + PIXEL_BLUE ), exposureFactor, gamma);
+ i += MAX_CHANNEL_RGBA;
+ j += MAX_CHANNEL_RGBA;
+ }
+
+ /*
+ if (srcProfile != 0 && dstProfile != 0) {
+ convertPixelsTo(img.bits(), srcProfile,
+ img.bits(), this, dstProfile,
+ width * height, renderingIntent);
+ }
+ */
+ return img;
+}
+
+
+void KisRgbF16HalfColorSpace::compositeOver(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ while (rows > 0) {
+
+ const half *src = reinterpret_cast<const half *>(srcRowStart);
+ half *dst = reinterpret_cast<half *>(dstRowStart);
+ const TQ_UINT8 *tqmask = tqmaskRowStart;
+ TQ_INT32 columns = numColumns;
+
+ while (columns > 0) {
+
+ half srcAlpha = src[PIXEL_ALPHA];
+
+ // apply the alphatqmask
+ if (tqmask != 0) {
+ TQ_UINT8 U8_tqmask = *tqmask;
+
+ if (U8_tqmask != OPACITY_OPAQUE) {
+ srcAlpha *= UINT8_TO_HALF(U8_tqmask);
+ }
+ tqmask++;
+ }
+
+ if (srcAlpha > F16HALF_OPACITY_TRANSPARENT + EPSILON) {
+
+ if (opacity < F16HALF_OPACITY_OPAQUE - EPSILON) {
+ srcAlpha *= opacity;
+ }
+
+ if (srcAlpha > F16HALF_OPACITY_OPAQUE - EPSILON) {
+ memcpy(dst, src, MAX_CHANNEL_RGBA * sizeof(half));
+ } else {
+ half dstAlpha = dst[PIXEL_ALPHA];
+
+ half srcBlend;
+
+ if (dstAlpha > F16HALF_OPACITY_OPAQUE - EPSILON) {
+ srcBlend = srcAlpha;
+ } else {
+ half newAlpha = dstAlpha + (F16HALF_OPACITY_OPAQUE - dstAlpha) * srcAlpha;
+ dst[PIXEL_ALPHA] = newAlpha;
+
+ if (newAlpha > EPSILON) {
+ srcBlend = srcAlpha / newAlpha;
+ } else {
+ srcBlend = srcAlpha;
+ }
+ }
+
+ if (srcBlend > F16HALF_OPACITY_OPAQUE - EPSILON) {
+ memcpy(dst, src, MAX_CHANNEL_RGB * sizeof(half));
+ } else {
+ dst[PIXEL_RED] = HALF_BLEND(src[PIXEL_RED], dst[PIXEL_RED], srcBlend);
+ dst[PIXEL_GREEN] = HALF_BLEND(src[PIXEL_GREEN], dst[PIXEL_GREEN], srcBlend);
+ dst[PIXEL_BLUE] = HALF_BLEND(src[PIXEL_BLUE], dst[PIXEL_BLUE], srcBlend);
+ }
+ }
+ }
+
+ columns--;
+ src += MAX_CHANNEL_RGBA;
+ dst += MAX_CHANNEL_RGBA;
+ }
+
+ rows--;
+ srcRowStart += srcRowStride;
+ dstRowStart += dstRowStride;
+ if(tqmaskRowStart) {
+ tqmaskRowStart += tqmaskRowStride;
+ }
+ }
+}
+
+#define COMMON_COMPOSITE_OP_PROLOG() \
+ while (rows > 0) { \
+ \
+ const half *src = reinterpret_cast<const half *>(srcRowStart); \
+ half *dst = reinterpret_cast<half *>(dstRowStart); \
+ TQ_INT32 columns = numColumns; \
+ const TQ_UINT8 *tqmask = tqmaskRowStart; \
+ \
+ while (columns > 0) { \
+ \
+ half srcAlpha = src[PIXEL_ALPHA]; \
+ half dstAlpha = dst[PIXEL_ALPHA]; \
+ \
+ srcAlpha = TQMIN(srcAlpha, dstAlpha); \
+ \
+ if (tqmask != 0) { \
+ TQ_UINT8 U8_tqmask = *tqmask; \
+ \
+ if (U8_tqmask != OPACITY_OPAQUE) { \
+ srcAlpha *= UINT8_TO_HALF(U8_tqmask); \
+ } \
+ tqmask++; \
+ } \
+ \
+ if (srcAlpha > F16HALF_OPACITY_TRANSPARENT + EPSILON) { \
+ \
+ if (opacity < F16HALF_OPACITY_OPAQUE - EPSILON) { \
+ srcAlpha *= opacity; \
+ } \
+ \
+ half srcBlend; \
+ \
+ if (dstAlpha > F16HALF_OPACITY_OPAQUE - EPSILON) { \
+ srcBlend = srcAlpha; \
+ } else { \
+ half newAlpha = dstAlpha + (F16HALF_OPACITY_OPAQUE - dstAlpha) * srcAlpha; \
+ dst[PIXEL_ALPHA] = newAlpha; \
+ \
+ if (newAlpha > EPSILON) { \
+ srcBlend = srcAlpha / newAlpha; \
+ } else { \
+ srcBlend = srcAlpha; \
+ } \
+ }
+
+#define COMMON_COMPOSITE_OP_EPILOG() \
+ } \
+ \
+ columns--; \
+ src += MAX_CHANNEL_RGBA; \
+ dst += MAX_CHANNEL_RGBA; \
+ } \
+ \
+ rows--; \
+ srcRowStart += srcRowStride; \
+ dstRowStart += dstRowStride; \
+ if(tqmaskRowStart) { \
+ tqmaskRowStart += tqmaskRowStride; \
+ } \
+ }
+
+void KisRgbF16HalfColorSpace::compositeMultiply(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ half srcColor = src[PIXEL_RED];
+ half dstColor = dst[PIXEL_RED];
+
+ srcColor = srcColor * dstColor;
+
+ dst[PIXEL_RED] = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ srcColor = src[PIXEL_GREEN];
+ dstColor = dst[PIXEL_GREEN];
+
+ srcColor = srcColor * dstColor;
+
+ dst[PIXEL_GREEN] = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ srcColor = src[PIXEL_BLUE];
+ dstColor = dst[PIXEL_BLUE];
+
+ srcColor = srcColor * dstColor;
+
+ dst[PIXEL_BLUE] = HALF_BLEND(srcColor, dstColor, srcBlend);
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeDivide(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = TQMIN(dstColor / (srcColor + EPSILON), HALF_MAX);
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeScreen(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = HALF_MAX - ((HALF_MAX - dstColor) * (HALF_MAX - srcColor));
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeOverlay(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = dstColor * (dstColor + 2 * (srcColor * (HALF_MAX - dstColor)));
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeDodge(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = TQMIN(dstColor / (HALF_MAX + EPSILON - srcColor), HALF_MAX);
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeBurn(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = TQMIN((HALF_MAX - dstColor) / (srcColor + EPSILON), HALF_MAX);
+ srcColor = CLAMP(HALF_MAX - srcColor, 0, HALF_MAX);
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeDarken(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = TQMIN(srcColor, dstColor);
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeLighten(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ half srcColor = src[channel];
+ half dstColor = dst[channel];
+
+ srcColor = TQMAX(srcColor, dstColor);
+
+ half newColor = HALF_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeHue(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ float srcRed = src[PIXEL_RED];
+ float srcGreen = src[PIXEL_GREEN];
+ float srcBlue = src[PIXEL_BLUE];
+
+ float dstRed = dst[PIXEL_RED];
+ float dstGreen = dst[PIXEL_GREEN];
+ float dstBlue = dst[PIXEL_BLUE];
+
+ float srcHue;
+ float srcSaturation;
+ float srcValue;
+
+ float dstHue;
+ float dstSaturation;
+ float dstValue;
+
+ RGBToHSV(srcRed, srcGreen, srcBlue, &srcHue, &srcSaturation, &srcValue);
+ RGBToHSV(dstRed, dstGreen, dstBlue, &dstHue, &dstSaturation, &dstValue);
+
+ HSVToRGB(srcHue, dstSaturation, dstValue, &srcRed, &srcGreen, &srcBlue);
+
+ dst[PIXEL_RED] = FLOAT_BLEND(srcRed, dstRed, srcBlend);
+ dst[PIXEL_GREEN] = FLOAT_BLEND(srcGreen, dstGreen, srcBlend);
+ dst[PIXEL_BLUE] = FLOAT_BLEND(srcBlue, dstBlue, srcBlend);
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeSaturation(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ float srcRed = src[PIXEL_RED];
+ float srcGreen = src[PIXEL_GREEN];
+ float srcBlue = src[PIXEL_BLUE];
+
+ float dstRed = dst[PIXEL_RED];
+ float dstGreen = dst[PIXEL_GREEN];
+ float dstBlue = dst[PIXEL_BLUE];
+
+ float srcHue;
+ float srcSaturation;
+ float srcValue;
+
+ float dstHue;
+ float dstSaturation;
+ float dstValue;
+
+ RGBToHSV(srcRed, srcGreen, srcBlue, &srcHue, &srcSaturation, &srcValue);
+ RGBToHSV(dstRed, dstGreen, dstBlue, &dstHue, &dstSaturation, &dstValue);
+
+ HSVToRGB(dstHue, srcSaturation, dstValue, &srcRed, &srcGreen, &srcBlue);
+
+ dst[PIXEL_RED] = FLOAT_BLEND(srcRed, dstRed, srcBlend);
+ dst[PIXEL_GREEN] = FLOAT_BLEND(srcGreen, dstGreen, srcBlend);
+ dst[PIXEL_BLUE] = FLOAT_BLEND(srcBlue, dstBlue, srcBlend);
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeValue(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ float srcRed = src[PIXEL_RED];
+ float srcGreen = src[PIXEL_GREEN];
+ float srcBlue = src[PIXEL_BLUE];
+
+ float dstRed = dst[PIXEL_RED];
+ float dstGreen = dst[PIXEL_GREEN];
+ float dstBlue = dst[PIXEL_BLUE];
+
+ float srcHue;
+ float srcSaturation;
+ float srcValue;
+
+ float dstHue;
+ float dstSaturation;
+ float dstValue;
+
+ RGBToHSV(srcRed, srcGreen, srcBlue, &srcHue, &srcSaturation, &srcValue);
+ RGBToHSV(dstRed, dstGreen, dstBlue, &dstHue, &dstSaturation, &dstValue);
+
+ HSVToRGB(dstHue, dstSaturation, srcValue, &srcRed, &srcGreen, &srcBlue);
+
+ dst[PIXEL_RED] = FLOAT_BLEND(srcRed, dstRed, srcBlend);
+ dst[PIXEL_GREEN] = FLOAT_BLEND(srcGreen, dstGreen, srcBlend);
+ dst[PIXEL_BLUE] = FLOAT_BLEND(srcBlue, dstBlue, srcBlend);
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeColor(TQ_UINT8 *dstRowStart, TQ_INT32 dstRowStride, const TQ_UINT8 *srcRowStart, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmaskRowStart, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 numColumns, half opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ float srcRed = src[PIXEL_RED];
+ float srcGreen = src[PIXEL_GREEN];
+ float srcBlue = src[PIXEL_BLUE];
+
+ float dstRed = dst[PIXEL_RED];
+ float dstGreen = dst[PIXEL_GREEN];
+ float dstBlue = dst[PIXEL_BLUE];
+
+ float srcHue;
+ float srcSaturation;
+ float srcLightness;
+
+ float dstHue;
+ float dstSaturation;
+ float dstLightness;
+
+ RGBToHSL(srcRed, srcGreen, srcBlue, &srcHue, &srcSaturation, &srcLightness);
+ RGBToHSL(dstRed, dstGreen, dstBlue, &dstHue, &dstSaturation, &dstLightness);
+
+ HSLToRGB(srcHue, srcSaturation, dstLightness, &srcRed, &srcGreen, &srcBlue);
+
+ dst[PIXEL_RED] = FLOAT_BLEND(srcRed, dstRed, srcBlend);
+ dst[PIXEL_GREEN] = FLOAT_BLEND(srcGreen, dstGreen, srcBlend);
+ dst[PIXEL_BLUE] = FLOAT_BLEND(srcBlue, dstBlue, srcBlend);
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF16HalfColorSpace::compositeErase(TQ_UINT8 *dst,
+ TQ_INT32 dstRowSize,
+ const TQ_UINT8 *src,
+ TQ_INT32 srcRowSize,
+ const TQ_UINT8 *srcAlphaMask,
+ TQ_INT32 tqmaskRowStride,
+ TQ_INT32 rows,
+ TQ_INT32 cols,
+ half /*opacity*/)
+{
+ while (rows-- > 0)
+ {
+ const Pixel *s = reinterpret_cast<const Pixel *>(src);
+ Pixel *d = reinterpret_cast<Pixel *>(dst);
+ const TQ_UINT8 *tqmask = srcAlphaMask;
+
+ for (TQ_INT32 i = cols; i > 0; i--, s++, d++)
+ {
+ half srcAlpha = s->alpha;
+
+ // apply the alphatqmask
+ if (tqmask != 0) {
+ TQ_UINT8 U8_tqmask = *tqmask;
+
+ if (U8_tqmask != OPACITY_OPAQUE) {
+ srcAlpha = HALF_BLEND(srcAlpha, F16HALF_OPACITY_OPAQUE, UINT8_TO_HALF(U8_tqmask));
+ }
+ tqmask++;
+ }
+ d->alpha = srcAlpha * d->alpha;
+ }
+
+ dst += dstRowSize;
+ src += srcRowSize;
+ if(srcAlphaMask) {
+ srcAlphaMask += tqmaskRowStride;
+ }
+ }
+}
+
+void KisRgbF16HalfColorSpace::bitBlt(TQ_UINT8 *dst,
+ TQ_INT32 dstRowStride,
+ const TQ_UINT8 *src,
+ TQ_INT32 srcRowStride,
+ const TQ_UINT8 *tqmask,
+ TQ_INT32 tqmaskRowStride,
+ TQ_UINT8 U8_opacity,
+ TQ_INT32 rows,
+ TQ_INT32 cols,
+ const KisCompositeOp& op)
+{
+ half opacity = UINT8_TO_HALF(U8_opacity);
+
+ switch (op.op()) {
+ case COMPOSITE_UNDEF:
+ // Undefined == no composition
+ break;
+ case COMPOSITE_OVER:
+ compositeOver(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_IN:
+ //compositeIn(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ case COMPOSITE_OUT:
+ //compositeOut(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_ATOP:
+ //compositeAtop(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_XOR:
+ //compositeXor(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_PLUS:
+ //compositePlus(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_MINUS:
+ //compositeMinus(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_ADD:
+ //compositeAdd(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_SUBTRACT:
+ //compositeSubtract(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_DIFF:
+ //compositeDiff(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_MULT:
+ compositeMultiply(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_DIVIDE:
+ compositeDivide(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_BUMPMAP:
+ //compositeBumpmap(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COPY:
+ compositeCopy(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, U8_opacity);
+ break;
+ case COMPOSITE_COPY_RED:
+ //compositeCopyRed(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COPY_GREEN:
+ //compositeCopyGreen(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COPY_BLUE:
+ //compositeCopyBlue(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COPY_OPACITY:
+ //compositeCopyOpacity(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_CLEAR:
+ //compositeClear(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_DISSOLVE:
+ //compositeDissolve(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_DISPLACE:
+ //compositeDisplace(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+#if 0
+ case COMPOSITE_MODULATE:
+ compositeModulate(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_THRESHOLD:
+ compositeThreshold(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+#endif
+ case COMPOSITE_NO:
+ // No composition.
+ break;
+ case COMPOSITE_DARKEN:
+ compositeDarken(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_LIGHTEN:
+ compositeLighten(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_HUE:
+ compositeHue(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_SATURATION:
+ compositeSaturation(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_VALUE:
+ compositeValue(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COLOR:
+ compositeColor(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_COLORIZE:
+ //compositeColorize(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_LUMINIZE:
+ //compositeLuminize(pixelSize(), dst, dstRowStride, src, srcRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_SCREEN:
+ compositeScreen(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_OVERLAY:
+ compositeOverlay(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_ERASE:
+ compositeErase(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_DODGE:
+ compositeDodge(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_BURN:
+ compositeBurn(dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride, rows, cols, opacity);
+ break;
+ case COMPOSITE_ALPHA_DARKEN:
+ abstractCompositeAlphaDarken<half, F16HalfMult, Uint8ToF16Half, F16HalfOpacityTest,
+ PIXEL_ALPHA, MAX_CHANNEL_RGB, MAX_CHANNEL_RGBA>(
+ dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride,
+ rows, cols,
+ U8_opacity, F16HalfMult(), Uint8ToF16Half(), F16HalfOpacityTest());
+ break;
+ default:
+ break;
+ }
+}
+
+KisCompositeOpList KisRgbF16HalfColorSpace::userVisiblecompositeOps() const
+{
+ KisCompositeOpList list;
+
+ list.append(KisCompositeOp(COMPOSITE_OVER));
+ list.append(KisCompositeOp(COMPOSITE_ALPHA_DARKEN));
+ list.append(KisCompositeOp(COMPOSITE_MULT));
+ list.append(KisCompositeOp(COMPOSITE_BURN));
+ list.append(KisCompositeOp(COMPOSITE_DODGE));
+ list.append(KisCompositeOp(COMPOSITE_DIVIDE));
+ list.append(KisCompositeOp(COMPOSITE_SCREEN));
+ list.append(KisCompositeOp(COMPOSITE_OVERLAY));
+ list.append(KisCompositeOp(COMPOSITE_DARKEN));
+ list.append(KisCompositeOp(COMPOSITE_LIGHTEN));
+ list.append(KisCompositeOp(COMPOSITE_HUE));
+ list.append(KisCompositeOp(COMPOSITE_SATURATION));
+ list.append(KisCompositeOp(COMPOSITE_VALUE));
+ list.append(KisCompositeOp(COMPOSITE_COLOR));
+
+ return list;
+}
+
diff --git a/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.h b/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.h
new file mode 100644
index 00000000..a148a8f9
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2005 Adrian Page <[email protected]>
+ *
+ * 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 KIS_RGB_F16HALF_COLORSPACE_H_
+#define KIS_RGB_F16HALF_COLORSPACE_H_
+
+#include <tqcolor.h>
+
+#include <klocale.h>
+
+#include <koffice_export.h>
+
+#include "kis_global.h"
+#include "kis_f16half_base_colorspace.h"
+
+
+class KRITATOOL_EXPORT KisRgbF16HalfColorSpace : public KisF16HalfBaseColorSpace {
+public:
+ KisRgbF16HalfColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile *p);
+ virtual ~KisRgbF16HalfColorSpace();
+
+ virtual bool willDegrade(ColorSpaceIndependence independence)
+ {
+ if (independence == TO_RGBA8 || independence == TO_LAB16)
+ return true;
+ else
+ return false;
+ };
+
+
+public:
+ void setPixel(TQ_UINT8 *pixel, half red, half green, half blue, half alpha) const;
+ void getPixel(const TQ_UINT8 *pixel, half *red, half *green, half *blue, half *alpha) const;
+
+ virtual void fromTQColor(const TQColor& c, TQ_UINT8 *dst, KisProfile * profile = 0);
+ virtual void fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dst, KisProfile * profile = 0);
+
+ virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, KisProfile * profile = 0);
+ virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, TQ_UINT8 *opacity, KisProfile * profile = 0);
+
+ virtual TQ_UINT8 difference(const TQ_UINT8 *src1, const TQ_UINT8 *src2);
+ virtual void mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const;
+ virtual void invertColor(TQ_UINT8 * src, TQ_INT32 nPixels);
+ virtual void convolveColors(TQ_UINT8** colors, TQ_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, TQ_UINT8 *dst, TQ_INT32 factor, TQ_INT32 offset, TQ_INT32 nColors) const;
+ virtual TQ_UINT8 intensity8(const TQ_UINT8 * src) const;
+
+ virtual TQValueVector<KisChannelInfo *> channels() const;
+ virtual TQ_UINT32 nChannels() const;
+ virtual TQ_UINT32 nColorChannels() const;
+ virtual TQ_UINT32 pixelSize() const;
+
+ virtual TQImage convertToTQImage(const TQ_UINT8 *data, TQ_INT32 width, TQ_INT32 height,
+ KisProfile * dstProfile,
+ TQ_INT32 renderingIntent,
+ float exposure = 0.0f);
+
+ virtual KisCompositeOpList userVisiblecompositeOps() const;
+
+
+protected:
+
+ virtual void bitBlt(TQ_UINT8 *dst,
+ TQ_INT32 dstRowStride,
+ const TQ_UINT8 *src,
+ TQ_INT32 srcRowStride,
+ const TQ_UINT8 *srcAlphaMask,
+ TQ_INT32 tqmaskRowStride,
+ TQ_UINT8 opacity,
+ TQ_INT32 rows,
+ TQ_INT32 cols,
+ const KisCompositeOp& op);
+
+ void compositeOver(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeMultiply(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeDivide(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeScreen(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeOverlay(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeDodge(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeBurn(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeDarken(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeLighten(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeHue(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeSaturation(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeValue(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeColor(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+ void compositeErase(TQ_UINT8 *dst, TQ_INT32 dstRowStride, const TQ_UINT8 *src, TQ_INT32 srcRowStride, const TQ_UINT8 *tqmask, TQ_INT32 tqmaskRowStride, TQ_INT32 rows, TQ_INT32 columns, half opacity);
+
+private:
+ friend class KisRgbF16HalfColorSpaceTester;
+
+ static const TQ_UINT8 PIXEL_BLUE = 0;
+ static const TQ_UINT8 PIXEL_GREEN = 1;
+ static const TQ_UINT8 PIXEL_RED = 2;
+ static const TQ_UINT8 PIXEL_ALPHA = 3;
+
+ struct Pixel {
+ half blue;
+ half green;
+ half red;
+ half alpha;
+ };
+};
+
+// FIXME: lcms doesn't support 16-bit float
+#define RGBAF16HALF_LCMS_TYPE TYPE_BGRA_16
+
+class KisRgbF16HalfColorSpaceFactory : public KisColorSpaceFactory
+{
+public:
+ /**
+ * Chalk definition for use in .kra files and internally: unchanging name +
+ * i18n'able description.
+ */
+ virtual KisID id() const { return KisID("RGBAF16HALF", i18n("RGB (16-bit float/channel)")); };
+
+ /**
+ * lcms colorspace type definition.
+ */
+ virtual TQ_UINT32 colorSpaceType() { return RGBAF16HALF_LCMS_TYPE; };
+
+ virtual icColorSpaceSignature colorSpaceSignature() { return icSigRgbData; };
+
+ virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile *p) { return new KisRgbF16HalfColorSpace(tqparent, p); };
+
+ virtual TQString defaultProfile() { return "sRGB built-in - (lcms internal)"; };
+};
+
+#endif // KIS_RGB_F16HALF_COLORSPACE_H_
+
diff --git a/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc
new file mode 100644
index 00000000..f50672b9
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc
@@ -0,0 +1,63 @@
+/*
+* rgb_f32_plugin.cc -- Part of Chalk
+*
+* Copyright (c) 2004 Boudewijn Rempt ([email protected])
+* Copyright (c) 2005 Adrian Page <[email protected]>
+*
+* 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 <kinstance.h>
+#include <kgenericfactory.h>
+#include <kdebug.h>
+
+#include <kis_debug_areas.h>
+#include <kis_colorspace_factory_registry.h>
+#include <kis_basic_histogram_producers.h>
+
+#include "rgb_f16half_plugin.h"
+#include "kis_rgb_f16half_colorspace.h"
+
+typedef KGenericFactory<RGBF16HalfPlugin> RGBF16HalfPluginFactory;
+K_EXPORT_COMPONENT_FACTORY( chalk_rgb_f16half_plugin, RGBF16HalfPluginFactory( "chalk" ) )
+
+
+RGBF16HalfPlugin::RGBF16HalfPlugin(TQObject *tqparent, const char *name, const TQStringList &)
+ : KParts::Plugin(tqparent, name)
+{
+ setInstance(RGBF16HalfPluginFactory::instance());
+
+ if ( tqparent->inherits("KisColorSpaceFactoryRegistry") )
+ {
+ KisColorSpaceFactoryRegistry * f = dynamic_cast<KisColorSpaceFactoryRegistry*>( tqparent );
+
+ KisColorSpace * colorSpaceRGBF16Half = new KisRgbF16HalfColorSpace(f, 0);
+ KisColorSpaceFactory *csf = new KisRgbF16HalfColorSpaceFactory();
+ Q_CHECK_PTR(colorSpaceRGBF16Half);
+ f->add(csf);
+ KisHistogramProducerFactoryRegistry::instance()->add(
+ new KisBasicHistogramProducerFactory<KisBasicF16HalfHistogramProducer>
+ (KisID("RGBF16HALFHISTO", i18n("Float16 Half")), colorSpaceRGBF16Half) );
+ }
+
+}
+
+RGBF16HalfPlugin::~RGBF16HalfPlugin()
+{
+}
+
+#include "rgb_f16half_plugin.moc"
+
diff --git a/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.h b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.h
new file mode 100644
index 00000000..a970247c
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2003 Boudewijn Rempt ([email protected])
+ *
+ * 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 RGB_F16HALF_PLUGIN_H_
+#define RGB_F16HALF_PLUGIN_H_
+
+#include <kparts/plugin.h>
+
+/**
+ * A plugin wrapper around the RGB F16Half colour space strategy.
+ */
+class RGBF16HalfPlugin : public KParts::Plugin
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ RGBF16HalfPlugin(TQObject *tqparent, const char *name, const TQStringList &);
+ virtual ~RGBF16HalfPlugin();
+
+};
+
+
+#endif // RGB_F16HALF_PLUGIN_H_
diff --git a/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.rc b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.rc
new file mode 100644
index 00000000..125060ae
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.rc
@@ -0,0 +1,9 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui library="chalk_rgb_f16half_plugin" version="1">
+<Menu name="Image"><text>&amp;Image</text>
+ <Menu name="Mode"><text>&amp;Mode</text>
+ <Action name="convert to RGB(A) (16-bit float 'half')"/>
+ </Menu>
+</Menu>
+
+</kpartgui>
diff --git a/chalk/colorspaces/rgb_f16half/tests/Makefile.am b/chalk/colorspaces/rgb_f16half/tests/Makefile.am
new file mode 100644
index 00000000..284359ee
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/tests/Makefile.am
@@ -0,0 +1,19 @@
+AM_CPPFLAGS = -I$(srcdir)/.. \
+ -I$(srcdir)/../../../sdk \
+ -I$(srcdir)/../../../chalkcolor/color_strategy/ \
+ -I$(srcdir)/../../../color_strategy/ \
+ -I$(srcdir)/../../../modules/rgb_f32 \
+ $(OPENEXR_CFLAGS) \
+ $(all_includes)
+
+# The check_ target makes sure we don't install the modules,
+# $(KDE_CHECK_PLUGIN) assures a shared library is created.
+check_LTLIBRARIES = kunittest_kis_rgb_f16half_colorspace_tester.la
+
+kunittest_kis_rgb_f16half_colorspace_tester_la_SOURCES = kis_rgb_f16half_colorspace_tester.cc
+kunittest_kis_rgb_f16half_colorspace_tester_la_LIBADD = -lkunittest ../libchalk_rgb_f16half.la
+kunittest_kis_rgb_f16half_colorspace_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries)
+
+check-local: kunittest_kis_rgb_f16half_colorspace_tester.la
+ kunittestmodrunner
+
diff --git a/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cc b/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cc
new file mode 100644
index 00000000..59eb8e5f
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cc
@@ -0,0 +1,545 @@
+/*
+ * Copyright (c) 2005 Adrian Page <[email protected]>
+ *
+ * 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 <kunittest/runner.h>
+#include <kunittest/module.h>
+
+#include "kis_factory.h"
+#include "kis_rgb_f16half_colorspace.h"
+#include "kis_rgb_f16half_colorspace_tester.h"
+#include "kis_rgb_f32_colorspace.h"
+#include "kis_integer_maths.h"
+#include "kis_paint_device.h"
+
+using namespace KUnitTest;
+
+KUNITTEST_MODULE( kunittest_kis_rgb_f16half_colorspace_tester, "RGBA 16-bit float half colorspace tester" );
+KUNITTEST_MODULE_REGISTER_TESTER( KisRgbF16HalfColorSpaceTester );
+
+#define PIXEL_BLUE 0
+#define PIXEL_GREEN 1
+#define PIXEL_RED 2
+#define PIXEL_ALPHA 3
+
+#define NUM_CHANNELS 4
+#define NUM_COLOUR_CHANNELS 3
+#define CHANNEL_SIZE ((int)sizeof(half))
+
+#define RED_CHANNEL 0
+#define GREEN_CHANNEL 1
+#define BLUE_CHANNEL 2
+#define ALPHA_CHANNEL 3
+
+//#define MAX_CHANNEL_VALUE 1.0f
+//#define MIN_CHANNEL_VALUE 0.0f
+
+#define CHANNEL_VALUE_ZERO ((half)0)
+#define CHANNEL_VALUE_ONE ((half)1)
+
+void KisRgbF16HalfColorSpaceTester::allTests()
+{
+ // We need this so that the colour profile loading can operate without crashing.
+ KisFactory *factory = new KisFactory();
+
+ testBasics();
+ testToTQImage();
+ testCompositeOps();
+ testMixColors();
+
+ delete factory;
+}
+
+void KisRgbF16HalfColorSpaceTester::testBasics()
+{
+
+
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisRgbF16HalfColorSpace *cs = new KisRgbF16HalfColorSpace(profile);
+ KisAbstractColorSpace * csSP = cs;
+
+ CHECK(cs->hasAlpha(), true);
+ CHECK(cs->nChannels(), NUM_CHANNELS);
+ CHECK(cs->nColorChannels(), NUM_COLOUR_CHANNELS);
+ CHECK(cs->pixelSize(), NUM_CHANNELS * CHANNEL_SIZE);
+
+ TQValueVector<KisChannelInfo *> channels = cs->channels();
+
+ // Red
+ CHECK(channels[0]->pos(), PIXEL_RED * CHANNEL_SIZE);
+ CHECK(channels[0]->size(), CHANNEL_SIZE);
+ CHECK(channels[0]->channelType(), COLOR);
+
+ // Green
+ CHECK(channels[1]->pos(), PIXEL_GREEN * CHANNEL_SIZE);
+ CHECK(channels[1]->size(), CHANNEL_SIZE);
+ CHECK(channels[1]->channelType(), COLOR);
+
+ // Blue
+ CHECK(channels[2]->pos(), PIXEL_BLUE * CHANNEL_SIZE);
+ CHECK(channels[2]->size(), CHANNEL_SIZE);
+ CHECK(channels[2]->channelType(), COLOR);
+
+ // Alpha
+ CHECK(channels[3]->pos(), PIXEL_ALPHA * CHANNEL_SIZE);
+ CHECK(channels[3]->size(), CHANNEL_SIZE);
+ CHECK(channels[3]->channelType(), ALPHA);
+
+ KisPaintDeviceSP pd = new KisPaintDevice(cs, "test");
+
+ KisRgbF16HalfColorSpace::Pixel defaultPixel;
+
+ memcpy(&defaultPixel, pd->dataManager()->defaultPixel(), sizeof(defaultPixel));
+
+ CHECK(defaultPixel.red, CHANNEL_VALUE_ZERO);
+ CHECK(defaultPixel.green, CHANNEL_VALUE_ZERO);
+ CHECK(defaultPixel.blue, CHANNEL_VALUE_ZERO);
+ CHECK(defaultPixel.alpha, F16HALF_OPACITY_TRANSPARENT);
+
+ half pixel[NUM_CHANNELS];
+
+ cs->fromTQColor(tqRgb(255, 255, 255), reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+
+ cs->fromTQColor(tqRgb(0, 0, 0), reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], CHANNEL_VALUE_ZERO);
+ CHECK(pixel[PIXEL_GREEN], CHANNEL_VALUE_ZERO);
+ CHECK(pixel[PIXEL_BLUE], CHANNEL_VALUE_ZERO);
+
+ cs->fromTQColor(tqRgb(128, 64, 192), reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], UINT8_TO_HALF(128));
+ CHECK(pixel[PIXEL_GREEN], UINT8_TO_HALF(64));
+ CHECK(pixel[PIXEL_BLUE], UINT8_TO_HALF(192));
+
+ cs->fromTQColor(tqRgb(255, 255, 255), OPACITY_OPAQUE, reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_ALPHA], CHANNEL_VALUE_ONE);
+
+ cs->fromTQColor(tqRgb(255, 255, 255), OPACITY_TRANSPARENT, reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_ALPHA], F16HALF_OPACITY_TRANSPARENT);
+
+ cs->fromTQColor(tqRgb(255, 255, 255), OPACITY_OPAQUE / 2, reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+ CHECK(pixel[PIXEL_ALPHA], UINT8_TO_HALF(OPACITY_OPAQUE / 2));
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ONE;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ONE;
+ pixel[PIXEL_BLUE] = CHANNEL_VALUE_ONE;
+
+ TQColor c;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c);
+
+ CHECK(c.red(), 255);
+ CHECK(c.green(), 255);
+ CHECK(c.blue(), 255);
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ZERO;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ZERO;
+ pixel[PIXEL_BLUE] = CHANNEL_VALUE_ZERO;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c);
+
+ CHECK(c.red(), 0);
+ CHECK(c.green(), 0);
+ CHECK(c.blue(), 0);
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ONE / 4;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ONE / 2;
+ pixel[PIXEL_BLUE] = (3 * CHANNEL_VALUE_ONE) / 4;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c);
+
+ CHECK(c.red(), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 4));
+ CHECK(c.green(), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 2));
+ CHECK(c.blue(), (int)HALF_TO_UINT8((3 * CHANNEL_VALUE_ONE) / 4));
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ONE;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ONE;
+ pixel[PIXEL_BLUE] = CHANNEL_VALUE_ONE;
+ pixel[PIXEL_ALPHA] = CHANNEL_VALUE_ONE;
+
+ TQ_UINT8 opacity;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c, &opacity);
+
+ CHECK(c.red(), 255);
+ CHECK(c.green(), 255);
+ CHECK(c.blue(), 255);
+ CHECK(opacity, OPACITY_OPAQUE);
+
+ pixel[PIXEL_ALPHA] = F16HALF_OPACITY_OPAQUE;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c, &opacity);
+
+ CHECK(c.red(), 255);
+ CHECK(c.green(), 255);
+ CHECK(c.blue(), 255);
+ CHECK(opacity, OPACITY_OPAQUE);
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ZERO;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ZERO;
+ pixel[PIXEL_BLUE] = CHANNEL_VALUE_ZERO;
+ pixel[PIXEL_ALPHA] = F16HALF_OPACITY_TRANSPARENT;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c, &opacity);
+
+ CHECK(c.red(), 0);
+ CHECK(c.green(), 0);
+ CHECK(c.blue(), 0);
+ CHECK(opacity, OPACITY_TRANSPARENT);
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ONE / 4;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ONE / 2;
+ pixel[PIXEL_BLUE] = (3 * CHANNEL_VALUE_ONE) / 4;
+ pixel[PIXEL_ALPHA] = CHANNEL_VALUE_ONE / 2;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c, &opacity);
+
+ CHECK(c.red(), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 4));
+ CHECK(c.green(), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 2));
+ CHECK(c.blue(), (int)HALF_TO_UINT8((3 * CHANNEL_VALUE_ONE) / 4));
+ CHECK((int)opacity, (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 2));
+
+ #define NUM_PIXELS 4
+
+ KisRgbF16HalfColorSpace::Pixel pixels[NUM_PIXELS] = {
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE / 4},
+ {CHANNEL_VALUE_ONE / 4, CHANNEL_VALUE_ONE / 2, CHANNEL_VALUE_ONE / 3, CHANNEL_VALUE_ONE / 2},
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ZERO},
+ {CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ONE}
+ };
+
+ cs->setAlpha(reinterpret_cast<TQ_UINT8 *>(pixels), OPACITY_OPAQUE / 2, NUM_PIXELS);
+
+ CHECK(pixels[0].red, CHANNEL_VALUE_ONE);
+ CHECK(pixels[0].green, CHANNEL_VALUE_ONE);
+ CHECK(pixels[0].blue, CHANNEL_VALUE_ONE);
+ CHECK(pixels[0].alpha, UINT8_TO_HALF(OPACITY_OPAQUE / 2));
+
+ CHECK(pixels[1].red, (half)(CHANNEL_VALUE_ONE / 3));
+ CHECK(pixels[1].green, (half)(CHANNEL_VALUE_ONE / 2));
+ CHECK(pixels[1].blue, (half)(CHANNEL_VALUE_ONE / 4));
+ CHECK(pixels[1].alpha, UINT8_TO_HALF(OPACITY_OPAQUE / 2));
+
+ CHECK(pixels[2].red, CHANNEL_VALUE_ONE);
+ CHECK(pixels[2].green, CHANNEL_VALUE_ONE);
+ CHECK(pixels[2].blue, CHANNEL_VALUE_ONE);
+ CHECK(pixels[2].alpha, UINT8_TO_HALF(OPACITY_OPAQUE / 2));
+
+ CHECK(pixels[3].red, CHANNEL_VALUE_ZERO);
+ CHECK(pixels[3].green, CHANNEL_VALUE_ZERO);
+ CHECK(pixels[3].blue, CHANNEL_VALUE_ZERO);
+ CHECK(pixels[3].alpha, UINT8_TO_HALF(OPACITY_OPAQUE / 2));
+
+ pixel[PIXEL_RED] = CHANNEL_VALUE_ONE;
+ pixel[PIXEL_GREEN] = CHANNEL_VALUE_ONE / 2;
+ pixel[PIXEL_BLUE] = CHANNEL_VALUE_ONE / 4;
+ pixel[PIXEL_ALPHA] = CHANNEL_VALUE_ZERO;
+
+ TQString valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), RED_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ONE));
+
+ valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), GREEN_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ONE / 2));
+
+ valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), BLUE_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ONE / 4));
+
+ valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), ALPHA_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ZERO));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), RED_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ONE));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), GREEN_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ONE / 2));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), BLUE_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ONE / 4));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), ALPHA_CHANNEL);
+ CHECK(valueText, TQString().setNum(CHANNEL_VALUE_ZERO));
+
+ cs->setPixel(reinterpret_cast<TQ_UINT8 *>(pixel), 0.128, 0.192, 0.64, 0.99);
+ CHECK(pixel[PIXEL_RED], (half)0.128f);
+ CHECK(pixel[PIXEL_GREEN], (half)0.192f);
+ CHECK(pixel[PIXEL_BLUE], (half)0.64f);
+ CHECK(pixel[PIXEL_ALPHA], (half)0.99f);
+
+ half red;
+ half green;
+ half blue;
+ half alpha;
+
+ cs->getPixel(reinterpret_cast<const TQ_UINT8 *>(pixel), &red, &green, &blue, &alpha);
+ CHECK(red, (half)0.128f);
+ CHECK(green, (half)0.192f);
+ CHECK(blue, (half)0.64f);
+ CHECK(alpha, (half)0.99f);
+
+ CHECK(HALF_TO_UINT8(-0.5), 0u);
+ CHECK(HALF_TO_UINT8(0), 0u);
+ CHECK_TOLERANCE(HALF_TO_UINT8(0.5), UINT8_MAX / 2, 1u);
+ CHECK(HALF_TO_UINT8(1), UINT8_MAX);
+ CHECK(HALF_TO_UINT8(1.5), UINT8_MAX);
+
+ CHECK(HALF_TO_UINT16(-0.5), 0u);
+ CHECK(HALF_TO_UINT16(0), 0u);
+ CHECK_TOLERANCE(HALF_TO_UINT16(0.5), UINT16_MAX / 2, 1u);
+ CHECK(HALF_TO_UINT16(1), UINT16_MAX);
+ CHECK(HALF_TO_UINT16(1.5), UINT16_MAX);
+}
+
+void KisRgbF16HalfColorSpaceTester::testMixColors()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+ KisAbstractColorSpace * cs = new KisRgbF16HalfColorSpace(profile);
+
+ // Test mixColors.
+ half pixel1[NUM_CHANNELS];
+ half pixel2[NUM_CHANNELS];
+ half outputPixel[NUM_CHANNELS];
+
+ outputPixel[PIXEL_RED] = 0;
+ outputPixel[PIXEL_GREEN] = 0;
+ outputPixel[PIXEL_BLUE] = 0;
+ outputPixel[PIXEL_ALPHA] = 0;
+
+ pixel1[PIXEL_RED] = CHANNEL_VALUE_ONE;
+ pixel1[PIXEL_GREEN] = CHANNEL_VALUE_ONE;
+ pixel1[PIXEL_BLUE] = CHANNEL_VALUE_ONE;
+ pixel1[PIXEL_ALPHA] = CHANNEL_VALUE_ONE;
+
+ pixel2[PIXEL_RED] = 0;
+ pixel2[PIXEL_GREEN] = 0;
+ pixel2[PIXEL_BLUE] = 0;
+ pixel2[PIXEL_ALPHA] = 0;
+
+ const TQ_UINT8 *pixelPtrs[2];
+ TQ_UINT8 weights[2];
+
+ pixelPtrs[0] = reinterpret_cast<const TQ_UINT8 *>(pixel1);
+ pixelPtrs[1] = reinterpret_cast<const TQ_UINT8 *>(pixel2);
+
+ weights[0] = 255;
+ weights[1] = 0;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_ALPHA], CHANNEL_VALUE_ONE);
+
+ weights[0] = 0;
+ weights[1] = 255;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], (half)0.0f);
+ CHECK(outputPixel[PIXEL_GREEN], (half)0.0f);
+ CHECK(outputPixel[PIXEL_BLUE], (half)0.0f);
+ CHECK(outputPixel[PIXEL_ALPHA], (half)0.0f);
+
+ weights[0] = 128;
+ weights[1] = 127;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_ALPHA], (half)((128 * CHANNEL_VALUE_ONE) / 255));
+
+ pixel1[PIXEL_RED] = 20000;
+ pixel1[PIXEL_GREEN] = 10000;
+ pixel1[PIXEL_BLUE] = 5000;
+ pixel1[PIXEL_ALPHA] = CHANNEL_VALUE_ONE;
+
+ pixel2[PIXEL_RED] = 10000;
+ pixel2[PIXEL_GREEN] = 20000;
+ pixel2[PIXEL_BLUE] = 2000;
+ pixel2[PIXEL_ALPHA] = CHANNEL_VALUE_ONE;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK_TOLERANCE(outputPixel[PIXEL_RED], (128 * 20000 + 127 * 10000) / 255, 5);
+ CHECK_TOLERANCE(outputPixel[PIXEL_GREEN], (128 * 10000 + 127 * 20000) / 255, 5);
+ CHECK_TOLERANCE(outputPixel[PIXEL_BLUE], (128 * 5000 + 127 * 2000) / 255, 5);
+ CHECK(outputPixel[PIXEL_ALPHA], CHANNEL_VALUE_ONE);
+
+ pixel1[PIXEL_RED] = 0;
+ pixel1[PIXEL_GREEN] = 0;
+ pixel1[PIXEL_BLUE] = 0;
+ pixel1[PIXEL_ALPHA] = 0;
+
+ pixel2[PIXEL_RED] = CHANNEL_VALUE_ONE;
+ pixel2[PIXEL_GREEN] = CHANNEL_VALUE_ONE;
+ pixel2[PIXEL_BLUE] = CHANNEL_VALUE_ONE;
+ pixel2[PIXEL_ALPHA] = CHANNEL_VALUE_ONE;
+
+ weights[0] = 89;
+ weights[1] = 166;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_GREEN], CHANNEL_VALUE_ONE);
+ CHECK(outputPixel[PIXEL_BLUE], CHANNEL_VALUE_ONE);
+ CHECK_TOLERANCE(outputPixel[PIXEL_ALPHA], (89 * 0 + 166 * CHANNEL_VALUE_ONE) / 255, 5);
+}
+
+#define PIXELS_WIDTH 2
+#define PIXELS_HEIGHT 2
+
+void KisRgbF16HalfColorSpaceTester::testToTQImage()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisAbstractColorSpace * cs = new KisRgbF16HalfColorSpace(profile);
+
+ KisRgbF16HalfColorSpace::Pixel pixels[PIXELS_WIDTH * PIXELS_HEIGHT] = {
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE / 4},
+ {CHANNEL_VALUE_ONE / 4, CHANNEL_VALUE_ONE / 2, CHANNEL_VALUE_ONE / 3, CHANNEL_VALUE_ONE / 2},
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ZERO},
+ {CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ONE}
+ };
+
+ TQImage image = cs->convertToTQImage(reinterpret_cast<const TQ_UINT8 *>(pixels), PIXELS_WIDTH, PIXELS_HEIGHT, 0, 0);
+
+ TQRgb c = image.pixel(0, 0);
+
+ // Exposure comes into play here.
+ /*
+ CHECK(tqRed(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ CHECK(tqGreen(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ CHECK(tqBlue(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ CHECK(tqAlpha(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 4));
+
+ c = image.pixel(1, 0);
+
+ CHECK(tqRed(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 3));
+ CHECK(tqGreen(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 2));
+ CHECK(tqBlue(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 4));
+ CHECK(tqAlpha(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE / 2));
+
+ c = image.pixel(0, 1);
+
+ CHECK(tqRed(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ CHECK(tqGreen(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ CHECK(tqBlue(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ CHECK(tqAlpha(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ZERO));
+
+ c = image.pixel(1, 1);
+
+ CHECK(tqRed(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ZERO));
+ CHECK(tqGreen(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ZERO));
+ CHECK(tqBlue(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ZERO));
+ CHECK(tqAlpha(c), (int)HALF_TO_UINT8(CHANNEL_VALUE_ONE));
+ */
+}
+
+#define NUM_ROWS 2
+#define NUM_COLUMNS 2
+#define SRC_ROW_STRIDE (NUM_COLUMNS * CHANNEL_SIZE)
+#define DST_ROW_STRIDE (NUM_COLUMNS * CHANNEL_SIZE)
+#define MASK_ROW_STRIDE NUM_COLUMNS
+
+/*
+1 alpha 1 0 alpha 1
+1 alpha 0.5 0 alpha 1
+1 alpha 0.5 0 alpha 0.5
+1 alpha 0 0 alpha 0.5
+
+*/
+
+void KisRgbF16HalfColorSpaceTester::testCompositeOps()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisRgbF16HalfColorSpace *cs = new KisRgbF16HalfColorSpace(profile);
+
+ KisRgbF16HalfColorSpace::Pixel srcPixel;
+ KisRgbF16HalfColorSpace::Pixel dstPixel;
+
+ srcPixel.red = UINT8_TO_HALF(102);
+ srcPixel.green = UINT8_TO_HALF(170);
+ srcPixel.blue = UINT8_TO_HALF(238);
+ srcPixel.alpha = F16HALF_OPACITY_OPAQUE;
+
+ dstPixel = srcPixel;
+
+ cs->compositeDivide(reinterpret_cast<TQ_UINT8 *>(&dstPixel), 1, reinterpret_cast<const TQ_UINT8 *>(&srcPixel),
+ 1, 0, 0, 1, 1, F16HALF_OPACITY_OPAQUE);
+ /*
+ CHECK(dstPixel.red, (TQ_UINT16)UINT8_TO_UINT16(253));
+ CHECK(dstPixel.green, (TQ_UINT16)UINT8_TO_UINT16(254));
+ CHECK(dstPixel.blue, (TQ_UINT16)UINT8_TO_UINT16(254));
+ CHECK(dstPixel.alpha, KisRgbF16HalfColorSpace::F16HALF_OPACITY_OPAQUE);
+
+ TQ_UINT16 srcColor = 43690;
+ TQ_UINT16 dstColor = 43690;
+
+ srcColor = TQMIN((dstColor * (65535u + 1u) + (srcColor / 2u)) / (1u + srcColor), 65535u);
+
+ CHECK((int)srcColor, 65534);
+
+ TQ_UINT16 newColor = UINT16_BLEND(srcColor, dstColor, 65535u);
+
+ CHECK((int)newColor, 65534);
+ */
+
+ /*
+ KisRgbF16HalfColorSpace::Pixel srcPixels[NUM_ROWS * NUM_COLUMNS] = {
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE / 4},
+ {CHANNEL_VALUE_ONE / 4, CHANNEL_VALUE_ONE / 2, CHANNEL_VALUE_ONE / 3, CHANNEL_VALUE_ONE / 2},
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ZERO},
+ {CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ONE}
+ };
+
+ KisRgbF16HalfColorSpace::Pixel dstPixels[NUM_ROWS * NUM_COLUMNS] = {
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE / 4},
+ {CHANNEL_VALUE_ONE / 4, CHANNEL_VALUE_ONE / 2, CHANNEL_VALUE_ONE / 3, CHANNEL_VALUE_ONE / 2},
+ {CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ONE, CHANNEL_VALUE_ZERO},
+ {CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ZERO, CHANNEL_VALUE_ONE}
+ };
+
+ cs->compositeOver(reinterpret_cast<TQ_UINT8 *>(dstPixels), DST_ROW_STRIDE, reinterpret_cast<const TQ_UINT8 *>(srcPixels),
+ SRC_ROW_STRIDE, tqmask, MASK_ROW_STRIDE, NUM_ROWS, NUM_COLUMNS, opacity);
+ */
+
+ delete cs;
+}
+
diff --git a/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.h b/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.h
new file mode 100644
index 00000000..6547e35b
--- /dev/null
+++ b/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2005 Adrian Page <[email protected]>
+ *
+ * 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 KIS_RGB_F16HALF_COLORSPACE_TESTER_H
+#define KIS_RGB_F16HALF_COLORSPACE_TESTER_H
+
+#include <kunittest/tester.h>
+
+#define CHECK_TOLERANCE( x, y, tolerance ) \
+if ((x) <= (y) + (tolerance) && (x) >= (y) - (tolerance)) \
+{ \
+ success(TQString(__FILE__) + "[" + TQString::number(__LINE__) + "]: passed " + #x); \
+} \
+else \
+{ \
+ failure(TQString(__FILE__) + "[" + TQString::number(__LINE__) + TQString("]: failed ") + #x + "\n Expected " + #y + ", Actual result " + TQString::number(x)); \
+} \
+
+class KisRgbF16HalfColorSpaceTester : public KUnitTest::Tester
+{
+public:
+ void allTests();
+ void testBasics();
+ void testMixColors();
+ void testToTQImage();
+ void testCompositeOps();
+};
+
+#endif
+