File: balloc.3

package info (click to toggle)
sam 4.3-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,416 kB
  • ctags: 1,660
  • sloc: ansic: 14,329; makefile: 204; sh: 189
file content (140 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
.TH BALLOC 3G
.SH NAME
balloc, bfree, rdbitmap, wrbitmap, rdbitmapfile, wrbitmapfile \- allocating, freeing, reading, writing bitmaps
.SH SYNOPSIS
.nf
.PP
.B
#include <libc.h>
.B
#include <libg.h>
.PP
.ta \w'\fLBitmap 'u
.B
Bitmap	*balloc(Rectangle r, int ldepth)
.PP
.B
void	bfree(Bitmap *b)
.PP
.B
void	rdbitmap(Bitmap *b, int miny, int maxy, uchar *data)
.PP
.B
void	wrbitmap(Bitmap *b, int miny, int maxy, uchar *data)
.PP
.B
Bitmap	*rdbitmapfile(int fd)
.PP
.B
void	wrbitmapfile(int fd, Bitmap *b)
.SH DESCRIPTION
A new bitmap is allocated with
.BR balloc ;
it will have the extent and depth given by its arguments,
and will be filled with zeros. The
.I id
field contains the handle of the X
.B Pixmap
associated with the bitmap
and the
.I cache
field is zero.
.I Balloc
returns 0 if the server has run out of bitmap resources.
.B Bfree
frees the resources used by its argument bitmap.
.PP
The remaining functions deal with moving groups of pixel
values between bitmaps and user space or external files.
There is a fixed format for the bitmap data in user space or on
external files.
A pixel with x-coordinate =
.I x
in a bitmap with
.B ldepth
=
.I l
will appear as
.if t \fIw\fP = 2\u\s8\fIl\fP\s10\d
.if n w = 2^l
contiguous bits in a byte, with the pixel's high order bit
starting at the byte's bit number
.if t \fIw\fP\(mu(\fIx\fP mod 8/\fIw\fP),
.if n w*(x mod 8/w),
where bits within a byte are numbered 0 to 7 from the
high order to the low order bit.
If
.I w
is greater than 8, it is a multiple of 8, so
pixel values take up an integral number of bytes.
A
.I row
of bitmap
.I b
consists of the byte containing pixel
.IB b .r.min.x
and all the bytes up to and including the byte containing pixel
.IB b .r.max.x\fR\(mi1.
.PP
.I Rdbitmap
reads rows of pixels from bitmap
.I b
into
.IR data .
The rows read have
.IR y = ymin , ymin "+1, ... "
.IR ymax \(mi1.
Those rows must be within the range allowed by
.IB b .r.
.PP
.B Wrbitmap
replaces the specified rows of pixels in bitmap
.I b
with
.IR data .
.PP
.I Rdbitmapfile
creates a bitmap from data contained an external file;
.I fd
should be a file descriptor obtained by opening such a file for reading.
The external file should start with 5 ASCII integers:
.BR ldepth ,
.BR r.min.x ,
.BR r.min.y ,
.BR r.max.x ,
and
.BR r.max.y .
Each number is right-justified in 11 characters, followed by a blank.
The rows of bitmap data, formatted as described above,
follow the header.
The returned bitmap is allocated using
.I balloc .
.I Rdbitmapfile
returns 0 if the server has run out of bitmap resources.
.PP
.I Wrbitmapfile
writes bitmap
.I b
onto file descriptor
.IR fd ,
which should be open for writing.
The format is as just described for
.IR rdbitmapfile .
.PP
.I Rdbitmapfile
and
.I wrbitmapfile
don't close
.IR fd .
.PP
.SH DIAGNOSTICS
Some errors can occur when accessing the internal bitmaps,
when trying to malloc, or when trying to read or write the
argument file descriptors;
the graphics error function (see
.IR graphics (3g))
is called when this happens.
.SH "SEE ALSO"
.IR bitmap (7g),
.IR graphics (3g),
.IR bitblt (3g).