load.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <memlayer.h>
  14. int
  15. memload(Memimage *dst, Rectangle r, uint8_t *data, int n, int iscompressed)
  16. {
  17. int (*loadfn)(Memimage*, Rectangle, uint8_t*, int);
  18. Memimage *tmp;
  19. Memlayer *dl;
  20. Rectangle lr;
  21. int dx;
  22. loadfn = loadmemimage;
  23. if(iscompressed)
  24. loadfn = cloadmemimage;
  25. Top:
  26. dl = dst->layer;
  27. if(dl == nil)
  28. return loadfn(dst, r, data, n);
  29. /*
  30. * Convert to screen coordinates.
  31. */
  32. lr = r;
  33. r.min.x += dl->delta.x;
  34. r.min.y += dl->delta.y;
  35. r.max.x += dl->delta.x;
  36. r.max.y += dl->delta.y;
  37. dx = dl->delta.x&(7/dst->depth);
  38. if(dl->clear && dx==0){
  39. dst = dl->screen->image;
  40. goto Top;
  41. }
  42. /*
  43. * dst is an obscured layer or data is unaligned
  44. */
  45. if(dl->save && dx==0){
  46. n = loadfn(dl->save, lr, data, n);
  47. if(n > 0)
  48. memlexpose(dst, r);
  49. return n;
  50. }
  51. tmp = allocmemimage(lr, dst->chan);
  52. if(tmp == nil)
  53. return -1;
  54. n = loadfn(tmp, lr, data, n);
  55. memdraw(dst, lr, tmp, lr.min, nil, lr.min, S);
  56. freememimage(tmp);
  57. return n;
  58. }