37 hwdraw \- drawing routines for memory-resident images
43 .B #include <memdraw.h>
46 typedef struct Memdata
48 ulong *base; /* allocated data pointer */
49 uchar *bdata; /* first byte of actual data; word-aligned */
50 int ref; /* number of Memimages using this data */
51 void* imref; /* last image that pointed at this */
52 int allocd; /* is this malloc'd? */
56 Frepl = 1<<0, /* is replicated */
57 Fsimple = 1<<1, /* is 1x1 */
58 Fgrey = 1<<2, /* is grey */
59 Falpha = 1<<3, /* has explicit alpha */
60 Fcmap = 1<<4, /* has cmap channel */
61 Fbytes = 1<<5, /* has only 8-bit channels */
64 typedef struct Memimage
66 Rectangle r; /* rectangle in data area, local coords */
67 Rectangle clipr; /* clipping region */
68 int depth; /* number of bits of storage per pixel */
69 int nchan; /* number of channels */
70 ulong chan; /* channel descriptions */
72 Memdata *data; /* pointer to data */
73 int zero; /* data->bdata+zero==&byte containing (0,0) */
74 ulong width; /* width in words of a single scan line */
75 Memlayer *layer; /* nil if not a layer*/
80 typedef struct Memdrawparam
91 .ta \w'\fLMemsubfont* 'u
97 void memimageinit(void)
98 ulong* wordaddr(Memimage *i, Point p)
99 uchar* byteaddr(Memimage *i, Point p)
100 void memimagemove(void *from, void *to)
104 Memimage* allocmemimage(Rectangle r, ulong chan)
105 Memimage* allocmemimaged(Rectangle r, ulong chan, Memdata *data)
106 Memimage* readmemimage(int fd)
107 Memimage* creadmemimage(int fd)
108 int writememimage(int fd, Memimage *i)
109 void freememimage(Memimage *i)
110 int memsetchan(Memimage*, ulong)
114 int loadmemimage(Memimage *i, Rectangle r,
115 uchar *buf, int nbuf)
116 int cloadmemimage(Memimage *i, Rectangle r,
117 uchar *buf, int nbuf)
118 int unloadmemimage(Memimage *i, Rectangle r,
119 uchar *buf, int nbuf)
120 void memfillcolor(Memimage *i, ulong color)
124 void memarc(Memimage *dst, Point c, int a, int b, int thick,
125 Memimage *src, Point sp, int alpha, int phi, Drawop op)
126 void mempoly(Memimage *dst, Point *p, int np, int end0,
127 int end1, int radius, Memimage *src, Point sp, Drawop op)
128 void memellipse(Memimage *dst, Point c, int a, int b,
129 int thick, Memimage *src, Point sp, Drawop op)
130 void memfillpoly(Memimage *dst, Point *p, int np, int wind,
131 Memimage *src, Point sp, Drawop op)
132 void memimageline(Memimage *dst, Point p0, Point p1, int end0,
133 int end1, int radius, Memimage *src, Point sp, Drawop op)
134 void memimagedraw(Memimage *dst, Rectangle r, Memimage *src,
135 Point sp, Memimage *mask, Point mp, Drawop op)
139 int drawclip(Memimage *dst, Rectangle *dr, Memimage *src,
140 Point *sp, Memimage *mask, Point *mp,
141 Rectangle *sr, Rectangle *mr)
142 Rectangle memlinebbox(Point p0, Point p1, int end0, int end1,
144 int memlineendsize(int end)
148 Memsubfont* allocmemsubfont(char *name, int n, int height,
149 int ascent, Fontchar *info, Memimage *i)
150 Memsubfont* openmemsubfont(char *name)
151 void freememsubfont(Memsubfont *f)
152 Point memsubfontwidth(Memsubfont *f, char *s)
153 Memsubfont* getmemdefont(void)
154 Point memimagestring(Memimage *dst, Point p, Memimage *color,
155 Point cp, Memsubfont *f, char *cs)
159 int iprint(char *fmt, ...)
160 int hwdraw(Memdrawparam *param)
165 type defines memory-resident rectangular pictures and the methods to draw upon them;
171 in that they are manipulated directly in user memory rather than by
177 library is the basis for the kernel
179 driver and also used by a number of programs that must manipulate
180 images without a display.
189 structure elements are identical to
190 the ones of the same name
199 structure holds a number of bits of information about the image.
200 In particular, it subsumes the
208 initializes various static data that the library depends on,
209 as well as the replicated solid color images
215 It should be called before referring to any of these images
216 and before calling any of the other library functions.
222 structure that in turn points at the actual pixel data for the image.
223 This allows multiple images to be associated with the same
225 The first word of the data pointed at by
232 structure, so that the
233 memory allocator (see
235 can compact image memory
239 Because images can have different coordinate systems,
244 structure contains the offset that must be added
247 element of the corresponding
249 structure in order to yield a pointer to the data for the pixel (0,0).
253 to this pointer moves it down one scan line.
256 element can be used to determine how to move the
257 pointer horizontally.
258 Note that this method works even for images whose rectangles
259 do not include the origin, although one should only dereference
260 pointers corresponding to pixels within the image rectangle.
264 perform these calculations,
265 returning pointers to the word and byte, respectively,
266 that contain the beginning of the data for a given pixel.
270 images with a given rectangle and channel descriptor
277 structure and associated storage.
279 is similar but uses the supplied
281 structure rather than a new one.
284 function reads an uncompressed bitmap
285 from the given file descriptor,
288 reads a compressed bitmap.
290 writes a compressed representation of
294 For more on bitmap formats, see
297 frees images returned by any of these routines.
300 structure contains some tables that are used
301 to store precomputed values depending on the channel descriptor.
305 element of the structure as well as these tables,
306 returning \-1 if passed a bad channel descriptor.
311 replace the pixel data for a given rectangle of an image
312 with the given buffer of uncompressed or compressed
316 the buffer must contain an
318 compressed chunks of data that exactly cover the rectangle.
320 retrieves the uncompressed pixel data for a given rectangle of an image.
321 All three return the number of bytes consumed on success,
322 and \-1 in case of an error.
325 fills an image with the given color, a 32-bit number as
344 routines described in
346 except that they operate on
351 .IR allocmemsubfont ,
354 .IR memsubfontwidth ,
364 .IR strsubfontwidth ,
372 except that they operate
379 takes the images involved in a draw operation,
380 together with the destination rectangle
383 and mask alignment points
388 clips them according to the clipping rectangles of the images involved.
389 It also fills in the rectangles
393 with rectangles congruent to the returned destination rectangle
394 but translated so the upper left corners are the returned
399 returns zero when the clipped rectangle is empty.
401 returns a conservative bounding box containing a line between
403 with given end styles
406 calculates the extra length added to a line by attaching
407 an end of a given style.
413 functions are no-op stubs that may be overridden by clients
416 is called at each call to
418 with the current request's parameters.
419 If it can satisfy the request, it should do so
421 If it cannot satisfy the request, it should return 0.
422 This allows (for instance) the kernel to take advantage
423 of hardware acceleration.
425 should format and print its arguments;
426 it is given much debugging output when
427 the global integer variable
432 prints to a serial line rather than the screen, for obvious reasons.
434 .B /sys/src/libmemdraw
447 is unusual in using a subfont rather than a font,
448 and in having no parameter to align the source.