View Full Version : How to convert clan::Image to grayscale?(clanlib3.0)

01-06-2016, 10:01 AM
How to convert clan::Image to grayscale?(clanlib3.0)

01-08-2016, 08:25 AM
I can't remember ClanLib 3.0 API, but for ClanLib 4.0 you can't do that automatically.

However there can be workarounds
1. Create a GLSL shader to convert the image to greyscale. This is quite tricky, for various reasons. If interested, the HSVSprite does something similar

2. Manually convert the image (in ClanLib 4.0 speak)

clan::PixelBuffer pixels(filename);
(pixels should be in rgba8 format)
clan::Size size = pixels.get_size();
for (int ycnt=0; ycny < size.height; ycnt++)
unsigned int *ptr = pixels.get_line_uint32(ycnt);
for (int xcnt = 0; xcnt < size.width; xcnt++, ptr++)
unsigned char *cptr = (unsigned char *)(ptr);
// NOTE -- I cannot remember the RGBA order in ClanLib 3.0, so these maybe cptr[1], cptr[2] and cptr[3]
int colour = ( cptr[0] + cptr[1] + cptr[2] ) / 6;
cptr[0] = colour;
cptr[1] = colour;
cptr[2] = colour;

clan::Image image(canvas, pixels, size);

Btw, nobody uses these forums any more.

01-14-2016, 06:47 AM
any new forum?

01-14-2016, 11:28 AM

Some developers hang out occasionaly on IRC #clanlib @ freenode.net

All developers don't have any free time. We decided that it's better to concentrate on programming. Thus we dropped the website and ClanLib is now a github project.

It seems to work out better. Developers tune ClanLib to fit their individual needs, thus create their own fork.

The official ClanLib github project https://github.com/sphair/ClanLib API is the best we can get it. There will not be any more major changes in the foresable future.