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