blob: 056ac7c2d09de26f814c8d8b009275f4669a8894 (
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
|
#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(u32int));
}
int
bytesperline(Rectangle r, int d)
{
return unitsperline(r, d, 8);
}
|