computil.c 666 B

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