KoColorDisplayRendererInterface.cpp 2.8 KB
Newer Older
1 2 3
/*
 *  Copyright (c) 2014 Dmitry Kazakov <dimula73@gmail.com>
 *
4 5 6 7
 * 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.
8
 *
9 10 11 12
 * 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.
13
 *
14 15 16 17
 * 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.
18 19 20 21
 */

#include "KoColorDisplayRendererInterface.h"

22
#include <QGlobalStatic>
23

24
#include <KoColorSpaceRegistry.h>
25
#include <KoChannelInfo.h>
26 27
#include <KoColorConversionTransformation.h>
#include <KoColorSpace.h>
28

29
Q_GLOBAL_STATIC(KoDumbColorDisplayRenderer, s_instance)
30 31 32 33 34 35 36 37 38

KoColorDisplayRendererInterface::KoColorDisplayRendererInterface()
{
}

KoColorDisplayRendererInterface::~KoColorDisplayRendererInterface()
{
}

39 40 41 42 43
QImage KoDumbColorDisplayRenderer::convertToQImage(const KoColorSpace *srcColorSpace, const quint8 *data, qint32 width, qint32 height) const
{
    return srcColorSpace->convertToQImage(data, width, height, 0, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
}

44 45 46 47 48
QColor KoDumbColorDisplayRenderer::toQColor(const KoColor &c) const
{
    return c.toQColor();
}

49 50 51 52 53 54 55
KoColor KoDumbColorDisplayRenderer::approximateFromRenderedQColor(const QColor &c) const
{
    KoColor color;
    color.fromQColor(c);
    return color;
}

56 57
KoColor KoDumbColorDisplayRenderer::fromHsv(int h, int s, int v, int a) const
{
58 59 60 61
    h = qBound(0, h, 359);
    s = qBound(0, s, 255);
    v = qBound(0, v, 255);
    a = qBound(0, a, 255);
62
    QColor qcolor(QColor::fromHsv(h, s, v, a));
63 64 65 66 67 68 69 70 71
    return KoColor(qcolor, KoColorSpaceRegistry::instance()->rgb8());
}

void KoDumbColorDisplayRenderer::getHsv(const KoColor &srcColor, int *h, int *s, int *v, int *a) const
{
    QColor qcolor = toQColor(srcColor);
    qcolor.getHsv(h, s, v, a);
}

72 73 74 75 76
KoColorDisplayRendererInterface* KoDumbColorDisplayRenderer::instance()
{
    return s_instance;
}

77
qreal KoDumbColorDisplayRenderer::minVisibleFloatValue(const KoChannelInfo *chaninfo) const
78
{
79 80
    Q_ASSERT(chaninfo);
    return chaninfo->getUIMin();
81 82
}

83
qreal KoDumbColorDisplayRenderer::maxVisibleFloatValue(const KoChannelInfo *chaninfo) const
84
{
85 86
    Q_ASSERT(chaninfo);
    return chaninfo->getUIMax();
87
}
88 89 90 91 92

const KoColorSpace* KoDumbColorDisplayRenderer::getPaintingColorSpace() const
{
    return KoColorSpaceRegistry::instance()->rgb8();
}