computil.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /*
  13. * compressed data are seuences of byte codes.
  14. * if the first byte b has the 0x80 bit set, the next (b^0x80)+1 bytes
  15. * are data. otherwise, it's two bytes specifying a previous string to repeat.
  16. */
  17. void
  18. _twiddlecompressed(uint8_t *buf, int n)
  19. {
  20. uint8_t *ebuf;
  21. int j, k, c;
  22. ebuf = buf+n;
  23. while(buf < ebuf){
  24. c = *buf++;
  25. if(c >= 128){
  26. k = c-128+1;
  27. for(j=0; j<k; j++, buf++)
  28. *buf ^= 0xFF;
  29. }else
  30. buf++;
  31. }
  32. }
  33. int
  34. _compblocksize(Rectangle r, int depth)
  35. {
  36. int bpl;
  37. bpl = bytesperline(r, depth);
  38. bpl = 2*bpl; /* add plenty extra for blocking, etc. */
  39. if(bpl < NCBLOCK)
  40. return NCBLOCK;
  41. return bpl;
  42. }