37 hwdraw \- drawing routines for memory-resident images
45 .B #include <memdraw.h>
48 typedef struct Memdata
50 ulong *base; /* allocated data pointer */
51 uchar *bdata; /* first byte of actual data; word-aligned */
52 int ref; /* number of Memimages using this data */
53 void* imref; /* last image that pointed at this */
54 int allocd; /* is this malloc'd? */
58 Frepl = 1<<0, /* is replicated */
59 Fsimple = 1<<1, /* is 1x1 */
60 Fgrey = 1<<2, /* is grey */
61 Falpha = 1<<3, /* has explicit alpha */
62 Fcmap = 1<<4, /* has cmap channel */
63 Fbytes = 1<<5, /* has only 8-bit channels */
66 typedef struct Memimage
68 Rectangle r; /* rectangle in data area, local coords */
69 Rectangle clipr; /* clipping region */
70 int depth; /* number of bits of storage per pixel */
71 int nchan; /* number of channels */
72 ulong chan; /* channel descriptions */
74 Memdata *data; /* pointer to data */
75 int zero; /* data->bdata+zero==&byte containing (0,0) */
76 ulong width; /* width in words of a single scan line */
77 Memlayer *layer; /* nil if not a layer*/
82 typedef struct Memdrawparam
93 .ta \w'\fLMemsubfont* 'u
99 void memimageinit(void)
100 ulong* wordaddr(Memimage *i, Point p)
101 uchar* byteaddr(Memimage *i, Point p)
102 void memimagemove(void *from, void *to)
106 Memimage* allocmemimage(Rectangle r, ulong chan)
107 Memimage* allocmemimaged(Rectangle r, ulong chan, Memdata *data)
108 Memimage* readmemimage(int fd)
109 Memimage* creadmemimage(int fd)
110 int writememimage(int fd, Memimage *i)
111 void freememimage(Memimage *i)
112 int memsetchan(Memimage*, ulong)
116 int loadmemimage(Memimage *i, Rectangle r,
117 uchar *buf, int nbuf)
118 int cloadmemimage(Memimage *i, Rectangle r,
119 uchar *buf, int nbuf)
120 int unloadmemimage(Memimage *i, Rectangle r,
121 uchar *buf, int nbuf)
122 void memfillcolor(Memimage *i, ulong color)
126 void memarc(Memimage *dst, Point c, int a, int b, int thick,
127 Memimage *src, Point sp, int alpha, int phi, Drawop op)
128 void mempoly(Memimage *dst, Point *p, int np, int end0,
129 int end1, int radius, Memimage *src, Point sp, Drawop op)
130 void memellipse(Memimage *dst, Point c, int a, int b,
131 int thick, Memimage *src, Point sp, Drawop op)
132 void memfillpoly(Memimage *dst, Point *p, int np, int wind,
133 Memimage *src, Point sp, Drawop op)
134 void memimageline(Memimage *dst, Point p0, Point p1, int end0,
135 int end1, int radius, Memimage *src, Point sp, Drawop op)
136 void memimagedraw(Memimage *dst, Rectangle r, Memimage *src,
137 Point sp, Memimage *mask, Point mp, Drawop op)
141 int drawclip(Memimage *dst, Rectangle *dr, Memimage *src,
142 Point *sp, Memimage *mask, Point *mp,
143 Rectangle *sr, Rectangle *mr)
144 Rectangle memlinebbox(Point p0, Point p1, int end0, int end1,
146 int memlineendsize(int end)
150 Memsubfont* allocmemsubfont(char *name, int n, int height,
151 int ascent, Fontchar *info, Memimage *i)
152 Memsubfont* openmemsubfont(char *name)
153 void freememsubfont(Memsubfont *f)
154 Point memsubfontwidth(Memsubfont *f, char *s)
155 Memsubfont* getmemdefont(void)
156 Point memimagestring(Memimage *dst, Point p, Memimage *color,
157 Point cp, Memsubfont *f, char *cs, Drawop op)
161 int iprint(char *fmt, ...)
162 int hwdraw(Memdrawparam *param)
167 type defines memory-resident rectangular pictures and the methods to draw upon them;
173 in that they are manipulated directly in user memory rather than by
179 library is the basis for the kernel
181 driver and also used by a number of programs that must manipulate
182 images without a display.
191 structure elements are identical to
192 the ones of the same name
201 structure holds a number of bits of information about the image.
202 In particular, it subsumes the
210 initializes various static data that the library depends on,
211 as well as the replicated solid color images
217 It should be called before referring to any of these images
218 and before calling any of the other library functions.
224 structure that in turn points at the actual pixel data for the image.
225 This allows multiple images to be associated with the same
227 The first word of the data pointed at by
234 structure, so that in the Plan 9 kernel, the
235 memory allocator (see
236 Plan 9's \fIpool\fR(3))
237 can compact image memory
241 Because images can have different coordinate systems,
246 structure contains the offset that must be added
249 element of the corresponding
251 structure in order to yield a pointer to the data for the pixel (0,0).
255 to this pointer moves it down one scan line.
258 element can be used to determine how to move the
259 pointer horizontally.
260 Note that this method works even for images whose rectangles
261 do not include the origin, although one should only dereference
262 pointers corresponding to pixels within the image rectangle.
266 perform these calculations,
267 returning pointers to the word and byte, respectively,
268 that contain the beginning of the data for a given pixel.
272 images with a given rectangle and channel descriptor
279 structure and associated storage.
281 is similar but uses the supplied
283 structure rather than a new one.
286 function reads an uncompressed bitmap
287 from the given file descriptor,
290 reads a compressed bitmap.
292 writes a compressed representation of
296 For more on bitmap formats, see
299 frees images returned by any of these routines.
302 structure contains some tables that are used
303 to store precomputed values depending on the channel descriptor.
307 element of the structure as well as these tables,
308 returning \-1 if passed a bad channel descriptor.
313 replace the pixel data for a given rectangle of an image
314 with the given buffer of uncompressed or compressed
318 the buffer must contain an
320 compressed chunks of data that exactly cover the rectangle.
322 retrieves the uncompressed pixel data for a given rectangle of an image.
323 All three return the number of bytes consumed on success,
324 and \-1 in case of an error.
327 fills an image with the given color, a 32-bit number as
346 routines described in
348 except that they operate on
353 .IR allocmemsubfont ,
356 .IR memsubfontwidth ,
366 .IR strsubfontwidth ,
374 except that they operate
381 takes the images involved in a draw operation,
382 together with the destination rectangle
385 and mask alignment points
390 clips them according to the clipping rectangles of the images involved.
391 It also fills in the rectangles
395 with rectangles congruent to the returned destination rectangle
396 but translated so the upper left corners are the returned
401 returns zero when the clipped rectangle is empty.
403 returns a conservative bounding box containing a line between
405 with given end styles
408 calculates the extra length added to a line by attaching
409 an end of a given style.
415 functions are no-op stubs that may be overridden by clients
418 is called at each call to
420 with the current request's parameters.
421 If it can satisfy the request, it should do so
423 If it cannot satisfy the request, it should return 0.
424 This allows (for instance) the kernel to take advantage
425 of hardware acceleration.
427 should format and print its arguments;
428 it is given much debugging output when
429 the global integer variable
434 prints to a serial line rather than the screen, for obvious reasons.
436 .B \*9/src/libmemdraw
449 is unusual in using a subfont rather than a font,
450 and in having no parameter to align the source.