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

List:       kde-kimageshop
Subject:    Inversion in colorspaces
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2005-10-23 19:06:23
Message-ID: 200510232106.26669.boud () valdyas ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


This turns out to be quite a fun topic... I haven't got it working completely. 
16-bit rgba works perfectly, but, for 8-bit rgb, I get a blank image back if 
I go through xyz (I will add an optimized 8-bit rgb function later, but this 
is for testing). I'm not sure why, maybe someone else has an idea. This is 
the code:

void KisAbstractColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
    if ( m_defaultToXYZ != 0 && m_defaultFromXYZ != 0 ) {
        KisColorSpace * xyz = m_parent->getXYZ16();
        
        Q_UINT32 psize = xyz->pixelSize();

        if ( m_conversionCache.size() < nPixels * psize ) {
            m_conversionCache.resize( nPixels * psize, QGArray::SpeedOptim );
        }

        cmsDoTransform( m_defaultToXYZ, const_cast<Q_UINT8*>( src ), 
m_conversionCache.data(), nPixels);
        xyz->invertColor(m_conversionCache.data(), nPixels);
        cmsDoTransform( m_defaultFromXYZ, m_conversionCache.data(), 
const_cast<Q_UINT8*>( src ), nPixels);
    }
    else {
	...
    }
}

The transforms to and back XYZ work, I tested that by commenting out the call 
to xyz->invertColor(). 

void KisXyzColorSpace::invertColor(Q_UINT8 * src, Q_INT32 nPixels)
{
    Q_INT32 pSize = pixelSize();
    
    while (nPixels--)
    {
        Q_UINT16 * p = reinterpret_cast<Q_UINT16 *>(src);
        p[PIXEL_X] = UINT16_MAX - p[PIXEL_X];
        p[PIXEL_Y] = UINT16_MAX - p[PIXEL_Y];
        p[PIXEL_Z] = UINT16_MAX - p[PIXEL_Z];
        src += pSize;
    }
}

An example of the xyz values before and after inverting:

krita: Before X 2860, Y 3377, z 2426
krita: After X 62675, Y 62158, z 63109

Looks good, so everything should work... But it doesnt :-(.

Anyway, there's also the intriguing mention of building an inversion lut in 
the lcms documentation, but I don't understand it at all... Perhaps Casper 
can take a look at that?


-- 
Boudewijn Rempt 
http://www.valdyas.org/fading/index.cgi

[Attachment #5 (application/pgp-signature)]

_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://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