I have an uncompressed RGBA Tiff file
(RGB + alpha channel) which I'm trying to
split into two data files, one containing
the RGB data, and the other
containing the alpha (transparency) data.
Here's a code snippet showing my (probably misguided)
attempt at doing this:
image_read_info< tiff_tag >
info = read_image_info(in, tiff_tag());
if ( info._photometric_interpretation == 2
&& info._samples_per_pixel == 4 ) {
// RGBA
rgba8_image_t
rgba_img;
// Read RGBA image ...
read_image(in, rgba_img, tiff_tag());
// Set up planar image (to extract alpha channel) and rgb image
// (to extract rgb data)
rgba8_planar_image_t
dst_planar_image(rgba_img.dimensions());
rgb8_image_t
dst_rgb_image(rgba_img.dimensions() );
// Convert pixels to appropriate view
copy_and_convert_pixels(view(rgba_img), view(dst_rgb_image));
copy_and_convert_pixels(view(rgba_img), view(dst_planar_image));
// Write out data
ofstream
out((ofilename+"rbg").c_str(), ios_base::binary),
alphaout((ofilename +"alpha").c_str(), ios_base::binary);
out.write(reinterpret_cast<const
char*>(interleaved_view_get_raw_data(view(dst_rgb_image))),
info._width * info._height * 3);
alphaout.write(reinterpret_cast<const
char*>(planar_view_get_raw_data(view(dst_planar_image), 3)),
info._width * info._height);
...
The alpha transparency data is ok as
far as I can see, but the RGB data is
mangled ... presumably I've misunderstood
how the copy_and_convert_pixels() works.
I'm new to the boost::gil library, and am
finding the documentation a little
hard to get to grips with, so any hints
you could give would be greatly appreciated.
Thanks a million in advance!
All the best,
... Corinna
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> The alpha transparency data is ok as
> far as I can see, but the RGB data is
> mangled ... presumably I've misunderstood
> how the copy_and_convert_pixels() works.
The default converter for converting a rgba value into anything will
multiply the alpha value to all other channels. That's why the rgb
data looks incorrect.
I suggest you have your own color converter. Here is some code:
#include <boost/gil/gil_all.hpp>
using namespace boost;
using namespace gil;
class convert_rgba_to_rgb
{
public:
void operator() ( const rgba8_pixel_t& src
, rgb8_pixel_t& dst
) const
{
get_color(dst,red_t()) = get_color(src,red_t());
get_color(dst,green_t()) = get_color(src,green_t());
get_color(dst,blue_t()) = get_color(src,blue_t());
}
};
int main()
{
rgba8_image_t img( 640, 480 );
fill_pixels( view( img ), rgba8_pixel_t( 255, 128, 10, 99 ));
rgba8_planar_image_t dst_planar_image(img.dimensions());
rgb8_image_t dst_rgb_image(img.dimensions() );
copy_and_convert_pixels( view( img ), view( dst_rgb_image ),
convert_rgba_to_rgb() );
rgba8_pixel_t v = *view( img ).xy_at( 0, 0 );
rgb8_pixel_t p = *view( dst_rgb_image ).xy_at( 0, 0 );
return 0;
}
>
> I'm new to the boost::gil library, and am
> finding the documentation a little
> hard to get to grips with, so any hints
> you could give would be greatly appreciated.
>
Let me know if you have some more issues.
Regards,
Christian