Update of /cvsroot/q-lang/q/modules/ggi
In directory sc8-pr-cvs1:/tmp/cvs-serv3157
Modified Files:
ggi.c
Log Message:
added proper alpha blending to text rendering
Index: ggi.c
===================================================================
RCS file: /cvsroot/q-lang/q/modules/ggi/ggi.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ggi.c 20 Dec 2003 02:41:44 -0000 1.5
--- ggi.c 20 Dec 2003 11:51:56 -0000 1.6
***************
*** 1308,1311 ****
--- 1308,1312 ----
ggi_color fgcol, bgcol, *col = NULL;
ggi_pixel pix, *pixel = NULL;
+ unsigned fgalpha = 0xff, bgalpha = 0xff;
if (!glyphs) return (l==0);
***************
*** 1377,1391 ****
dim = wd*ht;
! /* FIXME: handle alpha blending */
!
! if (wd > INT_MAX/ht ||
! !(col = malloc(dim*sizeof(ggi_color))))
goto errout;
if (ggiGetGCForeground(vis, &pix) || ggiUnmapPixel(vis, pix, &fgcol))
goto errout;
! fgcol.a = 0xffff;
if (ggiGetGCBackground(vis, &pix) || ggiUnmapPixel(vis, pix, &bgcol))
goto errout;
! bgcol.a = 0xffff;
for (n = 0; n < dim; n++)
col[n] = bgcol;
--- 1378,1398 ----
dim = wd*ht;
! #ifdef HAVE_GGIBUF
! if (v->b[0] && ggiBufGetGCForeground(v->b[0], &fgalpha))
goto errout;
+ if (v->b[0] && ggiBufGetGCBackground(v->b[0], &bgalpha))
+ goto errout;
+ #endif
+ fgalpha *= 0x101;
+ bgalpha *= 0x101;
if (ggiGetGCForeground(vis, &pix) || ggiUnmapPixel(vis, pix, &fgcol))
goto errout;
! fgcol.a = fgalpha;
if (ggiGetGCBackground(vis, &pix) || ggiUnmapPixel(vis, pix, &bgcol))
goto errout;
! bgcol.a = bgalpha;
! if (wd > INT_MAX/ht ||
! !(col = malloc(dim*sizeof(ggi_color))))
! goto errout;
for (n = 0; n < dim; n++)
col[n] = bgcol;
***************
*** 1411,1414 ****
--- 1418,1431 ----
int j = q*w+p;
if (buf[j]) {
+ #if 1
+ /* shades of fg color -- I hope that's the right way to do
+ it? */
+ col[i].r = ((long)fgcol.r)*buf[j]/0xff;
+ col[i].g = ((long)fgcol.g)*buf[j]/0xff;
+ col[i].b = ((long)fgcol.b)*buf[j]/0xff;
+ col[i].a = ((long)fgcol.a)*buf[j]/0xff;
+ #else
+ /* blend fg with bg color -- this looks odd with some fg/bg
+ combinations */
col[i].r = (((long)fgcol.r)*buf[j]+
((long)bgcol.r)*(0xff-buf[j]))/0xff;
***************
*** 1419,1423 ****
--- 1436,1442 ----
col[i].a = (((long)fgcol.a)*buf[j]+
((long)bgcol.a)*(0xff-buf[j]))/0xff;
+ #endif
}
+
}
FT_Done_Glyph(image);
***************
*** 1444,1453 ****
}
- /* clean up */
free(glyphs);
if (!(pixel = malloc(pack_size(v->vis, dim)))) return 0;
! error = ggiPackColors(v->vis, pixel, col, dim) ||
! ggiPutBox(v->vis, x, y, wd, ht, pixel);
free(col);
free(pixel);
--- 1463,1492 ----
}
free(glyphs);
+ /* blit the rendered string to the visual */
+
if (!(pixel = malloc(pack_size(v->vis, dim)))) return 0;
! error = ggiPackColors(v->vis, pixel, col, dim);
! if (!error) {
! #ifdef HAVE_GGIBUF
! if (v->b[0]) {
! /* Ouch! Because of the function call overhead this is fairly slow. We'd
! need something like a ggiBufPutBoxWithAlpha operation here, but
! libggibuf doesn't provide it. :( */
! int i, j;
! ggi_bufval val;
! ggiBufGetGCForeground(v->b[0], &val);
! for (i = 0; i < wd; i++)
! for (j = 0; j < ht; j++) {
! n = j*wd+i;
! ggiBufSetGCForeground(v->b[0], col[n].a/0x101);
! ggiPutPixel(vis, x+i, y+j, pixel[n]);
! }
! ggiBufSetGCForeground(v->b[0], val);
! } else
! #endif
! error = ggiPutBox(v->vis, x, y, wd, ht, pixel);
! }
free(col);
free(pixel);
|