plan9port/src/libdraw/allocimagemix.c
2003-09-30 17:47:42 +00:00

43 lines
926 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}
}