2
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
#include <GrayU8ColorSpace.h>
20
#include <QDomElement>
25
#include <KoIntegerMaths.h>
26
#include <KoColorSpaceRegistry.h>
28
#include "compositeops/KoCompositeOpOver.h"
29
#include "compositeops/KoCompositeOpErase.h"
30
#include "compositeops/KoCompositeOpMultiply.h"
31
#include "compositeops/KoCompositeOpDivide.h"
32
#include "compositeops/KoCompositeOpBurn.h"
34
KoGrayAU8ColorSpace ::KoGrayAU8ColorSpace(KoColorProfile *p) :
35
LcmsColorSpace<GrayAU8Traits>("GRAYA", i18n("Grayscale (8-bit integer/channel)"), TYPE_GRAYA_8, icSigGrayData, p)
37
addChannel(new KoChannelInfo(i18n("Gray"), 0, 0, KoChannelInfo::COLOR, KoChannelInfo::UINT8));
38
addChannel(new KoChannelInfo(i18n("Alpha"), 1, 1, KoChannelInfo::ALPHA, KoChannelInfo::UINT8));
42
addCompositeOp(new KoCompositeOpOver<GrayAU8Traits>(this));
43
addCompositeOp(new KoCompositeOpErase<GrayAU8Traits>(this));
44
addCompositeOp(new KoCompositeOpMultiply<GrayAU8Traits>(this));
45
addCompositeOp(new KoCompositeOpDivide<GrayAU8Traits>(this));
46
addCompositeOp(new KoCompositeOpBurn<GrayAU8Traits>(this));
49
KoColorSpace* KoGrayAU8ColorSpace::clone() const
51
return new KoGrayAU8ColorSpace(profile()->clone());
54
void KoGrayAU8ColorSpace::colorToXML(const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
56
const GrayAU8Traits::channels_type* p = reinterpret_cast<const GrayAU8Traits::channels_type*>(pixel);
57
QDomElement labElt = doc.createElement("Gray");
58
labElt.setAttribute("g", KoColorSpaceMaths< GrayAU8Traits::channels_type, qreal>::scaleToA(p[0]));
59
labElt.setAttribute("space", profile()->name());
60
colorElt.appendChild(labElt);
63
void KoGrayAU8ColorSpace::colorFromXML(quint8* pixel, const QDomElement& elt) const
65
GrayAU8Traits::channels_type* p = reinterpret_cast<GrayAU8Traits::channels_type*>(pixel);
66
p[0] = KoColorSpaceMaths< qreal, GrayAU8Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
67
p[1] = KoColorSpaceMathsTraits<quint8>::max;