diff --git a/libs/pigment/colorspaces/KoAlphaColorSpace.h b/libs/pigment/colorspaces/KoAlphaColorSpace.h index 4eaf4696fd..0f62a85b47 100644 --- a/libs/pigment/colorspaces/KoAlphaColorSpace.h +++ b/libs/pigment/colorspaces/KoAlphaColorSpace.h @@ -1,243 +1,243 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * 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.1 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 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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KOALPHACOLORSPACE_H #define KOALPHACOLORSPACE_H #include #include "DebugPigment.h" #include "kritapigment_export.h" #include "KoColorSpaceAbstract.h" #include "KoColorSpaceTraits.h" #include "KoColorModelStandardIds.h" #include "KoColorModelStandardIdsUtils.h" #include "KoSimpleColorSpaceFactory.h" #include #ifdef HAVE_OPENEXR #include #endif template class KoColorSpaceMaths; typedef KoColorSpaceTrait AlphaU8Traits; typedef KoColorSpaceTrait AlphaU16Traits; typedef KoColorSpaceTrait AlphaF32Traits; template KoID alphaIdFromChannelType(); template <> inline KoID alphaIdFromChannelType() { return KoID("ALPHA", i18n("Alpha (8-bit integer)")); } template <> inline KoID alphaIdFromChannelType() { return KoID("ALPHAU16", i18n("Alpha (16-bit integer)")); } template <> inline KoID alphaIdFromChannelType() { return KoID("ALPHAF32", i18n("Alpha (32-bit floating point)")); } #ifdef HAVE_OPENEXR typedef KoColorSpaceTrait AlphaF16Traits; template <> inline KoID alphaIdFromChannelType() { return KoID("ALPHAF16", i18n("Alpha (16-bit floating point)")); } #endif class QBitArray; /** * The alpha mask is a special color strategy that treats all pixels as * alpha value with a color common to the mask. The default color is white. */ template class KRITAPIGMENT_EXPORT KoAlphaColorSpaceImpl : public KoColorSpaceAbstract<_CSTrait> { typedef typename _CSTrait::channels_type channels_type; typedef KoColorSpaceMaths _Maths; typedef KoColorSpaceMaths _MathsToU8; typedef KoColorSpaceMaths _MathsFromU8; public: KoAlphaColorSpaceImpl(); ~KoAlphaColorSpaceImpl() override; static QString colorSpaceId() { return alphaIdFromChannelType().id(); } KoID colorModelId() const override { return AlphaColorModelID; } KoID colorDepthId() const override { return colorDepthIdForChannelType(); } virtual KoColorSpace* clone() const; bool willDegrade(ColorSpaceIndependence independence) const override { Q_UNUSED(independence); return false; } bool profileIsCompatible(const KoColorProfile* /*profile*/) const override { return false; } void fromQColor(const QColor& color, quint8 *dst, const KoColorProfile * profile = 0) const override; void toQColor(const quint8 *src, QColor *c, const KoColorProfile * profile = 0) const override; quint8 difference(const quint8 *src1, const quint8 *src2) const override; quint8 differenceA(const quint8 *src1, const quint8 *src2) const override; quint32 colorChannelCount() const override { return 0; } QString channelValueText(const quint8 *pixel, quint32 channelIndex) const override; QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex) const override; virtual void convolveColors(quint8** colors, qreal* kernelValues, quint8 *dst, qreal factor, qreal offset, qint32 nColors, const QBitArray & channelFlags) const; virtual quint32 colorSpaceType() const { return 0; } bool hasHighDynamicRange() const override { return false; } const KoColorProfile* profile() const override { return m_profile; } QImage convertToQImage(const quint8 *data, qint32 width, qint32 height, const KoColorProfile * dstProfile, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const override; void toLabA16(const quint8* src, quint8* dst, quint32 nPixels) const override; void fromLabA16(const quint8* src, quint8* dst, quint32 nPixels) const override; void toRgbA16(const quint8* src, quint8* dst, quint32 nPixels) const override; void fromRgbA16(const quint8* src, quint8* dst, quint32 nPixels) const override; KoColorTransformation* createBrightnessContrastAdjustment(const quint16* transferValues) const override { Q_UNUSED(transferValues); warnPigment << i18n("Undefined operation in the alpha color space"); return 0; } KoColorTransformation* createPerChannelAdjustment(const quint16* const*) const override { warnPigment << i18n("Undefined operation in the alpha color space"); return 0; } KoColorTransformation *createDarkenAdjustment(qint32 , bool , qreal) const override { warnPigment << i18n("Undefined operation in the alpha color space"); return 0; } virtual void invertColor(quint8*, qint32) const { warnPigment << i18n("Undefined operation in the alpha color space"); } void colorToXML(const quint8* , QDomDocument& , QDomElement&) const override { warnPigment << i18n("Undefined operation in the alpha color space"); } void colorFromXML(quint8* , const QDomElement&) const override { warnPigment << i18n("Undefined operation in the alpha color space"); } void toHSY(const QVector &, qreal *, qreal *, qreal *) const override { warnPigment << i18n("Undefined operation in the alpha color space"); } QVector fromHSY(qreal *, qreal *, qreal *) const override { warnPigment << i18n("Undefined operation in the alpha color space"); QVector channelValues (1); channelValues.fill(0.0); return channelValues; } void toYUV(const QVector &, qreal *, qreal *, qreal *) const override { warnPigment << i18n("Undefined operation in the alpha color space"); } QVector fromYUV(qreal *, qreal *, qreal *) const override { warnPigment << i18n("Undefined operation in the alpha color space"); QVector channelValues (1); channelValues.fill(0.0); return channelValues; } protected: bool preferCompositionInSourceColorSpace() const override; private: KoColorProfile* m_profile; QList m_compositeOps; }; typedef KoAlphaColorSpaceImpl KoAlphaColorSpace; typedef KoAlphaColorSpaceImpl KoAlphaU16ColorSpace; #ifdef HAVE_OPENEXR typedef KoAlphaColorSpaceImpl KoAlphaF16ColorSpace; #endif typedef KoAlphaColorSpaceImpl KoAlphaF32ColorSpace; template class KoAlphaColorSpaceFactoryImpl : public KoSimpleColorSpaceFactory { typedef typename _CSTrait::channels_type channels_type; public: KoAlphaColorSpaceFactoryImpl() : KoSimpleColorSpaceFactory(alphaIdFromChannelType().id(), alphaIdFromChannelType().name(), - true, + false, AlphaColorModelID, colorDepthIdForChannelType(), qMin(16, int(sizeof(channels_type) * 8)), // DIRTY HACK ALERT: see a comment below! 100000) { /** * Note about a hack with reference bit depth: right now all the color * conversions to/from Alpha colorspace are done via LabAU16 16-bit color space, * therefore, the conversions are lossy! Better conversions are yet to be implemented, * but for now we just define this color space as having 16-bit reference depth * (the problem arises with AlphaF32 only of course, which is hardly used anywhere). */ } KoColorSpace *createColorSpace(const KoColorProfile *) const override { return new KoAlphaColorSpaceImpl<_CSTrait>(); } QList colorConversionLinks() const override; }; typedef KoAlphaColorSpaceFactoryImpl KoAlphaColorSpaceFactory; typedef KoAlphaColorSpaceFactoryImpl KoAlphaU16ColorSpaceFactory; #ifdef HAVE_OPENEXR typedef KoAlphaColorSpaceFactoryImpl KoAlphaF16ColorSpaceFactory; #endif typedef KoAlphaColorSpaceFactoryImpl KoAlphaF32ColorSpaceFactory; #endif