allocimagemix.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. Image*
  13. allocimagemix(Display *d, uint32_t color1, uint32_t color3)
  14. {
  15. Image *t, *b;
  16. static Image *qmask;
  17. if(qmask == nil)
  18. qmask = allocimage(d, Rect(0,0,1,1), GREY8, 1, 0x3F3F3FFF);
  19. if(d->screenimage->depth <= 8){ /* create a 2×2 texture */
  20. t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 0, color1);
  21. if(t == nil)
  22. return nil;
  23. b = allocimage(d, Rect(0,0,2,2), d->screenimage->chan, 1, color3);
  24. if(b == nil){
  25. freeimage(t);
  26. return nil;
  27. }
  28. draw(b, Rect(0,0,1,1), t, nil, ZP);
  29. freeimage(t);
  30. return b;
  31. }else{ /* use a solid color, blended using alpha */
  32. t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color1);
  33. if(t == nil)
  34. return nil;
  35. b = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color3);
  36. if(b == nil){
  37. freeimage(t);
  38. return nil;
  39. }
  40. draw(b, b->r, t, qmask, ZP);
  41. freeimage(t);
  42. return b;
  43. }
  44. }