Inversion in colorspaces

Boudewijn Rempt boud at valdyas.org
Sun Oct 23 21:06:23 CEST 2005


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kimageshop/attachments/20051023/fdda0cf3/attachment.pgp


More information about the kimageshop mailing list