#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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5yRt6uIEO1JJZpxP1ssR49H9jtuSPs1DtTkMt5dK3Heth_h9JGg2r3Xvrjr5_1QWEhFMnqQFsCVFsxyvVmortgy-CJ9CEq3xIPKnsI3R5Z857TIKU_6WFP5oTNZnkyL-UBFDx-QIk8iLH/s400/rgb24.gif)
As expected, apply alpha to the red or the green and the intensity diminishes. No blending.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdvEtMVVhZD2hTgqFngGz3rjmM-wfe8YY9_HnZ49QtGgt49fD2jUGoqj8HZZonUKfZjedjS2tU_-x_0VWafjhoPETiwS9fAqsFZclGAjkX7c_nXOMmY8uDgyqM9SvPa-_oencsOr40G5vv/s400/rgb24-alpha.gif)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLYUjXsnmp_wOPhm9xKuAItrbA_uG_-moG3wVIQLdH6GnoNd0FUiGWNPm1Hdd20ou2Ibvtxxh4NDcduRLwBzzWAK7GbtGxSllmrqHvkCRAPP_yluCjut5duum3HKyskOxsnRW2fe6L2Pw2/s400/rgb24-alpha2.gif)
But with RGB24 you can't do Porter-Duff operations. But when you apply alpha to RGBA32 images something unexpected happens :
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiYHd38IQ7Plo5L9Lo9UbtzNenUHeM9vdKLX6zXcIdmb44Ny_AbyQsvzbVTzIgIMObtMcmz_-VZoyH1QWgQXWeiVHpI_1LHZcZaOW7TAJatLP9lMnRC2pfqU7Pp1G7YXQqss68Qy0b9-xj/s400/rgba32-alpha.gif)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYJXCqahqgXaAsRLzPeFoEcvC6-912EyglR1z7YL-HapDSwa9HCYssAEloaluUQqosl6vdGvrESwZEysr0WspQCFMSLRQ45MgWkwuoxUBaPm9At9Oss73wVLwjv2pJtOCnW_3s8yFahc-v/s400/rgba32-alpha2.gif)
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 :
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhISTvIADIEq6PBoYSkLA_ho8UeCLksyidrPvpPP9CYqwnRdO-XMWcCcSn8NVAl7oMTTSWptQkm60BCyuH7BGyRLUf7SZhB6tT21VbuoYdGciXYxvBEv2-1TKTBy197XGmWjPmutRxx1NTR/s400/rgba32-alpha-op.gif)
Green = bd40ff
Red = 7f80ff
I'm afraid it defies my comprehension!
No comments:
Post a Comment