computil.c 680 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. /*
  5. * compressed data are seuences of byte codes.
  6. * if the first byte b has the 0x80 bit set, the next (b^0x80)+1 bytes
  7. * are data. otherwise, it's two bytes specifying a previous string to repeat.
  8. */
  9. void
  10. _twiddlecompressed(uchar *buf, int n)
  11. {
  12. uchar *ebuf;
  13. int j, k, c;
  14. ebuf = buf+n;
  15. while(buf < ebuf){
  16. c = *buf++;
  17. if(c >= 128){
  18. k = c-128+1;
  19. for(j=0; j<k; j++, buf++)
  20. *buf ^= 0xFF;
  21. }else
  22. buf++;
  23. }
  24. }
  25. int
  26. _compblocksize(Rectangle r, int depth)
  27. {
  28. int bpl;
  29. bpl = bytesperline(r, depth);
  30. bpl = 2*bpl; /* add plenty extra for blocking, etc. */
  31. if(bpl < NCBLOCK)
  32. return NCBLOCK;
  33. return bpl;
  34. }