~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to plugins/colorengines/lcms/colorspaces/cmyk_u8/CmykU8ColorSpace.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2006-2007 Cyrille Berger <cberger@cberger.net>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
*/
 
19
 
 
20
#include "CmykU8ColorSpace.h"
 
21
 
 
22
#include <QDomElement>
 
23
 
 
24
#include <kdebug.h>
 
25
#include <klocale.h>
 
26
 
 
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"
 
32
 
 
33
CmykU8ColorSpace::CmykU8ColorSpace(KoColorProfile *p) :
 
34
        LcmsColorSpace<CmykU8Traits>("CMYK", i18n("CMYK (8-bit integer/channel)"),  TYPE_CMYK5_8, icSigCmykData, p)
 
35
{
 
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)));
 
41
    init();
 
42
 
 
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));
 
48
}
 
49
 
 
50
bool CmykU8ColorSpace::willDegrade(ColorSpaceIndependence independence) const
 
51
{
 
52
    if (independence == TO_RGBA8)
 
53
        return true;
 
54
    else
 
55
        return false;
 
56
}
 
57
 
 
58
KoColorSpace* CmykU8ColorSpace::clone() const
 
59
{
 
60
    return new CmykU8ColorSpace(profile()->clone());
 
61
}
 
62
 
 
63
void CmykU8ColorSpace::colorToXML(const quint8* pixel, QDomDocument& doc, QDomElement& colorElt) const
 
64
{
 
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);
 
73
}
 
74
 
 
75
void CmykU8ColorSpace::colorFromXML(quint8* pixel, const QDomElement& elt) const
 
76
{
 
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;
 
83
}
 
84