Alpha fixed to float (0-1), was: is alpha fixed to 8bit unsigned
Boudewijn Rempt
boud at valdyas.org
Thu Jun 16 10:27:52 CEST 2005
I just stumbled into this myself, in the context of the fill painter. You want
to be able to fill a rect with a certain color and a certain opacity. The
color, if it's a kiscolor, can have an alpha channel, of course (and we
should add an opacity slider to all color selector palettes to support that),
but despite that, it may still be necessary to set an opacity explicity.
Especially when we're talking about patterns, too.
So, what I did was:
void KisFillPainter::fillRect(Q_INT32 x1, Q_INT32 y1, Q_INT32 w, Q_INT32 h,
const KisColor& kc, QUANTUM opacity)
{
Q_INT32 y;
Q_UINT32 depth = m_device->pixelSize();
m_device->colorStrategy()->setAlpha(kc.data(), &opacity, 1);
for (y = y1; y < y1 + h; y++)
{
KisHLineIterator hiter = m_device->createHLineIterator(x1, y,
w, true);
while( ! hiter.isDone())
{
memcpy(hiter.rawData(), src, depth);
++hiter;
}
}
}
And setAlpha is defined as:
void KisStrategyColorSpace::setAlpha(Q_UINT8 * pixels, Q_UINT8 * alpha,
Q_INT32 nPixels) {
// Decide size of pixel
// Determine startpoint of alpha in pixel
// Determine size in bytes of alpha
Q_UINT8 * ptr = pixels;
for (Q_INT32 i = 0; i < nPixels; ++i) {
memcpy(pixels + (i * psize) + alphaPos, alpha, alphaSize);
ptr += psize;
}
}
Or something like this -- this is untested code since I'm at work now and
cannot do more than think a little while my work code is compiling. This
falls through, of course, at the Q_UINT8 * alpha because nothing in Krita can
now how to initialize this value.
What I propose as a solution is to define alpha in Krita outside
colorstrategies as a float with a range from 0 to 1, with 0 transparent and 1
opaque. The colorstrategies can then convert the float value to whatever
floats their own boat.
so:
void KisStrategyColorSpace::setAlpha(Q_UINT8 * pixels, float alpha, Q_INT32
nPixels) {
// Convert alpha to whatever fits the range of this, maybe justa Q_UINT8
// memcpy alpha to the right place in all the given pixels
}
Oh, and by the way: what about premultiplied alpha?
--
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/20050616/29fc4ca4/attachment.pgp
More information about the kimageshop
mailing list