multichan.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include <memdraw.h>
  13. #include <bio.h>
  14. #include "imagefile.h"
  15. /* Separate colors, if not a grey scale or bitmap, into one byte per color per pixel, no alpha or X */
  16. /* Result is GREY[1248] or RGB24 */
  17. static
  18. int
  19. notrans(uint32_t chan)
  20. {
  21. switch(chan){
  22. case GREY1:
  23. case GREY2:
  24. case GREY4:
  25. case GREY8:
  26. case RGB24:
  27. return 1;
  28. }
  29. return 0;
  30. }
  31. Image*
  32. multichan(Image *i)
  33. {
  34. Image *ni;
  35. if(notrans(i->chan))
  36. return i;
  37. ni = allocimage(display, i->r, RGB24, 0, DNofill);
  38. if(ni == nil)
  39. return ni;
  40. draw(ni, ni->r, i, nil, i->r.min);
  41. return ni;
  42. }
  43. Memimage*
  44. memmultichan(Memimage *i)
  45. {
  46. Memimage *ni;
  47. if(notrans(i->chan))
  48. return i;
  49. ni = allocmemimage(i->r, RGB24);
  50. if(ni == nil)
  51. return ni;
  52. memimagedraw(ni, ni->r, i, i->r.min, nil, i->r.min, S);
  53. return ni;
  54. }