Boost logo

Boost Users :

Subject: [Boost-users] Generic Image Library and premultiplied RGBA
From: David Warkentin (ev0rtex_at_[hidden])
Date: 2008-10-28 19:33:48


I am trying to take advantage of the convolution capabilities of the
GIL (with the numeric extension of course). I have some text that I
render first using Cairo and then I pass the raw image data along to
the code I'm using with the GIL with some simple glue code. This much
of my code works great - I can write out a PNG using png_write_view
after handing the data off to the library and it contains the rendered
text as I would expect. There is a problem I've encountered, however,
where the anti-aliasing pixels of the white text I have rendered
against a transparent background appear dark and the blurred part of
the text after convolving the image is also dark. I'm pretty sure
this is due to the fact that the raw RGBA data I pass along already
contains premultiplied alpha from Cairo. I'm guessing that the data
is treated as if the alpha has not been premultiplied. I've been
trying to figure out the best way to handle this situation and have
had very little success in getting anything to work. I have recently
been attempting to try one of the 2 things listed in this mailing list
post by Lubomir Bourdev where he gives an example of approaches one
could take to handle premultiplied RGBA data:
http://lists.boost.org/Archives/boost/2006/10/112532.php. No matter
what I try, however, I just keep getting endless compile errors and am
probably going about it all wrong.

Right now I've been trying to do something where I create types to
represent premultiplied RGBA data:

namespace boost {
        namespace gil {

                struct premultiplied_rgba_t : public rgba_t {};

                typedef layout<premultiplied_rgba_t> premultiplied_layout_t;
                typedef pixel<bits8, premultiplied_layout_t> premultiplied_pixel_t;
                typedef image<premultiplied_pixel_t, false> premultiplied_image_t;

        }
}

...so far this has just resulted in compile errors and I can't even
begin to work on any kind of custom color conversion sort of thing
that uses this new type yet (though actually I tried to once and
couldn't make it work either). I'm guessing that what I need to do is
either unmultiply the RGBA data first or I need to somehow get the
library to work correctly with the premultiplied data. Can anyone
help me figure out how to make this work?

David Warkentin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net