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 Point memimagestring(Memimage *dst, Point p, Memimage *color,
156 Point cp, Memsubfont *f, char *cs, Drawop op)
160 int iprint(char *fmt, ...)
161 int hwdraw(Memdrawparam *param)
166 type defines memory-resident rectangular pictures and the methods to draw upon them;
172 in that they are manipulated directly in user memory rather than by
178 library is the basis for the kernel
180 driver and also used by a number of programs that must manipulate
181 images without a display.
190 structure elements are identical to
191 the ones of the same name
200 structure holds a number of bits of information about the image.
201 In particular, it subsumes the
209 initializes various static data that the library depends on,
210 as well as the replicated solid color images
216 It should be called before referring to any of these images
217 and before calling any of the other library functions.
223 structure that in turn points at the actual pixel data for the image.
224 This allows multiple images to be associated with the same
226 The first word of the data pointed at by
233 structure, so that in the Plan 9 kernel, the
234 memory allocator (see
235 Plan 9's \fIpool\fR(3))
236 can compact image memory
240 Because images can have different coordinate systems,
245 structure contains the offset that must be added
248 element of the corresponding
250 structure in order to yield a pointer to the data for the pixel (0,0).
254 to this pointer moves it down one scan line.
257 element can be used to determine how to move the
258 pointer horizontally.
259 Note that this method works even for images whose rectangles
260 do not include the origin, although one should only dereference
261 pointers corresponding to pixels within the image rectangle.
265 perform these calculations,
266 returning pointers to the word and byte, respectively,
267 that contain the beginning of the data for a given pixel.
271 images with a given rectangle and channel descriptor
278 structure and associated storage.
280 is similar but uses the supplied
282 structure rather than a new one.
285 function reads an uncompressed bitmap
286 from the given file descriptor,
289 reads a compressed bitmap.
291 writes a compressed representation of
295 For more on bitmap formats, see
298 frees images returned by any of these routines.
301 structure contains some tables that are used
302 to store precomputed values depending on the channel descriptor.
306 element of the structure as well as these tables,
307 returning \-1 if passed a bad channel descriptor.
312 replace the pixel data for a given rectangle of an image
313 with the given buffer of uncompressed or compressed
317 the buffer must contain an
319 compressed chunks of data that exactly cover the rectangle.
321 retrieves the uncompressed pixel data for a given rectangle of an image.
322 All three return the number of bytes consumed on success,
323 and \-1 in case of an error.
326 fills an image with the given color, a 32-bit number as
345 routines described in
347 except that they operate on
352 .IR allocmemsubfont ,
355 .IR memsubfontwidth ,
364 .IR strsubfontwidth ,
371 except that they operate
378 takes the images involved in a draw operation,
379 together with the destination rectangle
382 and mask alignment points
387 clips them according to the clipping rectangles of the images involved.
388 It also fills in the rectangles
392 with rectangles congruent to the returned destination rectangle
393 but translated so the upper left corners are the returned
398 returns zero when the clipped rectangle is empty.
400 returns a conservative bounding box containing a line between
402 with given end styles
405 calculates the extra length added to a line by attaching
406 an end of a given style.
412 functions are no-op stubs that may be overridden by clients
415 is called at each call to
417 with the current request's parameters.
418 If it can satisfy the request, it should do so
420 If it cannot satisfy the request, it should return 0.
421 This allows (for instance) the kernel to take advantage
422 of hardware acceleration.
424 should format and print its arguments;
425 it is given much debugging output when
426 the global integer variable
431 prints to a serial line rather than the screen, for obvious reasons.
433 .B \*9/src/libmemdraw
446 is unusual in using a subfont rather than a font,
447 and in having no parameter to align the source.