From 09ffa3cfc72a10e82c5c68f4010d1c518f0c3328 Mon Sep 17 00:00:00 2001 From: rodri Date: Wed, 11 Sep 2024 20:48:13 +0000 Subject: change the raster format to RGBA32. draw to any image format. clean up. got rid of the bullshit dance between XRGB32 and RGBA32, now all rasters are RGBA32 and premultiply alpha before loading up an image and drawing over the destination. this lets the user compose their own scenes with correct transparency. no more mediocre clearcolor. as a consequence drawing got slower, but if i get the turbo drawing pool working properly that should go away. textures also take alpha pre-multiplied channels into account, dividing them when sampling, so loading transparent textures will show the correct colors. --- texture.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'texture.c') diff --git a/texture.c b/texture.c index 5d04b89..df5089a 100644 --- a/texture.c +++ b/texture.c @@ -48,6 +48,7 @@ _memreadcolor(Texture *t, Point sp) uchar cbuf[4]; switch(t->image->chan){ + default: sysfatal("unsupported texture format"); case RGB24: unloadmemimage(t->image, rectaddpt(UR, sp), cbuf+1, sizeof cbuf - 1); cbuf[0] = 0xFF; @@ -63,6 +64,12 @@ _memreadcolor(Texture *t, Point sp) } c = cbuf2col(cbuf); + /* remove pre-multiplied alpha */ + if(hasalpha(t->image->chan) && c.a > 0 && c.a < 1){ + c.r /= c.a; + c.g /= c.a; + c.b /= c.a; + } switch(t->type){ case sRGBTexture: c = srgb2linear(c); break; } -- cgit v1.2.3