aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/allocimagemix.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-09-30 17:47:42 +0000
committerrsc <devnull@localhost>2003-09-30 17:47:42 +0000
commited7c8e8d02c02bdbff1e88a6d8d1419f39af48ad (patch)
treeebcd32d20b0df2584bce713fefa87620ecd1cce7 /src/libdraw/allocimagemix.c
parentb2cfc4e2e71d0f0a5113ddfbd93c8285cc4d74e4 (diff)
downloadplan9port-ed7c8e8d02c02bdbff1e88a6d8d1419f39af48ad.tar.gz
plan9port-ed7c8e8d02c02bdbff1e88a6d8d1419f39af48ad.tar.bz2
plan9port-ed7c8e8d02c02bdbff1e88a6d8d1419f39af48ad.zip
Initial import.
Diffstat (limited to 'src/libdraw/allocimagemix.c')
-rw-r--r--src/libdraw/allocimagemix.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/libdraw/allocimagemix.c b/src/libdraw/allocimagemix.c
new file mode 100644
index 00000000..09d60ec9
--- /dev/null
+++ b/src/libdraw/allocimagemix.c
@@ -0,0 +1,43 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+Image*
+allocimagemix(Display *d, u32int color1, u32int color3)
+{
+ Image *t, *b;
+ static Image *qmask;
+
+ if(qmask == nil)
+ qmask = allocimage(d, Rect(0,0,1,1), GREY8, 1, 0x3F3F3FFF);
+
+ if(d->screenimage->depth <= 8){ /* create a 2×2 texture */
+ t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 0, color1);
+ if(t == nil)
+ return nil;
+
+ b = allocimage(d, Rect(0,0,2,2), d->screenimage->chan, 1, color3);
+ if(b == nil){
+ freeimage(t);
+ return nil;
+ }
+
+ draw(b, Rect(0,0,1,1), t, nil, ZP);
+ freeimage(t);
+ return b;
+ }else{ /* use a solid color, blended using alpha */
+ t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color1);
+ if(t == nil)
+ return nil;
+
+ b = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color3);
+ if(b == nil){
+ freeimage(t);
+ return nil;
+ }
+
+ draw(b, b->r, t, qmask, ZP);
+ freeimage(t);
+ return b;
+ }
+}