Record of some of the computer tech I deal with so that it's documented at least somewhere.

Tuesday 3 March 2009

O, that way madness lies.

Thanks Skip for the title.

#include <u.h>
#include <libc.h>
#include <draw.h>
#include <cursor.h>

Image *col[2];

void
main(void) {
Point zero;
zero.x = 0;
zero.y = 0;

newwindow("-r 0 0 700 300");
if(initdraw(nil, nil, "tri") < 0){
fprint(2, "stats: initdraw failed: %r\n");
exits("initdraw");
}

/* code in the boxes goes here */
col[0] = allocimage(display, Rect(0,0,1,1), RGB24, 1, setalpha(0xFF0000FF, 0xFF));
col[1] = allocimage(display, Rect(0,0,1,1), RGB24, 1, setalpha(0x00FF00FF, 0xFF));
draw(screen, screen->r, col[0], nil, zero);
draw(screen, Rect(0,0,350,150), col[1], nil, zero);
/* to here */

flushimage(display, 1);
sleep(10000);
closedisplay(display);
}


This is the image with no alpha



As expected, apply alpha to the red or the green and the intensity diminishes. No blending.





But with RGB24 you can't do Porter-Duff operations. But when you apply alpha to RGBA32 images something unexpected happens :




I can't work out how that transformation even occurs - The green turns to fd007f, the red to 7f80ff. Where does the blue come from?

If I drawop them too I get :



Green = bd40ff
Red = 7f80ff

I'm afraid it defies my comprehension!

No comments: