[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    Re: nativeColor and endianness
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2003-10-22 21:51:04
[Download RAW message or body]

[" " (multipart/signed)]


On Wednesday 22 October 2003 23:46, Patrick Julien wrote:

>
> Nice, can I see?
>

Well, yes... But a) It's untested -- really untested, and b) I'm not sure 
whether I was barking up the right tree, and c) I probably made very silly 
mistakes. But here it is...
-- 
Boudewijn Rempt | http://www.valdyas.org/index2.html

[Attachment #5 (application/pgp-signature)]
["kis_strategy_colorspace_cmyk.cc" (text/x-c++src)]

/*
 *  Copyright (c) 2003 Boudewijn Rempt (boud@valdyas.org)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#include <limits.h>
#include <qimage.h>
#include <qpainter.h>
#include <qpixmap.h>
#include "kis_image.h"
#include "kis_strategy_colorspace_cmyk.h"
#include "tiles/kispixeldata.h"

namespace {
    const Q_INT32 MAX_CHANNEL_CMYK = 4;
    // Is it actually possible to have transparency with CMYK?
    const Q_INT32 MAX_CHANNEL_CMYKA = 5;
}

// Init static data
ColorLUT KisStrategyColorSpaceCMYK::m_rgbLUT = ColorLUT();


KisStrategyColorSpaceCMYK::KisStrategyColorSpaceCMYK() : m_pixmap(RENDER_WIDTH * 2, \
RENDER_HEIGHT * 2) {
    m_buf = new QUANTUM[RENDER_WIDTH * RENDER_HEIGHT * MAX_CHANNEL_CMYKA];
}

KisStrategyColorSpaceCMYK::~KisStrategyColorSpaceCMYK()
{
    delete[] m_buf;
}

void KisStrategyColorSpaceCMYK::nativeColor(const KoColor& c, QUANTUM *dst)
{
    dst[PIXEL_CYAN] = upscale( c.C() );
    dst[PIXEL_MAGENTA] = upscale( c.M() );
    dst[PIXEL_YELLOW] = upscale( c.Y() );
    dst[PIXEL_BLACK] = upscale( c.K() );
}

void KisStrategyColorSpaceCMYK::nativeColor(const KoColor& c, QUANTUM opacity, \
QUANTUM *dst) {
    dst[PIXEL_CYAN] = upscale( c.C() );
    dst[PIXEL_MAGENTA] = upscale( c.M() );
    dst[PIXEL_YELLOW] = upscale( c.Y() );
    dst[PIXEL_BLACK] = upscale( c.K() );
    dst[PIXEL_CMYK_ALPHA] = opacity;
}

void KisStrategyColorSpaceCMYK::nativeColor(const QColor& c, QUANTUM *dst)
{
    KoColor k = KoColor( c );

    dst[PIXEL_CYAN] = upscale( k.C() );
    dst[PIXEL_MAGENTA] = upscale( k.M() );
    dst[PIXEL_YELLOW] = upscale( k.Y() );
    dst[PIXEL_BLACK] = upscale( k.K() );
}

void KisStrategyColorSpaceCMYK::nativeColor(const QColor& c, QUANTUM opacity, QUANTUM \
*dst) {
    KoColor k = KoColor( c );

    dst[PIXEL_CYAN] = upscale( k.C() );
    dst[PIXEL_MAGENTA] = upscale( k.M() );
    dst[PIXEL_YELLOW] = upscale( k.Y() );
    dst[PIXEL_BLACK] = upscale( k.K() );
    dst[PIXEL_CMYK_ALPHA] = opacity;

}

void KisStrategyColorSpaceCMYK::nativeColor(QRgb rgb, QUANTUM *dst)
{
    KoColor k = KoColor(QColor( rgb ));

    dst[PIXEL_CYAN] = upscale( k.C() );
    dst[PIXEL_MAGENTA] = upscale( k.M() );
    dst[PIXEL_YELLOW] = upscale( k.Y() );
    dst[PIXEL_BLACK] = upscale( k.K() );
}

void KisStrategyColorSpaceCMYK::nativeColor(QRgb rgb, QUANTUM opacity, QUANTUM *dst)
{
    KoColor k = KoColor(QColor( rgb ));

    dst[PIXEL_CYAN] = upscale( k.C() );
    dst[PIXEL_MAGENTA] = upscale( k.M() );
    dst[PIXEL_YELLOW] = upscale( k.Y() );
    dst[PIXEL_BLACK] = upscale( k.K() );
    dst[PIXEL_CMYK_ALPHA] = opacity;
}

void KisStrategyColorSpaceCMYK::render(KisImageSP projection, QPainter& painter, \
Q_INT32 x, Q_INT32 y, Q_INT32 width, Q_INT32 height) {
    if (projection) {
        KisTileMgrSP tm = projection -> tiles();
        KisPixelDataSP pd = new KisPixelData;
        QImage img;

        pd -> mgr = 0;
        pd -> tile = 0;
        pd -> mode = TILEMODE_READ;
        pd -> x1 = x;
        pd -> x2 = x + width - 1;
        pd -> y1 = y;
        pd -> y2 = y + height - 1;
        pd -> width = pd -> x2 - pd -> x1 + 1;
        pd -> height = pd -> y2 - pd -> y1 + 1;
        pd -> depth = projection -> depth();
        pd -> stride = pd -> depth * pd -> width;
        pd -> owner = false;
        pd -> data = m_buf;
        tm -> readPixelData(pd);

        img = QImage(pd -> width, pd -> height, pd -> depth * CHAR_BIT, 0, \
QImage::LittleEndian);  img.setAlphaBuffer( true );

        Q_INT32 i = 0;
        uchar *j = img.bits();
        while ( i < pd ->stride * pd -> height ) {
            RGB r;
            // Check in LUT whether k already exists; if so, grab it, else
            CMYK c;
            c.c = *( pd->data + i + PIXEL_CYAN );
            c.m = *( pd->data + i + PIXEL_MAGENTA );
            c.y = *( pd->data + i + PIXEL_YELLOW );
            c.k = *( pd->data + i + PIXEL_BLACK );

            if ( m_rgbLUT.contains ( c ) ) {
                r =  m_rgbLUT[c];
            }
            else {
                // Accessing the rgba of KoColor automatically converts
                // from cmyk to rgb and caches the result
                KoColor k = KoColor(c.c,
                                    c.m,
                                    c.y,
                                    c.k );
                // Store as little as possible
                r.r = k.R();
                r.g = k.G();
                r.b = k.B();

                m_rgbLUT[c] = r;
            }

            // fix the pixel in QImage.

             *( j + PIXEL_ALPHA ) = *( pd->data + i + PIXEL_CMYK_ALPHA );
             *( j + PIXEL_RED ) = r.r;
             *( j + PIXEL_GREEN ) = r.g;
             *( j + PIXEL_BLUE ) = r.b;

             i += MAX_CHANNEL_CMYKA;
             j += 4;

        }
        m_pixio.putImage(&m_pixmap, 0, 0, &img);
        painter.drawPixmap(x, y, m_pixmap, 0, 0, width, height);
    }
}


["kis_strategy_colorspace.h" (text/x-chdr)]

/*
 *  Copyright (c) 2002 Patrick Julien  <freak@codepimps.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#if !defined KIS_STRATEGY_COLORSPACE_H_
#define KIS_STRATEGY_COLORSPACE_H_

#include <qcolor.h>
#include <ksharedptr.h>
#include <koColor.h>
#include "kis_global.h"
#include "kis_types.h"

class QPainter;

class KisStrategyColorSpace : public KShared {
public:
	KisStrategyColorSpace();
	virtual ~KisStrategyColorSpace();

public:
        // The nativeColor methods take a given color and fill *dst with 
        // the tuple that describes the colour for this particular strategy.
        
	virtual void nativeColor(const KoColor& c, QUANTUM *dst) = 0;
	virtual void nativeColor(const KoColor& c, QUANTUM opacity, QUANTUM *dst) = 0;
	virtual void nativeColor(const QColor& c, QUANTUM *dst) = 0;
	virtual void nativeColor(const QColor& c, QUANTUM opacity, QUANTUM *dst) = 0;
	virtual void nativeColor(QRgb rgb, QUANTUM *dst) = 0;
	virtual void nativeColor(QRgb rgb, QUANTUM opacity, QUANTUM *dst) = 0;

	virtual void render(KisImageSP projection, QPainter& painter, Q_INT32 x, Q_INT32 y, \
Q_INT32 width, Q_INT32 height) = 0;

private:
	KisStrategyColorSpace(const KisStrategyColorSpace&);
	KisStrategyColorSpace& operator=(const KisStrategyColorSpace&);
};

#endif // KIS_STRATEGY_COLORSPACE_H_



_______________________________________________
kimageshop mailing list
kimageshop@mail.kde.org
http://mail.kde.org/mailman/listinfo/kimageshop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic