allocimagemix.c 844 B

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