This commit is contained in:
Russ Cox
2005-08-08 12:50:13 +00:00
parent 0189e66e88
commit 934846f35c
382 changed files with 62614 additions and 0 deletions

34
libdraw/bytesperline.c Normal file
View File

@@ -0,0 +1,34 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
static
int
unitsperline(Rectangle r, int d, int bitsperunit)
{
ulong l, t;
if(d <= 0 || d > 32) /* being called wrong. d is image depth. */
abort();
if(r.min.x >= 0){
l = (r.max.x*d+bitsperunit-1)/bitsperunit;
l -= (r.min.x*d)/bitsperunit;
}else{ /* make positive before divide */
t = (-r.min.x*d+bitsperunit-1)/bitsperunit;
l = t+(r.max.x*d+bitsperunit-1)/bitsperunit;
}
return l;
}
int
wordsperline(Rectangle r, int d)
{
return unitsperline(r, d, 8*sizeof(ulong));
}
int
bytesperline(Rectangle r, int d)
{
return unitsperline(r, d, 8);
}