Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <draw.h>
4
 
5
Image*
6
allocimagemix(Display *d, ulong color1, ulong color3)
7
{
8
	Image *t, *b;
9
	static Image *qmask;
10
 
11
	if(qmask == nil)
12
		qmask = allocimage(d, Rect(0,0,1,1), GREY8, 1, 0x3F3F3FFF);
13
 
14
	if(d->screenimage->depth <= 8){	/* create a 2×2 texture */
15
		t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 0, color1);
16
		if(t == nil)
17
			return nil;
18
 
19
		b = allocimage(d, Rect(0,0,2,2), d->screenimage->chan, 1, color3);
20
		if(b == nil){
21
			freeimage(t);
22
			return nil;
23
		}
24
 
25
		draw(b, Rect(0,0,1,1), t, nil, ZP);
26
		freeimage(t);
27
		return b;
28
	}else{	/* use a solid color, blended using alpha */
29
		t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color1);
30
		if(t == nil)
31
			return nil;
32
 
33
		b = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color3);
34
		if(b == nil){
35
			freeimage(t);
36
			return nil;
37
		}
38
 
39
		draw(b, b->r, t, qmask, ZP);
40
		freeimage(t);
41
		return b;
42
	}
43
}