Commit acd9e34a authored by Cyrille Berger's avatar Cyrille Berger

remove useless Q_ASSERT(false)

fix toLab/fromLab toRgb/fromRgb in lcms
implement convert toRgb/fromRgb in HDR colorspaces

svn path=/trunk/koffice/; revision=620488
parent e7766808
/*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 2006-2007 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
......@@ -25,6 +25,8 @@
#define UINT8_TO_FLOAT(v) (KoColorSpaceMaths<quint8, typename _CSTraits::channels_type >::scaleToA(v))
#define FLOAT_TO_UINT8(v) (KoColorSpaceMaths<typename _CSTraits::channels_type, quint8>::scaleToA(v))
#define UINT16_TO_FLOAT(v) (KoColorSpaceMaths<quint16, typename _CSTraits::channels_type >::scaleToA(v))
#define FLOAT_TO_UINT16(v) (KoColorSpaceMaths<typename _CSTraits::channels_type, quint16>::scaleToA(v))
template <class _CSTraits>
class KisRgbFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits, KoRGB16Fallback>
......@@ -121,6 +123,24 @@ class KisRgbFloatHDRColorSpace : public KoIncompleteColorSpace<_CSTraits, KoRGB1
src += this->pixelSize();
}
}
virtual void fromRgbA16(const quint8 * srcU8, quint8 * dstU8, const quint32 nPixels) const
{
typename _CSTraits::channels_type* dst = this->nativeArray(dstU8);
const quint16* src = reinterpret_cast<const quint16*>(srcU8);
for(quint32 i = 0; i< 4*nPixels;i++)
{
dst[i] = UINT16_TO_FLOAT(src[i]);
}
}
virtual void toRgbA16(const quint8 * srcU8, quint8 * dstU8, const quint32 nPixels) const
{
const typename _CSTraits::channels_type* src = this->nativeArray(srcU8);
quint16* dst = reinterpret_cast<quint16*>(dstU8);
for(quint32 i = 0; i< 4*nPixels;i++)
{
dst[i] = FLOAT_TO_UINT16(src[i]);
}
}
private:
quint8 convertToDisplay(double value, double exposureFactor, double gamma) const
{
......
......@@ -72,8 +72,7 @@ bool KoColorSpace::convertPixelsTo(const quint8 * src,
{
Q_UNUSED(renderingIntent);
// 4 channels: labA, 2 bytes per lab channel
quint8 *pixels = new quint8[2*4*numPixels];
quint8 *pixels = new quint8[sizeof(quint16)*4*numPixels];
toLabA16(src, pixels,numPixels);
dstColorSpace->fromLabA16(pixels, dst,numPixels);
......
......@@ -138,7 +138,6 @@ class KoRGB16Fallback {
Q_UNUSED(buf);
Q_UNUSED(nPixels);
kFatal() << "THIS FUNCTION SHOULDN'T BE EXECUTED YOU NEED TO REIMPLEMENT fromRgbA16 IN YOUR COLORSPACE" << endl;
Q_ASSERT(false);
}
/**
* Should not be called or that mean the fallback doesn't work
......
......@@ -141,20 +141,20 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {
m_lastFromRGB, TYPE_BGR_8,
INTENT_PERCEPTUAL, 0);
m_defaultFromRGB16 = cmsCreateTransform(m_lastFromRGB, TYPE_BGR_16,
m_defaultFromRGB16 = cmsCreateTransform(m_lastFromRGB, TYPE_BGRA_16,
m_profile->profile(), this->colorSpaceType(),
INTENT_PERCEPTUAL, 0);
m_defaultToRGB16 = cmsCreateTransform(m_profile->profile(), this->colorSpaceType(),
m_lastFromRGB, TYPE_BGR_16,
m_lastFromRGB, TYPE_BGRA_16,
INTENT_PERCEPTUAL, 0);
cmsHPROFILE hLab = cmsCreateLabProfile(NULL);
m_defaultFromLab = cmsCreateTransform(hLab, TYPE_Lab_16, m_profile->profile(), this->colorSpaceType(),
m_defaultFromLab = cmsCreateTransform(hLab, (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)), m_profile->profile(), this->colorSpaceType(),
INTENT_PERCEPTUAL, 0);
m_defaultToLab = cmsCreateTransform(m_profile->profile(), this->colorSpaceType(), hLab, TYPE_Lab_16,
m_defaultToLab = cmsCreateTransform(m_profile->profile(), this->colorSpaceType(), hLab, (COLORSPACE_SH(PT_Lab)|CHANNELS_SH(3)|BYTES_SH(2)|EXTRA_SH(1)),
INTENT_PERCEPTUAL, 0);
}
public:
......@@ -244,6 +244,12 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {
if ( m_defaultToLab == 0 ) return;
cmsDoTransform( m_defaultToLab, const_cast<quint8 *>( src ), dst, nPixels );
quint16* dstU16 = reinterpret_cast<quint16*>(dst);
for(quint32 i = 0; i < nPixels; i++)
{
dstU16[4*i+3] = KoColorSpaceMaths<quint8,quint16>::scaleToA(this->alpha(src));
src += this->pixelSize();
}
}
virtual void fromLabA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
......@@ -251,18 +257,36 @@ class KoLcmsColorSpace : public KoColorSpaceAbstract<_CSTraits> {
if ( m_defaultFromLab == 0 ) return;
cmsDoTransform( m_defaultFromLab, const_cast<quint8 *>( src ), dst, nPixels );
const quint16* srcU16 = reinterpret_cast<const quint16*>(src);
for(quint32 i = 0; i < nPixels; i++)
{
this->setAlpha(dst, KoColorSpaceMaths<quint16,quint8>::scaleToA(srcU16[4*i+3]), 1 );
dst += this->pixelSize();
}
}
virtual void fromRgbA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
{
if ( m_defaultFromRGB16 == 0 ) return;
cmsDoTransform( m_defaultFromRGB16, const_cast<quint8 *>( src ), dst, nPixels );
const quint16* srcU16 = reinterpret_cast<const quint16*>(src);
for(quint32 i = 0; i < nPixels; i++)
{
this->setAlpha(dst, KoColorSpaceMaths<quint16,quint8>::scaleToA(srcU16[4*i+3]), 1 );
dst += this->pixelSize();
}
}
virtual void toRgbA16(const quint8 * src, quint8 * dst, const quint32 nPixels) const
{
if ( m_defaultToRGB16 == 0 ) return;
cmsDoTransform( m_defaultToRGB16, const_cast<quint8 *>( src ), dst, nPixels );
quint16* dstU16 = reinterpret_cast<quint16*>(dst);
for(quint32 i = 0; i < nPixels; i++)
{
dstU16[4*i+3] = KoColorSpaceMaths<quint8,quint16>::scaleToA(this->alpha(src));
src += this->pixelSize();
}
}
virtual bool convertPixelsTo(const quint8 * src,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment