summaryrefslogtreecommitdiff
path: root/texture.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-09-11 20:48:13 +0000
committerrodri <rgl@antares-labs.eu>2024-09-11 20:48:13 +0000
commit09ffa3cfc72a10e82c5c68f4010d1c518f0c3328 (patch)
treebe398761d4f406071417a0b021803d494aa90c11 /texture.c
parent8806aad87f7be2d2e82c7db2b9f0978246e5a747 (diff)
downloadlibgraphics-09ffa3cfc72a10e82c5c68f4010d1c518f0c3328.tar.gz
libgraphics-09ffa3cfc72a10e82c5c68f4010d1c518f0c3328.tar.bz2
libgraphics-09ffa3cfc72a10e82c5c68f4010d1c518f0c3328.zip
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.
Diffstat (limited to 'texture.c')
-rw-r--r--texture.c7
1 files changed, 7 insertions, 0 deletions
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;
}