summaryrefslogtreecommitdiff
path: root/sys/src/libdraw/allocimagemix.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libdraw/allocimagemix.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libdraw/allocimagemix.c')
-rwxr-xr-xsys/src/libdraw/allocimagemix.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/sys/src/libdraw/allocimagemix.c b/sys/src/libdraw/allocimagemix.c
new file mode 100755
index 000000000..45e26d14d
--- /dev/null
+++ b/sys/src/libdraw/allocimagemix.c
@@ -0,0 +1,43 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+Image*
+allocimagemix(Display *d, ulong color1, ulong 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;
+ }
+}