tbytesperline.c - plan9port - [fork] Plan 9 from user space | |
git clone git://src.adamsgaard.dk/plan9port | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
tbytesperline.c (618B) | |
--- | |
1 #include <u.h> | |
2 #include <libc.h> | |
3 #include <draw.h> | |
4 | |
5 static | |
6 int | |
7 unitsperline(Rectangle r, int d, int bitsperunit) | |
8 { | |
9 ulong l, t; | |
10 | |
11 if(d <= 0 || d > 32) /* being called wrong. d is image d… | |
12 abort(); | |
13 | |
14 if(r.min.x >= 0){ | |
15 l = (r.max.x*d+bitsperunit-1)/bitsperunit; | |
16 l -= (r.min.x*d)/bitsperunit; | |
17 }else{ /* make positive before divide */ | |
18 t = (-r.min.x*d+bitsperunit-1)/bitsperunit; | |
19 l = t+(r.max.x*d+bitsperunit-1)/bitsperunit; | |
20 } | |
21 return l; | |
22 } | |
23 | |
24 int | |
25 wordsperline(Rectangle r, int d) | |
26 { | |
27 return unitsperline(r, d, 8*sizeof(u32int)); | |
28 } | |
29 | |
30 int | |
31 bytesperline(Rectangle r, int d) | |
32 { | |
33 return unitsperline(r, d, 8); | |
34 } |