allocimagemix.c 924 B

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