KoColorSpace.cpp 4.01 KB
Newer Older
1 2 3
/*
 *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
 *
4 5 6 7
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
13
 *
14 15 16 17 18
 * You should have received a copy of the GNU Library 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.
*/
19

20
#include "KoColorSpace.h"
21
#include "KoCompositeOp.h"
22

23
KoColorSpace::KoColorSpace(const QString &id, const QString &name, KoColorSpaceRegistry * parent)
24
    : m_id(id)
25
    , m_name( name )
26
    , m_parent( parent )
27
{
Laurent Montel's avatar
Laurent Montel committed
28
    //m_dcop = 0;
29 30
}

31
KoColorSpace::~KoColorSpace()
32
{
Laurent Montel's avatar
Laurent Montel committed
33
    //delete m_dcop;
34 35
}

36
quint8 *KoColorSpace::allocPixelBuffer(quint32 numPixels) const
37 38 39 40
{
    return new quint8[pixelSize()*numPixels];
}

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
KoCompositeOpList KoColorSpace::userVisiblecompositeOps() const
{
    return m_compositeOps.values();
}

const KoCompositeOp * KoColorSpace::compositeOp(const QString & id)
{
    if ( m_compositeOps.contains( id ) )
        return m_compositeOps.value( id );
    else
        return m_compositeOps.value( COMPOSITE_OVER );
}

void KoColorSpace::addCompositeOp(const KoCompositeOp * op)
{
    if ( op->colorSpace()->id() == id()) {
        m_compositeOps.insert( op->id(), const_cast<KoCompositeOp*>( op ) );
    }
}


62
bool KoColorSpace::convertPixelsTo(const quint8 * src,
63 64 65 66
                                   quint8 * dst,
                                   KoColorSpace * dstColorSpace,
                                   quint32 numPixels,
                                   qint32 renderingIntent)
67
{
68
    Q_UNUSED(renderingIntent);
69 70 71 72 73 74 75 76 77 78
    // 4 channels: labA, 2 bytes per lab channel
    quint8 *pixels = new quint8[2*4*numPixels];

    toLabA16(src, pixels,numPixels);
    dstColorSpace->fromLabA16(pixels, dst,numPixels);

    delete [] pixels;

    return true;
}
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

void KoColorSpace::bitBlt(quint8 *dst,
                          qint32 dststride,
                          KoColorSpace * srcSpace,
                          const quint8 *src,
                          qint32 srcRowStride,
                          const quint8 *srcAlphaMask,
                          qint32 maskRowStride,
                          quint8 opacity,
                          qint32 rows,
                          qint32 cols,
                          const QString & op,
                          const QBitArray & channelFlags)
{
    if ( m_compositeOps.contains( op ) ) {
        bitBlt(dst, dststride, srcSpace, src, srcRowStride, srcAlphaMask, maskRowStride, opacity, rows, cols, m_compositeOps.value( op ), channelFlags);
    }
    else {
        bitBlt(dst, dststride, srcSpace, src, srcRowStride, srcAlphaMask, maskRowStride, opacity, rows, cols, m_compositeOps.value( COMPOSITE_OVER ), channelFlags);
    }

}

void KoColorSpace::bitBlt(quint8 *dst,
                          qint32 dststride,
                          KoColorSpace * srcSpace,
                          const quint8 *src,
                          qint32 srcRowStride,
                          const quint8 *srcAlphaMask,
                          qint32 maskRowStride,
                          quint8 opacity,
                          qint32 rows,
                          qint32 cols,
                          const QString& op)
{
    if ( m_compositeOps.contains( op ) ) {
        bitBlt(dst, dststride, srcSpace, src, srcRowStride, srcAlphaMask, maskRowStride, opacity, rows, cols, m_compositeOps.value( op ));
    }
    else {
        bitBlt(dst, dststride, srcSpace, src, srcRowStride, srcAlphaMask, maskRowStride, opacity, rows, cols, m_compositeOps.value( COMPOSITE_OVER ) );
    }
}