2
* Copyright (c) 2006-2007 Cyrille Berger <cberger@cberger.net>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library 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 GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "CmykU8ColorSpace.h"
22
#include <QDomElement>
27
#include "compositeops/KoCompositeOpOver.h"
28
#include "compositeops/KoCompositeOpErase.h"
29
#include "compositeops/KoCompositeOpMultiply.h"
30
#include "compositeops/KoCompositeOpDivide.h"
31
#include "compositeops/KoCompositeOpBurn.h"
33
CmykU8ColorSpace::CmykU8ColorSpace(KoColorProfile *p) :
34
LcmsColorSpace<CmykU8Traits>("CMYK", i18n("CMYK (8-bit integer/channel)"), TYPE_CMYK5_8, icSigCmykData, p)
36
addChannel(new KoChannelInfo(i18n("Cyan"), 0 * sizeof(quint8), 0, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::cyan));
37
addChannel(new KoChannelInfo(i18n("Magenta"), 1 * sizeof(quint8), 1, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::magenta));
38
addChannel(new KoChannelInfo(i18n("Yellow"), 2 * sizeof(quint8), 2, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::yellow));
39
addChannel(new KoChannelInfo(i18n("Black"), 3 * sizeof(quint8), 3, KoChannelInfo::COLOR, KoChannelInfo::UINT8, sizeof(quint8), Qt::black));
40
addChannel(new KoChannelInfo(i18n("Alpha"), 4 * sizeof(quint8), 4, KoChannelInfo::ALPHA, KoChannelInfo::UINT8, sizeof(quint8)));
43
addCompositeOp(new KoCompositeOpOver<CmykU8Traits>(this));
44
addCompositeOp(new KoCompositeOpErase<CmykU8Traits>(this));
45
addCompositeOp(new KoCompositeOpMultiply<CmykU8Traits>(this));
46
addCompositeOp(new KoCompositeOpDivide<CmykU8Traits>(this));
47
addCompositeOp(new KoCompositeOpBurn<CmykU8Traits>(this));
50
bool CmykU8ColorSpace::willDegrade(ColorSpaceIndependence independence) const
52
if (independence == TO_RGBA8)
58
KoColorSpace* CmykU8ColorSpace::clone() const
60
return new CmykU8ColorSpace(profile()->clone());
63
void CmykU8ColorSpace::colorToXML(const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
65
const CmykU8Traits::Pixel* p = reinterpret_cast<const CmykU8Traits::Pixel*>(pixel);
66
QDomElement labElt = doc.createElement("CMYK");
67
labElt.setAttribute("c", KoColorSpaceMaths< CmykU8Traits::channels_type, qreal>::scaleToA(p->cyan));
68
labElt.setAttribute("m", KoColorSpaceMaths< CmykU8Traits::channels_type, qreal>::scaleToA(p->magenta));
69
labElt.setAttribute("y", KoColorSpaceMaths< CmykU8Traits::channels_type, qreal>::scaleToA(p->yellow));
70
labElt.setAttribute("k", KoColorSpaceMaths< CmykU8Traits::channels_type, qreal>::scaleToA(p->black));
71
labElt.setAttribute("space", profile()->name());
72
colorElt.appendChild(labElt);
75
void CmykU8ColorSpace::colorFromXML(quint8* pixel, const QDomElement& elt) const
77
CmykU8Traits::Pixel* p = reinterpret_cast<CmykU8Traits::Pixel*>(pixel);
78
p->cyan = KoColorSpaceMaths< qreal, CmykU8Traits::channels_type >::scaleToA(elt.attribute("c").toDouble());
79
p->magenta = KoColorSpaceMaths< qreal, CmykU8Traits::channels_type >::scaleToA(elt.attribute("m").toDouble());
80
p->yellow = KoColorSpaceMaths< qreal, CmykU8Traits::channels_type >::scaleToA(elt.attribute("y").toDouble());
81
p->black = KoColorSpaceMaths< qreal, CmykU8Traits::channels_type >::scaleToA(elt.attribute("k").toDouble());
82
p->alpha = KoColorSpaceMathsTraits<quint8>::max;