summaryrefslogtreecommitdiffstats
path: root/chalk/colorspaces/rgb_f32
diff options
context:
space:
mode:
Diffstat (limited to 'chalk/colorspaces/rgb_f32')
-rw-r--r--chalk/colorspaces/rgb_f32/Makefile.am34
-rw-r--r--chalk/colorspaces/rgb_f32/chalk_rgb_f32_plugin.desktop77
-rw-r--r--chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cc949
-rw-r--r--chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h165
-rw-r--r--chalk/colorspaces/rgb_f32/rgb_f32_plugin.cc63
-rw-r--r--chalk/colorspaces/rgb_f32/rgb_f32_plugin.h39
-rw-r--r--chalk/colorspaces/rgb_f32/rgb_f32_plugin.rc9
-rw-r--r--chalk/colorspaces/rgb_f32/tests/Makefile.am17
-rw-r--r--chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cc541
-rw-r--r--chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.h47
10 files changed, 1941 insertions, 0 deletions
diff --git a/chalk/colorspaces/rgb_f32/Makefile.am b/chalk/colorspaces/rgb_f32/Makefile.am
new file mode 100644
index 00000000..edcf26a9
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/Makefile.am
@@ -0,0 +1,34 @@
+# Install the desktop file needed to detect the plugin
+kde_services_DATA = chalk_rgb_f32_plugin.desktop
+
+INCLUDES = \
+ -I$(srcdir)/../../sdk \
+ -I$(srcdir)/../../chalkcolor/color_strategy/ \
+ -I$(srcdir)/../../chalkcolor/ \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+
+lib_LTLIBRARIES = libchalk_rgb_f32.la
+libchalk_rgb_f32_la_SOURCES = kis_rgb_f32_colorspace.cc
+libchalk_rgb_f32_la_LDFLAGS = $(all_libraries)
+libchalk_rgb_f32_la_LIBADD = ../../chalkcolor/libchalkcolor.la
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = chalk_rgb_f32_plugin.la
+
+# Srcs for the plugin
+chalk_rgb_f32_plugin_la_SOURCES = rgb_f32_plugin.cc
+noinst_HEADERS = rgb_f32_plugin.h kis_rgb_f32_colorspace.h
+
+chalk_rgb_f32_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) -lkdecore -lkdeui -lkjs -lkdefx -lkio -lkparts -llcms
+chalk_rgb_f32_plugin_la_LIBADD = libchalk_rgb_f32.la ../../chalkcolor/libchalkcolor.la
+
+chalk_rgb_f32_plugin_la_METASOURCES = AUTO
+
+if include_kunittest_tests
+TESTSDIR = tests
+endif
+
+SUBDIRS = . $(TESTSDIR)
+
diff --git a/chalk/colorspaces/rgb_f32/chalk_rgb_f32_plugin.desktop b/chalk/colorspaces/rgb_f32/chalk_rgb_f32_plugin.desktop
new file mode 100644
index 00000000..7f238a47
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/chalk_rgb_f32_plugin.desktop
@@ -0,0 +1,77 @@
+[Desktop Entry]
+Name=RGB Color Model (32-bit float)
+Name[bg]=Цветови модел RGB (32 бита)
+Name[ca]=Model de color RGB (paleta de 32 bits)
+Name[cy]=Model Lliw RGB (arnawf 32-did)
+Name[da]=RGB-farvemodel (32-bit float)
+Name[de]=RGB-Farbmodell (32-bit Fließkomma)
+Name[el]=Χρωματικό μοντέλο RGB (32 bit δεκαδικοί)
+Name[en_GB]=RGB Colour Model (32-bit float)
+Name[eo]=RGB-kolormodelo (32-bita flupunkto)
+Name[es]=Modelo de color RGB (decimal de 32 bits)
+Name[et]=RGB värvimudel (32-bitine murdarv)
+Name[fa]=مدل رنگ RGB )شناور ۳۲ بیتی(
+Name[fr]=Modèle de couleurs RVB (flottants 32 bits)
+Name[fy]=RGB-kleurmodel (32-bit float)
+Name[gl]=Espazo de Cores RGB (flutuante de 32-bit)
+Name[he]=מודל צבעים RGB (32 סיביות)
+Name[hu]=RGB színmodell (32 bites lebegőpontos)
+Name[is]=RGB litategund (32-bita fleytitala)
+Name[it]=Modello di colore RGB (virgola mobile a 32 bit)
+Name[ja]=RGB カラーモデル (32 ビット浮動小数)
+Name[km]=គំរូ​ពណ៌ RGB (ចំនួន​ទស្សភាគ 32 ប៊ីត)
+Name[nb]=RGB-fargemodell (32-bit flyttall)
+Name[nds]=RGB-Klöörmodell (32-Bit Fleetkomma)
+Name[ne]=RGB रङ मोडेल (३२-बिट उत्प्लावन)
+Name[nl]=RGB-kleurmodel (32-bit float)
+Name[pl]=Przestrzeń barw RGB (32-bitowa zmiennoprzecinkowa)
+Name[pt]=Modelo de Cor RGB (v. flutuante de 32-bits)
+Name[pt_BR]=Modelo de Cor RGB (ponto flutuante de 32-bits)
+Name[ru]=RGB (32-бит с плавающей точкой)
+Name[sk]=Model farieb RGB (32-bitové reálne čísla)
+Name[sl]=Barvni model RGB (32-bitno celo število)
+Name[sr]=RGB модел боја (32-битно реално)
+Name[sr@Latn]=RGB model boja (32-bitno realno)
+Name[sv]=RGB-färgmodell (32-bitars heltal)
+Name[uk]=Модель кольорів RGB (32-бітне дробове число)
+Name[uz]=RGB rang usuli (32-bit kasr)
+Name[uz@cyrillic]=RGB ранг усули (32-бит каср)
+Name[zh_TW]=RGB 色彩模型 (32-bit 浮點數)
+Comment=Color model for 32-bit floating point per channel RGB images
+Comment[bg]=Цветови модел за 32 битови изображения RGB
+Comment[ca]=Model de color per a punt flotant de 32 bits-canal d'imatges RGB
+Comment[da]=Farvemodel for 32-bit decimaltal pr kanal RGB-billeder
+Comment[de]=Farbmodell für 32-bit Fließkomma pro Kanal RGB-Bilder
+Comment[el]=Χρωματικό μοντέλο για 32-bit δεκαδικούς ανά κανάλι RGB εικόνες
+Comment[en_GB]=Colour model for 32-bit floating point per channel RGB images
+Comment[es]=Modelo de color decimal de 32 bits por canal para imágenes RGB
+Comment[et]=32-bitiste murdarvuliste kanalitega RGB-piltide värvimudel
+Comment[fa]=مدل رنگ برای ممیز شناور ۳۲ بیتی برای هر تصویر RGB مجرا
+Comment[fr]=Modèle de couleurs pour des images RVB en 32 bits flottants par canal
+Comment[fy]=Kleurmodel foar RGB-ôfbyldings mei 32-bit Driuwende komma de kanaal
+Comment[gl]=Espazo de cores para imaxes RGB de 32-bit vírgula flutuante por canal
+Comment[he]=מודל צבעים עבור תמונות RGB של 32 סיביות/ערוצים
+Comment[hu]=Színmodell 32 bit (lebegőpontos)/csatorna RGB képekhez
+Comment[is]=Litategund fyrir 32-bita fleytitölu á rás RGB myndir
+Comment[it]=Modello di colore per immagini RGB in virgola mobile a canale di 32 bit
+Comment[ja]=32 ビット浮動小数/チャンネル RGB 画像のためのカラーモデル
+Comment[km]=ម៉ូដែល​ពណ៌​សម្រាប់​ចំណុច​ចំនួន​ទស្សភាគ 32-bit ក្នុង​ឆានែល​រូបភាព RGB
+Comment[nb]=Fargemodell for RGB-bilde med 32 bit flyttall per kanal
+Comment[nds]=Klöörmodell för RGB-Biller mit 32-Bit Fleetkomma per Kanaal
+Comment[ne]=प्रति च्यानल RGB छविहरूको ३२-बिट उत्प्लावन बिन्दुका लागि रङ मोडेल
+Comment[nl]=Kleurmodel voor RGB-afbeeldingen met 32-bit drijvende komma per kanaal
+Comment[pl]=Przestrzeń barw dla obrazków RGB z 32-bitową liczbą zmiennoprzecinkową na kanał
+Comment[pt]=Modelo de cor para imagens RGB com 32 bits de vírgula flutuante por canal
+Comment[pt_BR]=Modelo de cor para imagens RGB com 32 bits de ponto flutuante por canal
+Comment[ru]=Цветовое пространство RGB (32-бит/канал с плавающей точкой)
+Comment[sk]=Model farieb pre RGB obrázky s 32-bitovými reálnymi číslami na kanál
+Comment[sl]=Barvni model za slike RGB z 32-bitno plavajočo vejico na kanal
+Comment[sr]=Модел боја за RGB слике, 32-битно реално по каналу
+Comment[sr@Latn]=Model boja za RGB slike, 32-bitno realno po kanalu
+Comment[sv]=Färgmodell för 32-bitars flyttal per kanal RGB-bilder
+Comment[uk]=Модель кольорів для зображень RGB 32-біт з плаваючою комою на канал
+Comment[zh_TW]=每色頻 32-bit 浮點 RGB 圖片的色彩模型
+ServiceTypes=Chalk/ColorSpace
+Type=Service
+X-Chalk-Version=2
+X-KDE-Library=chalk_rgb_f32_plugin
diff --git a/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cc b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cc
new file mode 100644
index 00000000..98e0b28b
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cc
@@ -0,0 +1,949 @@
+/*
+ * Copyright (c) 2002 Patrick Julien <[email protected]>
+ * 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 <config.h>
+#include <limits.h>
+#include <stdlib.h>
+#include LCMS_HEADER
+
+#include <tqimage.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "kis_rgb_f32_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 FLOAT_MAX 1.0f //temp
+
+#define EPSILON 1e-6
+
+// FIXME: lcms doesn't support 32-bit float
+#define F32_LCMS_TYPE TYPE_BGRA_16
+
+// disable the lcms handling by setting profile=0
+KisRgbF32ColorSpace::KisRgbF32ColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile */*p*/) :
+ KisF32BaseColorSpace(KisID("RGBAF32", i18n("RGB (32-bit float/channel)")), F32_LCMS_TYPE, icSigRgbData, tqparent, 0)
+{
+ m_channels.push_back(new KisChannelInfo(i18n("Red"), i18n("R"), PIXEL_RED * sizeof(float), KisChannelInfo::COLOR, KisChannelInfo::FLOAT32, sizeof(float)));
+ m_channels.push_back(new KisChannelInfo(i18n("Green"), i18n("G"), PIXEL_GREEN * sizeof(float), KisChannelInfo::COLOR, KisChannelInfo::FLOAT32, sizeof(float)));
+ m_channels.push_back(new KisChannelInfo(i18n("Blue"), i18n("B"), PIXEL_BLUE * sizeof(float), KisChannelInfo::COLOR, KisChannelInfo::FLOAT32, sizeof(float)));
+ m_channels.push_back(new KisChannelInfo(i18n("Alpha"), i18n("A"), PIXEL_ALPHA * sizeof(float), KisChannelInfo::ALPHA, KisChannelInfo::FLOAT32, sizeof(float)));
+
+ m_alphaPos = PIXEL_ALPHA * sizeof(float);
+}
+
+KisRgbF32ColorSpace::~KisRgbF32ColorSpace()
+{
+}
+
+void KisRgbF32ColorSpace::setPixel(TQ_UINT8 *dst, float red, float green, float blue, float alpha) const
+{
+ Pixel *dstPixel = reinterpret_cast<Pixel *>(dst);
+
+ dstPixel->red = red;
+ dstPixel->green = green;
+ dstPixel->blue = blue;
+ dstPixel->alpha = alpha;
+}
+
+void KisRgbF32ColorSpace::getPixel(const TQ_UINT8 *src, float *red, float *green, float *blue, float *alpha) const
+{
+ const Pixel *srcPixel = reinterpret_cast<const Pixel *>(src);
+
+ *red = srcPixel->red;
+ *green = srcPixel->green;
+ *blue = srcPixel->blue;
+ *alpha = srcPixel->alpha;
+}
+
+void KisRgbF32ColorSpace::fromTQColor(const TQColor& c, TQ_UINT8 *dstU8, KisProfile * /*profile*/)
+{
+ Pixel *dst = reinterpret_cast<Pixel *>(dstU8);
+
+ dst->red = UINT8_TO_FLOAT(c.red());
+ dst->green = UINT8_TO_FLOAT(c.green());
+ dst->blue = UINT8_TO_FLOAT(c.blue());
+}
+
+void KisRgbF32ColorSpace::fromTQColor(const TQColor& c, TQ_UINT8 opacity, TQ_UINT8 *dstU8, KisProfile * /*profile*/)
+{
+ Pixel *dst = reinterpret_cast<Pixel *>(dstU8);
+
+ dst->red = UINT8_TO_FLOAT(c.red());
+ dst->green = UINT8_TO_FLOAT(c.green());
+ dst->blue = UINT8_TO_FLOAT(c.blue());
+ dst->alpha = UINT8_TO_FLOAT(opacity);
+}
+
+void KisRgbF32ColorSpace::toTQColor(const TQ_UINT8 *srcU8, TQColor *c, KisProfile * /*profile*/)
+{
+ const Pixel *src = reinterpret_cast<const Pixel *>(srcU8);
+
+ c->setRgb(FLOAT_TO_UINT8(src->red), FLOAT_TO_UINT8(src->green), FLOAT_TO_UINT8(src->blue));
+}
+
+void KisRgbF32ColorSpace::toTQColor(const TQ_UINT8 *srcU8, TQColor *c, TQ_UINT8 *opacity, KisProfile * /*profile*/)
+{
+ const Pixel *src = reinterpret_cast<const Pixel *>(srcU8);
+
+ c->setRgb(FLOAT_TO_UINT8(src->red), FLOAT_TO_UINT8(src->green), FLOAT_TO_UINT8(src->blue));
+ *opacity = FLOAT_TO_UINT8(src->alpha);
+}
+
+TQ_UINT8 KisRgbF32ColorSpace::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 FLOAT_TO_UINT8(TQMAX(TQABS(src2->red - src1->red),
+ TQMAX(TQABS(src2->green - src1->green),
+ TQABS(src2->blue - src1->blue))));
+}
+
+void KisRgbF32ColorSpace::mixColors(const TQ_UINT8 **colors, const TQ_UINT8 *weights, TQ_UINT32 nColors, TQ_UINT8 *dst) const
+{
+ float totalRed = 0, totalGreen = 0, totalBlue = 0, newAlpha = 0;
+
+ while (nColors--)
+ {
+ const Pixel *pixel = reinterpret_cast<const Pixel *>(*colors);
+
+ float alpha = pixel->alpha;
+ float alphaTimesWeight = alpha * UINT8_TO_FLOAT(*weights);
+
+ totalRed += pixel->red * alphaTimesWeight;
+ totalGreen += pixel->green * alphaTimesWeight;
+ totalBlue += pixel->blue * alphaTimesWeight;
+ newAlpha += alphaTimesWeight;
+
+ weights++;
+ colors++;
+ }
+
+ Q_ASSERT(newAlpha <= F32_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 KisRgbF32ColorSpace::convolveColors(TQ_UINT8** colors, TQ_INT32 * kernelValues, KisChannelInfo::enumChannelFlags channelFlags, TQ_UINT8 *dst, TQ_INT32 factor, TQ_INT32 offset, TQ_INT32 nColors) const
+{
+ float totalRed = 0, totalGreen = 0, totalBlue = 0, totalAlpha = 0;
+
+ while (nColors--)
+ {
+ const Pixel * pixel = reinterpret_cast<const Pixel *>( *colors );
+
+ float weight = *kernelValues;
+
+ if (weight != 0) {
+ totalRed += pixel->red * weight;
+ totalGreen += pixel->green * weight;
+ totalBlue += pixel->blue * weight;
+ totalAlpha += pixel->alpha * weight;
+ }
+ colors++;
+ kernelValues++;
+ }
+
+ Pixel * p = reinterpret_cast< Pixel *>( dst );
+
+ if (channelFlags & KisChannelInfo::FLAG_COLOR) {
+ p->red = CLAMP( ( totalRed / factor) + offset, 0, FLOAT_MAX);
+ p->green = CLAMP( ( totalGreen / factor) + offset, 0, FLOAT_MAX);
+ p->blue = CLAMP( ( totalBlue / factor) + offset, 0, FLOAT_MAX);
+ }
+ if (channelFlags & KisChannelInfo::FLAG_ALPHA) {
+ p->alpha = CLAMP((totalAlpha/ factor) + offset, 0, FLOAT_MAX);
+ }
+}
+
+
+void KisRgbF32ColorSpace::invertColor(TQ_UINT8 * src, TQ_INT32 nPixels)
+{
+ TQ_UINT32 psize = pixelSize();
+
+ while (nPixels--)
+ {
+ Pixel * p = reinterpret_cast< Pixel *>( src );
+ p->red = FLOAT_MAX - p->red;
+ p->green = FLOAT_MAX - p->green;
+ p->blue = FLOAT_MAX - p->blue;
+ src += psize;
+ }
+
+}
+
+TQ_UINT8 KisRgbF32ColorSpace::intensity8(const TQ_UINT8 * src) const
+{
+ const Pixel * p = reinterpret_cast<const Pixel *>( src );
+
+ return FLOAT_TO_UINT8((p->red * 0.30 + p->green * 0.59 + p->blue * 0.11) + 0.5);
+}
+
+
+
+TQValueVector<KisChannelInfo *> KisRgbF32ColorSpace::channels() const
+{
+ return m_channels;
+}
+
+TQ_UINT32 KisRgbF32ColorSpace::nChannels() const
+{
+ return MAX_CHANNEL_RGBA;
+}
+
+TQ_UINT32 KisRgbF32ColorSpace::nColorChannels() const
+{
+ return MAX_CHANNEL_RGB;
+}
+
+TQ_UINT32 KisRgbF32ColorSpace::pixelSize() const
+{
+ return MAX_CHANNEL_RGBA * sizeof(float);
+}
+
+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 KisRgbF32ColorSpace::convertToTQImage(const TQ_UINT8 *dataU8, TQ_INT32 width, TQ_INT32 height,
+ KisProfile * /*dstProfile*/,
+ TQ_INT32 /*renderingIntent*/, float exposure)
+
+{
+ const float *data = reinterpret_cast<const float *>(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) = FLOAT_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 KisRgbF32ColorSpace::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, float opacity)
+{
+ while (rows > 0) {
+
+ const float *src = reinterpret_cast<const float *>(srcRowStart);
+ float *dst = reinterpret_cast<float *>(dstRowStart);
+ const TQ_UINT8 *tqmask = tqmaskRowStart;
+ TQ_INT32 columns = numColumns;
+
+ while (columns > 0) {
+
+ float srcAlpha = src[PIXEL_ALPHA];
+
+ // apply the alphatqmask
+ if (tqmask != 0) {
+ TQ_UINT8 U8_tqmask = *tqmask;
+
+ if (U8_tqmask != OPACITY_OPAQUE) {
+ srcAlpha *= UINT8_TO_FLOAT(U8_tqmask);
+ }
+ tqmask++;
+ }
+
+ if (srcAlpha > F32_OPACITY_TRANSPARENT + EPSILON) {
+
+ if (opacity < F32_OPACITY_OPAQUE - EPSILON) {
+ srcAlpha *= opacity;
+ }
+
+ if (srcAlpha > F32_OPACITY_OPAQUE - EPSILON) {
+ memcpy(dst, src, MAX_CHANNEL_RGBA * sizeof(float));
+ } else {
+ float dstAlpha = dst[PIXEL_ALPHA];
+
+ float srcBlend;
+
+ if (dstAlpha > F32_OPACITY_OPAQUE - EPSILON) {
+ srcBlend = srcAlpha;
+ } else {
+ float newAlpha = dstAlpha + (F32_OPACITY_OPAQUE - dstAlpha) * srcAlpha;
+ dst[PIXEL_ALPHA] = newAlpha;
+
+ if (newAlpha > EPSILON) {
+ srcBlend = srcAlpha / newAlpha;
+ } else {
+ srcBlend = srcAlpha;
+ }
+ }
+
+ if (srcBlend > F32_OPACITY_OPAQUE - EPSILON) {
+ memcpy(dst, src, MAX_CHANNEL_RGB * sizeof(float));
+ } else {
+ dst[PIXEL_RED] = FLOAT_BLEND(src[PIXEL_RED], dst[PIXEL_RED], srcBlend);
+ dst[PIXEL_GREEN] = FLOAT_BLEND(src[PIXEL_GREEN], dst[PIXEL_GREEN], srcBlend);
+ dst[PIXEL_BLUE] = FLOAT_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 float *src = reinterpret_cast<const float *>(srcRowStart); \
+ float *dst = reinterpret_cast<float *>(dstRowStart); \
+ TQ_INT32 columns = numColumns; \
+ const TQ_UINT8 *tqmask = tqmaskRowStart; \
+ \
+ while (columns > 0) { \
+ \
+ float srcAlpha = src[PIXEL_ALPHA]; \
+ float dstAlpha = dst[PIXEL_ALPHA]; \
+ \
+ srcAlpha = TQMIN(srcAlpha, dstAlpha); \
+ \
+ if (tqmask != 0) { \
+ TQ_UINT8 U8_tqmask = *tqmask; \
+ \
+ if (U8_tqmask != OPACITY_OPAQUE) { \
+ srcAlpha *= UINT8_TO_FLOAT(U8_tqmask); \
+ } \
+ tqmask++; \
+ } \
+ \
+ if (srcAlpha > F32_OPACITY_TRANSPARENT + EPSILON) { \
+ \
+ if (opacity < F32_OPACITY_OPAQUE - EPSILON) { \
+ srcAlpha *= opacity; \
+ } \
+ \
+ float srcBlend; \
+ \
+ if (dstAlpha > F32_OPACITY_OPAQUE - EPSILON) { \
+ srcBlend = srcAlpha; \
+ } else { \
+ float newAlpha = dstAlpha + (F32_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 KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ float srcColor = src[PIXEL_RED];
+ float dstColor = dst[PIXEL_RED];
+
+ srcColor = srcColor * dstColor;
+
+ dst[PIXEL_RED] = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ srcColor = src[PIXEL_GREEN];
+ dstColor = dst[PIXEL_GREEN];
+
+ srcColor = srcColor * dstColor;
+
+ dst[PIXEL_GREEN] = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ srcColor = src[PIXEL_BLUE];
+ dstColor = dst[PIXEL_BLUE];
+
+ srcColor = srcColor * dstColor;
+
+ dst[PIXEL_BLUE] = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = TQMIN(dstColor / (srcColor + EPSILON), FLOAT_MAX);
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = FLOAT_MAX - ((FLOAT_MAX - dstColor) * (FLOAT_MAX - srcColor));
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = dstColor * (dstColor + 2 * (srcColor * (FLOAT_MAX - dstColor)));
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = TQMIN(dstColor / (FLOAT_MAX + EPSILON - srcColor), FLOAT_MAX);
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = TQMIN((FLOAT_MAX - dstColor) / (srcColor + EPSILON), FLOAT_MAX);
+ srcColor = CLAMP(FLOAT_MAX - srcColor, 0, FLOAT_MAX);
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = TQMIN(srcColor, dstColor);
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float opacity)
+{
+ COMMON_COMPOSITE_OP_PROLOG();
+
+ {
+ for (int channel = 0; channel < MAX_CHANNEL_RGB; channel++) {
+
+ float srcColor = src[channel];
+ float dstColor = dst[channel];
+
+ srcColor = TQMAX(srcColor, dstColor);
+
+ float newColor = FLOAT_BLEND(srcColor, dstColor, srcBlend);
+
+ dst[channel] = newColor;
+ }
+ }
+
+ COMMON_COMPOSITE_OP_EPILOG();
+}
+
+void KisRgbF32ColorSpace::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, float 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 KisRgbF32ColorSpace::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, float 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 KisRgbF32ColorSpace::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, float 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 KisRgbF32ColorSpace::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, float 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 KisRgbF32ColorSpace::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,
+ float /*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++)
+ {
+ float srcAlpha = s->alpha;
+
+ // apply the alphatqmask
+ if (tqmask != 0) {
+ TQ_UINT8 U8_tqmask = *tqmask;
+
+ if (U8_tqmask != OPACITY_OPAQUE) {
+ srcAlpha = FLOAT_BLEND(srcAlpha, F32_OPACITY_OPAQUE, UINT8_TO_FLOAT(U8_tqmask));
+ }
+ tqmask++;
+ }
+ d->alpha = srcAlpha * d->alpha;
+ }
+
+ dst += dstRowSize;
+ src += srcRowSize;
+ if(srcAlphaMask) {
+ srcAlphaMask += tqmaskRowStride;
+ }
+ }
+}
+
+void KisRgbF32ColorSpace::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)
+{
+ float opacity = UINT8_TO_FLOAT(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<float, F32Mult, Uint8ToF32, F32OpacityTest,
+ PIXEL_ALPHA, MAX_CHANNEL_RGB, MAX_CHANNEL_RGBA>(
+ dst, dstRowStride, src, srcRowStride, tqmask, tqmaskRowStride,
+ rows, cols, U8_opacity, F32Mult(), Uint8ToF32(), F32OpacityTest());
+ default:
+ break;
+ }
+}
+
+KisCompositeOpList KisRgbF32ColorSpace::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_f32/kis_rgb_f32_colorspace.h b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h
new file mode 100644
index 00000000..6f2ff3ae
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2002 Patrick Julien <[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.
+ */
+#ifndef KIS_STRATEGY_COLORSPACE_RGB_F32_H_
+#define KIS_STRATEGY_COLORSPACE_RGB_F32_H_
+
+#include <tqcolor.h>
+
+#include <klocale.h>
+
+#include <koffice_export.h>
+
+#include "kis_global.h"
+#include "kis_f32_base_colorspace.h"
+
+class KisColorSpaceFactoryRegistry;
+
+class KRITATOOL_EXPORT KisRgbF32ColorSpace : public KisF32BaseColorSpace {
+public:
+ KisRgbF32ColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile *p);
+ virtual ~KisRgbF32ColorSpace();
+
+ virtual bool willDegrade(ColorSpaceIndependence independence)
+ {
+ if (independence == TO_RGBA8 || independence == TO_LAB16)
+ return true;
+ else
+ return false;
+ };
+
+
+
+public:
+ void setPixel(TQ_UINT8 *pixel, float red, float green, float blue, float alpha) const;
+ void getPixel(const TQ_UINT8 *pixel, float *red, float *green, float *blue, float *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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float 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, float opacity);
+
+private:
+ friend class KisRgbF32ColorSpaceTester;
+
+ 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 {
+ float blue;
+ float green;
+ float red;
+ float alpha;
+ };
+
+ // For Alpha Composite
+ struct F32Mult {
+ inline float operator()(const float& a, const float& b) const {
+ return a * b;
+ }
+ };
+ struct Uint8ToF32 {
+ inline float operator()(const TQ_UINT8 src) const {
+ return UINT8_TO_FLOAT(src);
+ }
+ };
+ struct F32OpacityTest {
+ inline bool operator()(const float& opacity) const {
+ return opacity > F32_OPACITY_TRANSPARENT + 1e-6; // #define EPSILON in the .cc
+ }
+ };
+};
+
+// FIXME: lcms doesn't support 32-bit float
+#define F32_LCMS_TYPE TYPE_BGRA_16
+
+class KisRgbF32ColorSpaceFactory : public KisColorSpaceFactory
+{
+public:
+ /**
+ * Chalk definition for use in .kra files and internally: unchanging name +
+ * i18n'able description.
+ */
+ virtual KisID id() const { return KisID("RGBAF32", i18n("RGB (32-bit float/channel)")); };
+
+ /**
+ * lcms colorspace type definition.
+ */
+ virtual TQ_UINT32 colorSpaceType() { return F32_LCMS_TYPE; };
+
+ virtual icColorSpaceSignature colorSpaceSignature() { return icSigRgbData; };
+
+ virtual KisColorSpace *createColorSpace(KisColorSpaceFactoryRegistry * tqparent, KisProfile *p) { return new KisRgbF32ColorSpace(tqparent, p); };
+
+ virtual TQString defaultProfile() { return "sRGB built-in - (lcms internal)"; };
+};
+
+#endif // KIS_STRATEGY_COLORSPACE_RGB_F32_H_
+
diff --git a/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cc b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cc
new file mode 100644
index 00000000..4e11e36c
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/rgb_f32_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_f32_plugin.h"
+#include "kis_rgb_f32_colorspace.h"
+
+typedef KGenericFactory<RGBF32Plugin> RGBF32PluginFactory;
+K_EXPORT_COMPONENT_FACTORY( chalk_rgb_f32_plugin, RGBF32PluginFactory( "chalk" ) )
+
+
+RGBF32Plugin::RGBF32Plugin(TQObject *tqparent, const char *name, const TQStringList &)
+ : KParts::Plugin(tqparent, name)
+{
+ setInstance(RGBF32PluginFactory::instance());
+
+ if ( tqparent->inherits("KisColorSpaceFactoryRegistry") )
+ {
+ KisColorSpaceFactoryRegistry * f = dynamic_cast<KisColorSpaceFactoryRegistry*>(tqparent);
+
+ KisColorSpace * colorSpaceRGBF32 = new KisRgbF32ColorSpace(f, 0);
+
+ KisColorSpaceFactory * csf = new KisRgbF32ColorSpaceFactory();
+ f->add(csf);
+
+ KisHistogramProducerFactoryRegistry::instance()->add(
+ new KisBasicHistogramProducerFactory<KisBasicF32HistogramProducer>
+ (KisID("RGBF32HISTO", i18n("Float32")), colorSpaceRGBF32) );
+ }
+
+}
+
+RGBF32Plugin::~RGBF32Plugin()
+{
+}
+
+#include "rgb_f32_plugin.moc"
diff --git a/chalk/colorspaces/rgb_f32/rgb_f32_plugin.h b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.h
new file mode 100644
index 00000000..22ec674f
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/rgb_f32_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_F32_PLUGIN_H_
+#define RGB_F32_PLUGIN_H_
+
+#include <kparts/plugin.h>
+
+/**
+ * A plugin wrapper around the RGB F32 colour space strategy.
+ */
+class RGBF32Plugin : public KParts::Plugin
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ RGBF32Plugin(TQObject *tqparent, const char *name, const TQStringList &);
+ virtual ~RGBF32Plugin();
+
+};
+
+
+#endif // RGB_F32_PLUGIN_H_
diff --git a/chalk/colorspaces/rgb_f32/rgb_f32_plugin.rc b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.rc
new file mode 100644
index 00000000..88b13f85
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.rc
@@ -0,0 +1,9 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui library="chalk_rgb_f32_plugin" version="1">
+<Menu name="Image"><text>&amp;Image</text>
+ <Menu name="Mode"><text>&amp;Mode</text>
+ <Action name="convert to RGB(A) (32-bit float)"/>
+ </Menu>
+</Menu>
+
+</kpartgui>
diff --git a/chalk/colorspaces/rgb_f32/tests/Makefile.am b/chalk/colorspaces/rgb_f32/tests/Makefile.am
new file mode 100644
index 00000000..5980c24e
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/tests/Makefile.am
@@ -0,0 +1,17 @@
+AM_CPPFLAGS = -I$(srcdir)/.. \
+ -I$(srcdir)/../../../sdk \
+ -I$(srcdir)/../../../chalkcolor/color_strategy/ \
+ -I$(srcdir)/../../../color_strategy/ \
+ $(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_strategy_colorspace_rgb_f32_tester.la
+
+kunittest_kis_strategy_colorspace_rgb_f32_tester_la_SOURCES = kis_strategy_colorspace_rgb_f32_tester.cc
+kunittest_kis_strategy_colorspace_rgb_f32_tester_la_LIBADD = -lkunittest ../libchalk_rgb_f32.la
+kunittest_kis_strategy_colorspace_rgb_f32_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries)
+
+check-local: kunittest_kis_strategy_colorspace_rgb_f32_tester.la
+ kunittestmodrunner
+
diff --git a/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cc b/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cc
new file mode 100644
index 00000000..b4ec34e9
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cc
@@ -0,0 +1,541 @@
+/*
+ * 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_strategy_colorspace_rgb_f32_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_strategy_colorspace_rgb_f32_tester, "RGBA 32-bit float colorspace tester" );
+KUNITTEST_MODULE_REGISTER_TESTER( KisRgbF32ColorSpaceTester );
+
+#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(float))
+
+#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
+
+
+void KisRgbF32ColorSpaceTester::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 KisRgbF32ColorSpaceTester::testBasics()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisRgbF32ColorSpace *cs = new KisRgbF32ColorSpace(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");
+
+ KisRgbF32ColorSpace::Pixel defaultPixel;
+
+ memcpy(&defaultPixel, pd->dataManager()->defaultPixel(), sizeof(defaultPixel));
+
+ CHECK(defaultPixel.red, 0.0f);
+ CHECK(defaultPixel.green, 0.0f);
+ CHECK(defaultPixel.blue, 0.0f);
+ CHECK(defaultPixel.alpha, F32_OPACITY_TRANSPARENT);
+
+ float pixel[NUM_CHANNELS];
+
+ cs->fromTQColor(tqRgb(255, 255, 255), reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+
+ cs->fromTQColor(tqRgb(0, 0, 0), reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], MIN_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_GREEN], MIN_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_BLUE], MIN_CHANNEL_VALUE);
+
+ cs->fromTQColor(tqRgb(128, 64, 192), reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], UINT8_TO_FLOAT(128));
+ CHECK(pixel[PIXEL_GREEN], UINT8_TO_FLOAT(64));
+ CHECK(pixel[PIXEL_BLUE], UINT8_TO_FLOAT(192));
+
+ cs->fromTQColor(tqRgb(255, 255, 255), OPACITY_OPAQUE, reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_ALPHA], MAX_CHANNEL_VALUE);
+
+ cs->fromTQColor(tqRgb(255, 255, 255), OPACITY_TRANSPARENT, reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_ALPHA], F32_OPACITY_TRANSPARENT);
+
+ cs->fromTQColor(tqRgb(255, 255, 255), OPACITY_OPAQUE / 2, reinterpret_cast<TQ_UINT8 *>(pixel));
+
+ CHECK(pixel[PIXEL_RED], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+ CHECK(pixel[PIXEL_ALPHA], UINT8_TO_FLOAT(OPACITY_OPAQUE / 2));
+
+ pixel[PIXEL_RED] = MAX_CHANNEL_VALUE;
+ pixel[PIXEL_GREEN] = MAX_CHANNEL_VALUE;
+ pixel[PIXEL_BLUE] = MAX_CHANNEL_VALUE;
+
+ 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] = MIN_CHANNEL_VALUE;
+ pixel[PIXEL_GREEN] = MIN_CHANNEL_VALUE;
+ pixel[PIXEL_BLUE] = MIN_CHANNEL_VALUE;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c);
+
+ CHECK(c.red(), 0);
+ CHECK(c.green(), 0);
+ CHECK(c.blue(), 0);
+
+ pixel[PIXEL_RED] = MAX_CHANNEL_VALUE / 4;
+ pixel[PIXEL_GREEN] = MAX_CHANNEL_VALUE / 2;
+ pixel[PIXEL_BLUE] = (3 * MAX_CHANNEL_VALUE) / 4;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c);
+
+ CHECK(c.red(), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 4));
+ CHECK(c.green(), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 2));
+ CHECK(c.blue(), (int)FLOAT_TO_UINT8((3 * MAX_CHANNEL_VALUE) / 4));
+
+ pixel[PIXEL_RED] = MAX_CHANNEL_VALUE;
+ pixel[PIXEL_GREEN] = MAX_CHANNEL_VALUE;
+ pixel[PIXEL_BLUE] = MAX_CHANNEL_VALUE;
+ pixel[PIXEL_ALPHA] = MAX_CHANNEL_VALUE;
+
+ 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] = F32_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] = MIN_CHANNEL_VALUE;
+ pixel[PIXEL_GREEN] = MIN_CHANNEL_VALUE;
+ pixel[PIXEL_BLUE] = MIN_CHANNEL_VALUE;
+ pixel[PIXEL_ALPHA] = F32_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] = MAX_CHANNEL_VALUE / 4;
+ pixel[PIXEL_GREEN] = MAX_CHANNEL_VALUE / 2;
+ pixel[PIXEL_BLUE] = (3 * MAX_CHANNEL_VALUE) / 4;
+ pixel[PIXEL_ALPHA] = MAX_CHANNEL_VALUE / 2;
+
+ cs->toTQColor(reinterpret_cast<const TQ_UINT8 *>(pixel), &c, &opacity);
+
+ CHECK(c.red(), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 4));
+ CHECK(c.green(), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 2));
+ CHECK(c.blue(), (int)FLOAT_TO_UINT8((3 * MAX_CHANNEL_VALUE) / 4));
+ CHECK((int)opacity, (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 2));
+
+ #define NUM_PIXELS 4
+
+ KisRgbF32ColorSpace::Pixel pixels[NUM_PIXELS] = {
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE / 4},
+ {MAX_CHANNEL_VALUE / 4, MAX_CHANNEL_VALUE / 2, MAX_CHANNEL_VALUE / 3, MAX_CHANNEL_VALUE / 2},
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MIN_CHANNEL_VALUE},
+ {MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MAX_CHANNEL_VALUE}
+ };
+
+ cs->setAlpha(reinterpret_cast<TQ_UINT8 *>(pixels), OPACITY_OPAQUE / 2, NUM_PIXELS);
+
+ CHECK(pixels[0].red, MAX_CHANNEL_VALUE);
+ CHECK(pixels[0].green, MAX_CHANNEL_VALUE);
+ CHECK(pixels[0].blue, MAX_CHANNEL_VALUE);
+ CHECK(pixels[0].alpha, UINT8_TO_FLOAT(OPACITY_OPAQUE / 2));
+
+ CHECK(pixels[1].red, MAX_CHANNEL_VALUE / 3);
+ CHECK(pixels[1].green, MAX_CHANNEL_VALUE / 2);
+ CHECK(pixels[1].blue, MAX_CHANNEL_VALUE / 4);
+ CHECK(pixels[1].alpha, UINT8_TO_FLOAT(OPACITY_OPAQUE / 2));
+
+ CHECK(pixels[2].red, MAX_CHANNEL_VALUE);
+ CHECK(pixels[2].green, MAX_CHANNEL_VALUE);
+ CHECK(pixels[2].blue, MAX_CHANNEL_VALUE);
+ CHECK(pixels[2].alpha, UINT8_TO_FLOAT(OPACITY_OPAQUE / 2));
+
+ CHECK(pixels[3].red, MIN_CHANNEL_VALUE);
+ CHECK(pixels[3].green, MIN_CHANNEL_VALUE);
+ CHECK(pixels[3].blue, MIN_CHANNEL_VALUE);
+ CHECK(pixels[3].alpha, UINT8_TO_FLOAT(OPACITY_OPAQUE / 2));
+
+ pixel[PIXEL_RED] = MAX_CHANNEL_VALUE;
+ pixel[PIXEL_GREEN] = MAX_CHANNEL_VALUE / 2;
+ pixel[PIXEL_BLUE] = MAX_CHANNEL_VALUE / 4;
+ pixel[PIXEL_ALPHA] = MIN_CHANNEL_VALUE;
+
+ TQString valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), RED_CHANNEL);
+ CHECK(valueText, TQString().setNum(MAX_CHANNEL_VALUE));
+
+ valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), GREEN_CHANNEL);
+ CHECK(valueText, TQString().setNum(MAX_CHANNEL_VALUE / 2));
+
+ valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), BLUE_CHANNEL);
+ CHECK(valueText, TQString().setNum(MAX_CHANNEL_VALUE / 4));
+
+ valueText = cs->channelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), ALPHA_CHANNEL);
+ CHECK(valueText, TQString().setNum(MIN_CHANNEL_VALUE));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), RED_CHANNEL);
+ CHECK(valueText, TQString().setNum(MAX_CHANNEL_VALUE));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), GREEN_CHANNEL);
+ CHECK(valueText, TQString().setNum(MAX_CHANNEL_VALUE / 2));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), BLUE_CHANNEL);
+ CHECK(valueText, TQString().setNum(MAX_CHANNEL_VALUE / 4));
+
+ valueText = cs->normalisedChannelValueText(reinterpret_cast<TQ_UINT8 *>(pixel), ALPHA_CHANNEL);
+ CHECK(valueText, TQString().setNum(MIN_CHANNEL_VALUE));
+
+ cs->setPixel(reinterpret_cast<TQ_UINT8 *>(pixel), 0.128, 0.192, 0.64, 0.99);
+ CHECK(pixel[PIXEL_RED], 0.128f);
+ CHECK(pixel[PIXEL_GREEN], 0.192f);
+ CHECK(pixel[PIXEL_BLUE], 0.64f);
+ CHECK(pixel[PIXEL_ALPHA], 0.99f);
+
+ float red;
+ float green;
+ float blue;
+ float alpha;
+
+ cs->getPixel(reinterpret_cast<const TQ_UINT8 *>(pixel), &red, &green, &blue, &alpha);
+ CHECK(red, 0.128f);
+ CHECK(green, 0.192f);
+ CHECK(blue, 0.64f);
+ CHECK(alpha, 0.99f);
+
+ CHECK(FLOAT_TO_UINT8(-0.5), 0u);
+ CHECK(FLOAT_TO_UINT8(0), 0u);
+ CHECK_TOLERANCE(FLOAT_TO_UINT8(0.5), UINT8_MAX / 2, 1u);
+ CHECK(FLOAT_TO_UINT8(1), UINT8_MAX);
+ CHECK(FLOAT_TO_UINT8(1.5), UINT8_MAX);
+
+ CHECK(FLOAT_TO_UINT16(-0.5), 0u);
+ CHECK(FLOAT_TO_UINT16(0), 0u);
+ CHECK_TOLERANCE(FLOAT_TO_UINT16(0.5), UINT16_MAX / 2, 1u);
+ CHECK(FLOAT_TO_UINT16(1), UINT16_MAX);
+ CHECK(FLOAT_TO_UINT16(1.5), UINT16_MAX);
+}
+
+void KisRgbF32ColorSpaceTester::testMixColors()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisAbstractColorSpace * cs = new KisRgbF32ColorSpace(profile);
+
+ // Test mixColors.
+ float pixel1[NUM_CHANNELS];
+ float pixel2[NUM_CHANNELS];
+ float outputPixel[NUM_CHANNELS];
+
+ outputPixel[PIXEL_RED] = 0;
+ outputPixel[PIXEL_GREEN] = 0;
+ outputPixel[PIXEL_BLUE] = 0;
+ outputPixel[PIXEL_ALPHA] = 0;
+
+ pixel1[PIXEL_RED] = MAX_CHANNEL_VALUE;
+ pixel1[PIXEL_GREEN] = MAX_CHANNEL_VALUE;
+ pixel1[PIXEL_BLUE] = MAX_CHANNEL_VALUE;
+ pixel1[PIXEL_ALPHA] = MAX_CHANNEL_VALUE;
+
+ 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], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_ALPHA], MAX_CHANNEL_VALUE);
+
+ weights[0] = 0;
+ weights[1] = 255;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], 0.0f);
+ CHECK(outputPixel[PIXEL_GREEN], 0.0f);
+ CHECK(outputPixel[PIXEL_BLUE], 0.0f);
+ CHECK(outputPixel[PIXEL_ALPHA], 0.0f);
+
+ weights[0] = 128;
+ weights[1] = 127;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_ALPHA], (128 * MAX_CHANNEL_VALUE) / 255);
+
+ pixel1[PIXEL_RED] = 20000;
+ pixel1[PIXEL_GREEN] = 10000;
+ pixel1[PIXEL_BLUE] = 5000;
+ pixel1[PIXEL_ALPHA] = MAX_CHANNEL_VALUE;
+
+ pixel2[PIXEL_RED] = 10000;
+ pixel2[PIXEL_GREEN] = 20000;
+ pixel2[PIXEL_BLUE] = 2000;
+ pixel2[PIXEL_ALPHA] = MAX_CHANNEL_VALUE;
+
+ 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], MAX_CHANNEL_VALUE);
+
+ pixel1[PIXEL_RED] = 0;
+ pixel1[PIXEL_GREEN] = 0;
+ pixel1[PIXEL_BLUE] = 0;
+ pixel1[PIXEL_ALPHA] = 0;
+
+ pixel2[PIXEL_RED] = MAX_CHANNEL_VALUE;
+ pixel2[PIXEL_GREEN] = MAX_CHANNEL_VALUE;
+ pixel2[PIXEL_BLUE] = MAX_CHANNEL_VALUE;
+ pixel2[PIXEL_ALPHA] = MAX_CHANNEL_VALUE;
+
+ weights[0] = 89;
+ weights[1] = 166;
+
+ cs->mixColors(pixelPtrs, weights, 2, reinterpret_cast<TQ_UINT8 *>(outputPixel));
+
+ CHECK(outputPixel[PIXEL_RED], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_GREEN], MAX_CHANNEL_VALUE);
+ CHECK(outputPixel[PIXEL_BLUE], MAX_CHANNEL_VALUE);
+ CHECK_TOLERANCE(outputPixel[PIXEL_ALPHA], (89 * 0 + 166 * MAX_CHANNEL_VALUE) / 255, 5);
+}
+
+#define PIXELS_WIDTH 2
+#define PIXELS_HEIGHT 2
+
+void KisRgbF32ColorSpaceTester::testToTQImage()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisAbstractColorSpace * cs = new KisRgbF32ColorSpace(profile);
+
+ KisRgbF32ColorSpace::Pixel pixels[PIXELS_WIDTH * PIXELS_HEIGHT] = {
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE / 4},
+ {MAX_CHANNEL_VALUE / 4, MAX_CHANNEL_VALUE / 2, MAX_CHANNEL_VALUE / 3, MAX_CHANNEL_VALUE / 2},
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MIN_CHANNEL_VALUE},
+ {MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MAX_CHANNEL_VALUE}
+ };
+
+ 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)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ CHECK(tqGreen(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ CHECK(tqBlue(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ CHECK(tqAlpha(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 4));
+
+ c = image.pixel(1, 0);
+
+ CHECK(tqRed(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 3));
+ CHECK(tqGreen(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 2));
+ CHECK(tqBlue(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 4));
+ CHECK(tqAlpha(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE / 2));
+
+ c = image.pixel(0, 1);
+
+ CHECK(tqRed(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ CHECK(tqGreen(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ CHECK(tqBlue(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ CHECK(tqAlpha(c), (int)FLOAT_TO_UINT8(MIN_CHANNEL_VALUE));
+
+ c = image.pixel(1, 1);
+
+ CHECK(tqRed(c), (int)FLOAT_TO_UINT8(MIN_CHANNEL_VALUE));
+ CHECK(tqGreen(c), (int)FLOAT_TO_UINT8(MIN_CHANNEL_VALUE));
+ CHECK(tqBlue(c), (int)FLOAT_TO_UINT8(MIN_CHANNEL_VALUE));
+ CHECK(tqAlpha(c), (int)FLOAT_TO_UINT8(MAX_CHANNEL_VALUE));
+ */
+}
+
+#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 KisRgbF32ColorSpaceTester::testCompositeOps()
+{
+ KisProfile *profile = new KisProfile(cmsCreate_sRGBProfile());
+
+ KisRgbF32ColorSpace *cs = new KisRgbF32ColorSpace(profile);
+
+ KisRgbF32ColorSpace::Pixel srcPixel;
+ KisRgbF32ColorSpace::Pixel dstPixel;
+
+ srcPixel.red = UINT8_TO_FLOAT(102);
+ srcPixel.green = UINT8_TO_FLOAT(170);
+ srcPixel.blue = UINT8_TO_FLOAT(238);
+ srcPixel.alpha = F32_OPACITY_OPAQUE;
+
+ dstPixel = srcPixel;
+
+ cs->compositeDivide(reinterpret_cast<TQ_UINT8 *>(&dstPixel), 1, reinterpret_cast<const TQ_UINT8 *>(&srcPixel),
+ 1, 0, 0, 1, 1, F32_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, KisRgbF32ColorSpace::F32_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);
+ */
+
+ /*
+ KisRgbF32ColorSpace::Pixel srcPixels[NUM_ROWS * NUM_COLUMNS] = {
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE / 4},
+ {MAX_CHANNEL_VALUE / 4, MAX_CHANNEL_VALUE / 2, MAX_CHANNEL_VALUE / 3, MAX_CHANNEL_VALUE / 2},
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MIN_CHANNEL_VALUE},
+ {MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MAX_CHANNEL_VALUE}
+ };
+
+ KisRgbF32ColorSpace::Pixel dstPixels[NUM_ROWS * NUM_COLUMNS] = {
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE / 4},
+ {MAX_CHANNEL_VALUE / 4, MAX_CHANNEL_VALUE / 2, MAX_CHANNEL_VALUE / 3, MAX_CHANNEL_VALUE / 2},
+ {MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MAX_CHANNEL_VALUE, MIN_CHANNEL_VALUE},
+ {MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MIN_CHANNEL_VALUE, MAX_CHANNEL_VALUE}
+ };
+
+ 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_f32/tests/kis_strategy_colorspace_rgb_f32_tester.h b/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.h
new file mode 100644
index 00000000..1153f147
--- /dev/null
+++ b/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_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_STRATEGY_COLORSPACE_RGB_F32_TESTER_H
+#define KIS_STRATEGY_COLORSPACE_RGB_F32_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 KisRgbF32ColorSpaceTester : public KUnitTest::Tester
+{
+public:
+ void allTests();
+ void testBasics();
+ void testMixColors();
+ void testToTQImage();
+ void testCompositeOps();
+};
+
+#endif
+