sent-font

sent: font engine test
git clone git://git.codemadness.org/sent-font
Log | Files | Refs | LICENSE

commit 0798e82d2326fc330168733997006020cc59e215
parent b516f468faa3a80c31932cbcb1ea8ccd1468ffc1
Author: Markus Teich <markus.teich@stusta.mhn.de>
Date:   Tue,  8 Dec 2015 21:46:18 +0100

support transparent images

Diffstat:
sent.c | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/sent.c b/sent.c @@ -215,6 +215,8 @@ int ffread(Image *img) { uint32_t y, x; uint16_t *row; + uint8_t opac; + uint8_t fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; size_t rowlen, off, nbytes; ssize_t r; @@ -239,6 +241,11 @@ int ffread(Image *img) return 0; } + /* extract window background color channels for transparency */ + bg_r = (sc->bg.pix >> 16) % 256; + bg_g = (sc->bg.pix >> 8) % 256; + bg_b = (sc->bg.pix >> 0) % 256; + for (off = 0, y = 0; y < img->bufheight; y++) { nbytes = 0; while (nbytes < rowlen) { @@ -248,9 +255,15 @@ int ffread(Image *img) nbytes += r; } for (x = 0; x < rowlen / 2; x += 4) { - img->buf[off++] = ntohs(row[x + 0]) / 257; - img->buf[off++] = ntohs(row[x + 1]) / 257; - img->buf[off++] = ntohs(row[x + 2]) / 257; + fg_r = ntohs(row[x + 0]) / 256; + fg_g = ntohs(row[x + 1]) / 256; + fg_b = ntohs(row[x + 2]) / 256; + opac = ntohs(row[x + 3]) / 256; + /* blend opaque part of image data with window background color to + * emulate transparency */ + img->buf[off++] = (fg_r * opac + bg_r * (255 - opac)) / 256; + img->buf[off++] = (fg_g * opac + bg_g * (255 - opac)) / 256; + img->buf[off++] = (fg_b * opac + bg_b * (255 - opac)) / 256; } }