xref: /inferno-os/libdraw/computil.c (revision 54d06533f3d8d73d9369206f7f5be71351cfbcf3)
137da2899SCharles.Forsyth #include "lib9.h"
237da2899SCharles.Forsyth #include "draw.h"
337da2899SCharles.Forsyth 
437da2899SCharles.Forsyth /*
5*54d06533Sforsyth  * compressed data are sequences of byte codes.
637da2899SCharles.Forsyth  * if the first byte b has the 0x80 bit set, the next (b^0x80)+1 bytes
737da2899SCharles.Forsyth  * are data.  otherwise, it's two bytes specifying a previous string to repeat.
837da2899SCharles.Forsyth  */
937da2899SCharles.Forsyth void
_twiddlecompressed(uchar * buf,int n)1037da2899SCharles.Forsyth _twiddlecompressed(uchar *buf, int n)
1137da2899SCharles.Forsyth {
1237da2899SCharles.Forsyth 	uchar *ebuf;
1337da2899SCharles.Forsyth 	int j, k, c;
1437da2899SCharles.Forsyth 
1537da2899SCharles.Forsyth 	ebuf = buf+n;
1637da2899SCharles.Forsyth 	while(buf < ebuf){
1737da2899SCharles.Forsyth 		c = *buf++;
1837da2899SCharles.Forsyth 		if(c >= 128){
1937da2899SCharles.Forsyth 			k = c-128+1;
2037da2899SCharles.Forsyth 			for(j=0; j<k; j++, buf++)
2137da2899SCharles.Forsyth 				*buf ^= 0xFF;
2237da2899SCharles.Forsyth 		}else
2337da2899SCharles.Forsyth 			buf++;
2437da2899SCharles.Forsyth 	}
2537da2899SCharles.Forsyth }
2637da2899SCharles.Forsyth 
2737da2899SCharles.Forsyth int
_compblocksize(Rectangle r,int depth)2837da2899SCharles.Forsyth _compblocksize(Rectangle r, int depth)
2937da2899SCharles.Forsyth {
3037da2899SCharles.Forsyth 	int bpl;
3137da2899SCharles.Forsyth 
3237da2899SCharles.Forsyth 	bpl = bytesperline(r, depth);
3337da2899SCharles.Forsyth 	bpl = 2*bpl;	/* add plenty extra for blocking, etc. */
3437da2899SCharles.Forsyth 	if(bpl < NCBLOCK)
3537da2899SCharles.Forsyth 		return NCBLOCK;
3637da2899SCharles.Forsyth 	return bpl;
3737da2899SCharles.Forsyth }
38