Commit 2112a1dc authored by Cyrille Berger's avatar Cyrille Berger

first version of the template based pigment

svn path=/trunk/koffice/; revision=587880
parent b0fe8d2c
......@@ -21,6 +21,7 @@ set(pigment_SRCS
${FILE_OPENEXR_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/colorspaces/KoAlphaColorSpace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/colorspaces/KoLabColorSpace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/colorspaces/KoRgbU32ColorSpace.cpp
)
kde4_automoc(${pigment_SRCS})
......
......@@ -39,6 +39,7 @@ public:
enum enumChannelValueType {
UINT8,
UINT16,
UINT32,
FLOAT16,
FLOAT32,
INT8,
......
......@@ -57,7 +57,7 @@ enum ColorSpaceIndependence {
TO_RGBA8,
TO_RGBA16
};
// TODO: constify all function of KisColorSpace
/**
* A KoColorSpace is the definition of a certain color space.
*
......@@ -106,7 +106,10 @@ public:
//========== Channels =====================================================//
/// Return a vector describing all the channels this color model has.
virtual Q3ValueVector<KoChannelInfo *> channels() const = 0;
virtual Q3ValueVector<KoChannelInfo *> channels() const
{
return m_channels;
}
/**
* The total number of channels for a single pixel in this color model
......
This diff is collapsed.
/*
* 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
* 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.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <KoColorSpaceMaths.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;
}
/*
* 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
* 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.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef 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();
/// @return the minimum value of the channel
inline static qint64 min();
/// @return the number of bits
inline static qint8 bits();
};
template<>
class KoColorSpaceMathsTraits<quint8> {
public:
typedef qint32 compositetype;
inline static qint64 max() { return 0x000F; }
inline static qint64 min() { return 0; }
inline static qint8 bits() { return 8; }
};
template<>
class KoColorSpaceMathsTraits<quint16> {
public:
typedef qint32 compositetype;
inline static qint64 max() { return 0x00FF; }
inline static qint64 min() { return 0; }
inline static qint8 bits() { return 16; }
};
template<>
class KoColorSpaceMathsTraits<qint16> {
public:
typedef qint32 compositetype;
inline static qint64 max() { return 32767; }
inline static qint64 min() { return -32768; }
inline static qint8 bits() { return 16; }
};
template<>
class KoColorSpaceMathsTraits<quint32> {
public:
typedef qint64 compositetype;
inline static qint64 max() { return 0xFFFF; }
inline static qint64 min() { return 0; }
inline static qint8 bits() { return 32; }
};
template<typename _T, typename _Tdst = _T>
class KoColorSpaceMaths {
typedef KoColorSpaceMathsTraits<_T> traits;
typedef typename traits::compositetype traits_compositetype;
public:
inline static _T blend(_T a, _T b, qint64 alpha)
{
traits_compositetype c = ((traits_compositetype)a - (traits_compositetype)b) >> traits::bits();
// return c+b;
}
/**
* This function will scale a value of type _T to fit into a _Tdst.
*/
inline static _Tdst scaleToA(_T a)
{
return (traits_compositetype)a >> ( traits::bits() - KoColorSpaceMathsTraits<_Tdst>::bits() );
}
inline static _T multiply(_T a, _T b)
{
return a * b / traits::max();
}
};
#endif
......@@ -38,6 +38,7 @@
#include "KoColorSpaceRegistry.h"
#include "colorspaces/KoAlphaColorSpace.h"
#include "colorspaces/KoLabColorSpace.h"
#include "colorspaces/KoRgbU32ColorSpace.h"
KoColorSpaceRegistry *KoColorSpaceRegistry::m_singleton = 0;
......@@ -99,6 +100,7 @@ void KoColorSpaceRegistry::init()
KoColorProfile *labProfile = new KoColorProfile(cmsCreateLabProfile(NULL));
addProfile(labProfile);
add(new KoLabColorSpaceFactory());
add(new KoRgbU32ColorSpaceFactory());
/* XXX where to put this
KisHistogramProducerFactoryRegistry::instance()->add(
new KisBasicHistogramProducerFactory<KisBasicU16HistogramProducer>
......
This diff is collapsed.
/*
* 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 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoRgbU32ColorSpace.h"
#include <kdebug.h>
#include <klocale.h>
#include "KoCompositeOp.h"
KoRgbU32ColorSpace::KoRgbU32ColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p) :
KoLcmsColorSpace<quint32,4>("RGBU32", i18n("RGB 32-bit integer/channel)"), parent, 3, TYPE_BGRA_32, icSigRgbData, p)
{
m_channels.push_back(new KoChannelInfo(i18n("Red"), 2, KoChannelInfo::COLOR, KoChannelInfo::UINT32, 4, QColor(255,0,0)));
m_channels.push_back(new KoChannelInfo(i18n("Green"), 1, KoChannelInfo::COLOR, KoChannelInfo::UINT32, 4, QColor(0,255,0)));
m_channels.push_back(new KoChannelInfo(i18n("Blue"), 0, KoChannelInfo::COLOR, KoChannelInfo::UINT32, 4, QColor(0,0,255)));
m_channels.push_back(new KoChannelInfo(i18n("Alpha"), 3, KoChannelInfo::ALPHA, KoChannelInfo::UINT8));
init();
// m_compositeOps.insert( COMPOSITE_OVER, new CompositeOver( this ) );
// m_compositeOps.insert( COMPOSITE_ERASE, new CompositeErase( this ) );
}
bool KoRgbU32ColorSpace::willDegrade(ColorSpaceIndependence independence)
{
if (independence == TO_RGBA8)
return true;
else
return false;
}
/*
* 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 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KORGBU32COLORSPACE_H_
#define KORGBU32COLORSPACE_H_
#include <KoLcmsColorSpace.h>
class KoRgbU32ColorSpace : public KoLcmsColorSpace<quint32,4>
{
public:
KoRgbU32ColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p);
virtual bool willDegrade(ColorSpaceIndependence independence);
};
#define TYPE_BGRA_32 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
class KoRgbU32ColorSpaceFactory : public KoColorSpaceFactory
{
public:
/**
* Krita definition for use in .kra files and internally: unchanging name +
* i18n'able description.
*/
virtual KoID id() const { return KoID("RGBU32", i18n("RGB (32-bit integer/channel)")); };
/**
* lcms colorspace type definition.
*/
virtual quint32 colorSpaceType() { return TYPE_BGRA_32; };
virtual icColorSpaceSignature colorSpaceSignature() { return icSigLabData; };
virtual KoColorSpace *createColorSpace(KoColorSpaceRegistry * parent, KoColorProfile *p) { return new KoRgbU32ColorSpace(parent, p); };
virtual QString defaultProfile() { return "sRGB built-in - (lcms internal)"; };
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment