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