aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/computil.c
blob: b1dc2999b9d2145a4d9a17fb7f882fbf18dfe99c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <u.h>
#include <libc.h>
#include <draw.h>

/*
 * compressed data are seuences of byte codes.
 * if the first byte b has the 0x80 bit set, the next (b^0x80)+1 bytes
 * are data.  otherwise, it's two bytes specifying a previous string to repeat.
 */
void
_twiddlecompressed(uchar *buf, int n)
{
	uchar *ebuf;
	int j, k, c;

	ebuf = buf+n;
	while(buf < ebuf){
		c = *buf++;
		if(c >= 128){
			k = c-128+1;
			for(j=0; j<k; j++, buf++)
				*buf ^= 0xFF;
		}else
			buf++;
	}
}

int
_compblocksize(Rectangle r, int depth)
{
	int bpl;

	bpl = bytesperline(r, depth);
	bpl = 2*bpl;	/* add plenty extra for blocking, etc. */
	if(bpl < NCBLOCK)
		return NCBLOCK;
	return bpl;
}