Commit fd30de05 authored by Cyrille Berger's avatar Cyrille Berger

initial port and refactor of the 16bit float colorspace for HDR

(sorry for the warnings ;p)

svn path=/trunk/koffice/; revision=616985
parent 4f05ba82
......@@ -6,10 +6,7 @@ MESSAGE(STATUS "Remember to port ycbcr_u16 and ycbcr_u8 and all the rest when Cy
#add_subdirectory(ycbcr_u16)
#add_subdirectory(ycbcr_u8)
if(OPENEXR_FOUND)
# add_subdirectory( rgb_f16half )
endif(OPENEXR_FOUND)
add_subdirectory( rgb_float_hdr )
add_subdirectory( gray_u8 )
add_subdirectory( gray_u16 )
# if(KUNITTEST_FOUND)
# add_subdirectory(tests)
# endif(KUNITTEST_FOUND)
########### next target ###############
if(OPENEXR_FOUND)
set(kritargbf16hdr_LIB_SRCS kis_rgb_f16_hdr_colorspace.cc )
kde4_automoc(${kritargbf16hdr_LIB_SRCS})
kde4_add_library(kritargbf16hdr SHARED ${kritargbf16hdr_LIB_SRCS})
target_link_libraries(kritargbf16hdr ${KDE4_KDECORE_LIBS} pigment )
set_target_properties(kritargbf16hdr PROPERTIES VERSION ${GENERIC_KOFFICE_LIB_VERSION} SOVERSION ${GENERIC_KOFFICE_LIB_SOVERSION} )
install(TARGETS kritargbf16hdr DESTINATION ${LIB_INSTALL_DIR})
endif(OPENEXR_FOUND)
if(0)
########### next target ###############
set(kritargbf32hdr_LIB_SRCS kis_rgb_f32_hdr_colorspace.cc )
kde4_automoc(${kritargbf32hdr_LIB_SRCS})
kde4_add_library(kritargbf32hdr SHARED ${kritargbf32hdr_LIB_SRCS})
target_link_libraries(kritargbf32hdr ${KDE4_KDECORE_LIBS} pigment )
set_target_properties(kritargbf32hdr PROPERTIES VERSION ${GENERIC_KOFFICE_LIB_VERSION} SOVERSION ${GENERIC_KOFFICE_LIB_SOVERSION} )
install(TARGETS kritargbf32hdr DESTINATION ${LIB_INSTALL_DIR})
endif(0)
########### next target ###############
set(kritargbfloathdrplugin_PART_SRCS rgb_float_hdr.cc )
kde4_automoc(${kritargbfloathdrplugin_PART_SRCS})
kde4_add_plugin(kritargbfloathdrplugin ${kritargbfloathdrplugin_PART_SRCS})
target_link_libraries(kritargbfloathdrplugin ${KDE4_KDECORE_LIBS} kritargbf16hdr pigment)
install(TARGETS kritargbfloathdrplugin DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES kritargbfloathdrplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR})
/*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* 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.h>
#include <QImage>
#include <QColor>
#include <kdebug.h>
#include <klocale.h>
#include <KoIntegerMaths.h>
#include <KoColorSpaceRegistry.h>
#include "kis_rgb_f16_hdr_colorspace.h"
#include "compositeops/KoCompositeOpOver.h"
#include "compositeops/KoCompositeOpErase.h"
KisRgbF16HDRColorSpace::KisRgbF16HDRColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p)
: KisRgbFloatHDRColorSpace<RgbF16Traits>("RGBAF16HALF", i18n("RGB (16-bit float/channel)"), parent, RGBAF16HALF_LCMS_TYPE)
{
m_channels.push_back(new KoChannelInfo(i18n("Red"), 2 * sizeof(half), KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, sizeof(half), QColor(255,0,0)));
m_channels.push_back(new KoChannelInfo(i18n("Green"), 1 * sizeof(half), KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, sizeof(half), QColor(0,255,0)));
m_channels.push_back(new KoChannelInfo(i18n("Blue"), 0, KoChannelInfo::COLOR, KoChannelInfo::FLOAT16, sizeof(half), QColor(0,0,255)));
m_channels.push_back(new KoChannelInfo(i18n("Alpha"), 3 * sizeof(half), KoChannelInfo::ALPHA, KoChannelInfo::FLOAT16));
m_compositeOps.insert( COMPOSITE_OVER, new KoCompositeOpOver<RgbF16Traits>( this ) );
m_compositeOps.insert( COMPOSITE_ERASE, new KoCompositeOpErase<RgbF16Traits>( this ) );
}
/*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* 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_16F_HDR_H_
#define KIS_STRATEGY_COLORSPACE_RGB_16F_HDR_H_
#include "klocale.h"
#include "kis_rgb_float_hdr_colorspace.h"
#include <half.h>
struct RgbF16Traits {
typedef half channels_type;
static const quint32 channels_nb = 4;
static const qint32 alpha_pos = 3;
};
class KisRgbF16HDRColorSpace : public KisRgbFloatHDRColorSpace<RgbF16Traits>
{
public:
KisRgbF16HDRColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p);
virtual bool willDegrade(ColorSpaceIndependence independence) const {
if (independence == TO_RGBA8 /*|| independence == TO_LAB16*/)
return true;
else
return false;
}
};
// FIXME: lcms doesn't support 16-bit float
#define RGBAF16HALF_LCMS_TYPE TYPE_BGRA_16
class KisRgbF16HDRColorSpaceFactory : public KoColorSpaceFactory
{
public:
/**
* Krita definition for use in .kra files and internally: unchanging name +
* i18n'able description.
*/
virtual KoID id() const { return KoID("RGBAF16HALF", i18n("RGB (16-bit float/channel)")); };
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return RGBAF16HALF_LCMS_TYPE; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigRgbData; };
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile * p) { return new KisRgbF16HDRColorSpace(parent, p); };
virtual QString defaultProfile() { return "sRGB built-in - (lcms internal)"; };
};
#endif // KIS_STRATEGY_COLORSPACE_RGB_H_
/*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
*
* 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_FLOAT_HDR_COLORSPACE_H_
#define KIS_RGB_FLOAT_HDR_COLORSPACE_H_
#include "klocale.h"
#include <KoIncompleteColorSpace.h>
#include <KoFallBack.h>
template <class _CSTraits>
class KisRgbFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>
{
public:
KisRgbFloatHDRColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent, qint32 type)
: KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>(id, name, parent, type, icSigRgbData)
{
}
};
#endif // KIS_STRATEGY_COLORSPACE_RGB_H_
[Desktop Entry]
Encoding=UTF-8
Name=RGB (float 16-bit and 32-bit HDR) Color Model
Comment=Color model for 16-bit and 32-bit per channel in floating point for High-Dynamic Range RGB images
ServiceTypes=KOffice/ColorSpace
Type=Service
X-KDE-Library=kritargbfloathdrplugin
X-Pigment-Version=1
/*
* rgb_plugin.cc -- Part of Krita
*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* 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 "rgb_float_hdr.h"
#include <stdlib.h>
#include <vector>
#include <QPoint>
#include <klocale.h>
#include <kiconloader.h>
#include <kinstance.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kgenericfactory.h>
#include <KoColorSpaceRegistry.h>
#include <KoBasicHistogramProducers.h>
#include "kis_rgb_f16_hdr_colorspace.h"
typedef KGenericFactory<RGBFloatHDRPlugin> RGBFloatHDRPluginFactory;
K_EXPORT_COMPONENT_FACTORY( kritargbfloathdrplugin, RGBFloatHDRPluginFactory( "krita" ) )
RGBFloatHDRPlugin::RGBFloatHDRPlugin(QObject *parent, const QStringList &)
: QObject(parent)
{
KoColorSpaceRegistry * f = KoColorSpaceRegistry::instance();
// Register F16 HDR colorspace
KoColorSpace * colorSpaceRGBF16Half = new KisRgbF16HDRColorSpace(f, 0);
KoColorSpaceFactory *csf = new KisRgbF16HDRColorSpaceFactory();
Q_CHECK_PTR(colorSpaceRGBF16Half);
f->add(csf);
KoHistogramProducerFactoryRegistry::instance()->add(
new KoBasicHistogramProducerFactory<KoBasicF16HalfHistogramProducer>
(KoID("RGBF16HALFHISTO", i18n("Float16 Half Histogram")), colorSpaceRGBF16Half) );
}
RGBFloatHDRPlugin::~RGBFloatHDRPlugin()
{
}
#include "rgb_float_hdr.moc"
/*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* 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_FLOAT_HDR_PLUGIN_H_
#define _RGB_FLOAT_HDR_PLUGIN_H_
#include <QObject>
/**
* A plugin wrapper around the RGB color space strategy.
*/
class RGBFloatHDRPlugin : public QObject
{
Q_OBJECT
public:
RGBFloatHDRPlugin(QObject *parent, const QStringList &);
virtual ~RGBFloatHDRPlugin();
};
#endif // RGB_PLUGIN_H_
......@@ -9,7 +9,7 @@
* 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.
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
......
......@@ -9,7 +9,7 @@
* 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.
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
......@@ -25,6 +25,7 @@
#include <klocale.h>
#include "config.h"
#include "KoColorSpace.h"
#include "KoID.h"
#include <koffice_export.h>
......@@ -107,6 +108,7 @@ public:
virtual double maximalZoom() const;
};
#ifdef HAVE_OPENEXR
class PIGMENT_EXPORT KoBasicF16HalfHistogramProducer : public KoBasicHistogramProducer {
public:
......
......@@ -2,16 +2,16 @@
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
......
......@@ -2,16 +2,16 @@
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
......
......@@ -3,16 +3,16 @@
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
......
......@@ -2,16 +2,16 @@
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
......@@ -182,12 +182,17 @@ namespace {
template<class _CSTraits>
class KoColorSpaceAbstract : public KoColorSpace {
public:
KoColorSpaceAbstract(const QString &id, const QString &name, KoColorSpaceRegistry * parent) : KoColorSpace(id, name, parent) {
KoColorSpaceAbstract(const QString &id, const QString &name, KoColorSpaceRegistry * parent, DWORD cmType,
icColorSpaceSignature colorSpaceSignature) : KoColorSpace(id, name, parent), m_cmType(cmType), m_colorSpaceSignature(colorSpaceSignature) {
this->m_compositeOps.insert( COMPOSITE_COPY, new CompositeCopy( this ) );
m_mixColorsOp = new KoMixColorsOpImpl< _CSTraits>(this);
m_convolutionOp = new KoConvolutionOpImpl< _CSTraits>(this);
};
virtual void setColorSpaceType(quint32 type) { m_cmType = type; }
virtual quint32 colorSpaceType() const { return m_cmType; }
virtual icColorSpaceSignature colorSpaceSignature() const { return m_colorSpaceSignature; }
virtual quint32 colorChannelCount() const { return _CSTraits::channels_nb - 1; }
virtual quint32 channelCount() const { return _CSTraits::channels_nb; };
virtual quint32 pixelSize() const { return _CSTraits::channels_nb * sizeof(typename _CSTraits::channels_type); }
......@@ -297,6 +302,10 @@ class KoColorSpaceAbstract : public KoColorSpace {
protected:
inline const typename _CSTraits::channels_type* nativeArray(const quint8 * a) const { return reinterpret_cast<const typename _CSTraits::channels_type*>(a); }
inline typename _CSTraits::channels_type* nativeArray(quint8 * a) const { return reinterpret_cast<typename _CSTraits::channels_type*>(a); }
private:
DWORD m_cmType; // The colorspace type as defined by littlecms
icColorSpaceSignature m_colorSpaceSignature; // The colorspace signature as defined in icm/icc files
};
......
......@@ -2,16 +2,16 @@
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.bet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
......@@ -21,32 +21,3 @@
#include <KoColorSpaceMaths.h>
#include <KoIntegerMaths.h>
// TODO: use more functions from KoIntegersMaths to do the computation
/// This specialization is needed because the default implementation won't work when scaling up
template<>
quint16 KoColorSpaceMaths<quint8,quint16>::scaleToA(quint8 a)
{
return UINT8_TO_UINT16(a);
}
template<>
quint8 KoColorSpaceMaths<quint8,quint8>::scaleToA(quint8 a)
{
return a;
}
template<>
quint8 KoColorSpaceMaths<quint16,quint8>::scaleToA(quint16 a)
{
return UINT16_TO_UINT8(a);
}
template<>
quint16 KoColorSpaceMaths<quint16,quint16>::scaleToA(quint16 a)
{
return a;
}
......@@ -2,16 +2,16 @@
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.bet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
......@@ -20,13 +20,15 @@
#ifndef KOCOLORSPACEMATHS_H_
#define KOCOLORSPACEMATHS_H_
#include <KoIntegerMaths.h>
template<typename _T>
class KoColorSpaceMathsTraits {
public:
/// @return the maximum value of the channel
inline static qint64 max();
inline static _T max();
/// @return the minimum value of the channel
inline static qint64 min();
inline static _T min();
/// @return the number of bits
inline static qint8 bits();
};
......@@ -35,8 +37,8 @@ template<>
class KoColorSpaceMathsTraits<quint8> {
public:
typedef qint32 compositetype;
inline static qint64 max() { return 0x00FF; }
inline static qint64 min() { return 0; }
inline static quint8 max() { return 0x00FF; }
inline static quint8 min() { return 0; }
inline static qint8 bits() { return 8; }
};
......@@ -44,8 +46,8 @@ template<>
class KoColorSpaceMathsTraits<quint16> {
public:
typedef qint32 compositetype;
inline static qint64 max() { return 0xFFFF; }
inline static qint64 min() { return 0; }
inline static quint16 max() { return 0xFFFF; }
inline static quint16 min() { return 0; }
inline static qint8 bits() { return 16; }
};
......@@ -53,8 +55,8 @@ template<>
class KoColorSpaceMathsTraits<qint16> {
public:
typedef qint32 compositetype;
inline static qint64 max() { return 32767; }
inline static qint64 min() { return -32768; }
inline static qint16 max() { return 32767; }
inline static qint16 min() { return -32768; }
inline static qint8 bits() { return 16; }
};
......@@ -62,11 +64,33 @@ template<>
class KoColorSpaceMathsTraits<quint32> {
public:
typedef qint64 compositetype;
inline static qint64 max() { return 0xFFFFFFFF; }
inline static qint64 min() { return 0; }
inline static quint32 max() { return 0xFFFFFFFF; }
inline static quint32 min() { return 0; }
inline static qint8 bits() { return 32; }
};
// TODO: find someone who understand cmake and understand how to set HAVE_OPENEXR in pigment
#ifdef HAVE_OPENEXR
#include <half.h>
template<>
class KoColorSpaceMathsTraits<half> {
public:
typedef double compositetype;
inline static half max() { return 0.0; }
inline static half min() { return 1.0; }
inline static qint8 bits() { return 16; }
};
#endif
template<>
class KoColorSpaceMathsTraits<double> {
public:
typedef double compositetype;
inline static double max() { return 0.0; }
inline static double min() { return 1.0; }
inline static qint8 bits() { return 32; }
};
template<typename _T, typename _Tdst = _T>
class KoColorSpaceMaths {
......@@ -81,7 +105,7 @@ class KoColorSpaceMaths {
{
return ((traits_compositetype)a * KoColorSpaceMathsTraits<_Tdst>::max() ) / b;
}
inline static _T blend(_T a, _T b, qint64 alpha)
inline static _T blend(_T a, _T b, _T alpha)
{
traits_compositetype c = ( ((traits_compositetype)a - (traits_compositetype)b) * alpha ) >> traits::bits();
return c+b;
......@@ -95,5 +119,116 @@ class KoColorSpaceMaths {
}
};
//------------------------------ double specialization ------------------------------//
template<>
inline quint8 KoColorSpaceMaths<double,quint8>::scaleToA(double a)
{
double v = a * 255;
return (quint8)(CLAMP(v, 0, 255));
}
template<>
inline double KoColorSpaceMaths<quint8,double>::scaleToA(quint8 a)
{
return a * ( 1.0 / 255.0 );
}
template<>
inline quint16 KoColorSpaceMaths<double,quint16>::scaleToA(double a)
{
double v = a * 0xFFFF;
return (quint16)(CLAMP(v, 0, 0xFFFF));
}
template<>
inline double KoColorSpaceMaths<quint16,double>::scaleToA(quint16 a)
{
return a * ( 1.0 / 0xFFFF );
}
template<>
inline double KoColorSpaceMaths<double>::blend(double a, double b, double alpha)
{
return ( a - b) * alpha + b;
}
//------------------------------ half specialization ------------------------------//
// TODO: find someone who understand cmake and understand how to set HAVE_OPENEXR in pigment
#ifdef HAVE_OPENEXR
template<>
inline quint8 KoColorSpaceMaths<half,quint8>::scaleToA(half a)
{
half v = a * 255;
return (quint8)(CLAMP(v, 0, 255));
}
template<>
inline half KoColorSpaceMaths<quint8,half>::scaleToA(quint8 a)
{
return a * ( 1.0 / 255.0 );
}
template<>
inline quint16 KoColorSpaceMaths<half,quint16>::scaleToA(half a)
{
half v = a * 0xFFFF;
return (quint16)(CLAMP(v, 0, 0xFFFF));
}
template<>
inline half KoColorSpaceMaths<quint16,half>::scaleToA(quint16 a)
{
return a * ( 1.0 / 0xFFFF );
}
template<>
inline half KoColorSpaceMaths<half>::blend(half a, half b, half alpha)
{
return ( a - b) * alpha + b;