38 hwdraw \- drawing routines for memory-resident images
44 .B #include <memdraw.h>
47 typedef struct Memdata
49 ulong *base; /* allocated data pointer */
50 uchar *bdata; /* first byte of actual data; word-aligned */
51 int ref; /* number of Memimages using this data */
52 void* imref; /* last image that pointed at this */
53 int allocd; /* is this malloc'd? */
57 Frepl = 1<<0, /* is replicated */
58 Fsimple = 1<<1, /* is 1x1 */
59 Fgrey = 1<<2, /* is grey */
60 Falpha = 1<<3, /* has explicit alpha */
61 Fcmap = 1<<4, /* has cmap channel */
62 Fbytes = 1<<5, /* has only 8-bit channels */
65 typedef struct Memimage
67 Rectangle r; /* rectangle in data area, local coords */
68 Rectangle clipr; /* clipping region */
69 int depth; /* number of bits of storage per pixel */
70 int nchan; /* number of channels */
71 ulong chan; /* channel descriptions */
73 Memdata *data; /* pointer to data */
74 int zero; /* data->bdata+zero==&byte containing (0,0) */
75 ulong width; /* width in words of a single scan line */
76 Memlayer *layer; /* nil if not a layer*/
81 typedef struct Memdrawparam
92 .ta \w'\fLMemsubfont* 'u
98 int memimageinit(void)
99 ulong* wordaddr(Memimage *i, Point p)
100 uchar* byteaddr(Memimage *i, Point p)
101 void memimagemove(void *from, void *to)
105 Memimage* allocmemimage(Rectangle r, ulong chan)
106 Memimage* allocmemimaged(Rectangle r, ulong chan, Memdata *data)
107 Memimage* readmemimage(int fd)
108 Memimage* creadmemimage(int fd)
109 int writememimage(int fd, Memimage *i)
110 void freememimage(Memimage *i)
111 int memsetchan(Memimage*, ulong)
115 int loadmemimage(Memimage *i, Rectangle r,
116 uchar *buf, int nbuf)
117 int cloadmemimage(Memimage *i, Rectangle r,
118 uchar *buf, int nbuf)
119 int unloadmemimage(Memimage *i, Rectangle r,
120 uchar *buf, int nbuf)
121 void memfillcolor(Memimage *i, ulong color)
125 void memarc(Memimage *dst, Point c, int a, int b, int thick,
126 Memimage *src, Point sp, int alpha, int phi, Drawop op)
127 void mempoly(Memimage *dst, Point *p, int np, int end0,
128 int end1, int radius, Memimage *src, Point sp, Drawop op)
129 void memellipse(Memimage *dst, Point c, int a, int b,
130 int thick, Memimage *src, Point sp, Drawop op)
131 void memfillpoly(Memimage *dst, Point *p, int np, int wind,
132 Memimage *src, Point sp, Drawop op)
133 void memimageline(Memimage *dst, Point p0, Point p1, int end0,
134 int end1, int radius, Memimage *src, Point sp, Drawop op)
135 void memimagedraw(Memimage *dst, Rectangle r, Memimage *src,
136 Point sp, Memimage *mask, Point mp, Drawop op)
140 int drawclip(Memimage *dst, Rectangle *dr, Memimage *src,
141 Point *sp, Memimage *mask, Point *mp,
142 Rectangle *sr, Rectangle *mr)
143 int drawclipnorepl(Memimage *dst, Rectangle *dr, Memimage *src,
144 Point *sp, Memimage *mask, Point *mp,
145 Rectangle *sr, Rectangle *mr)
146 Rectangle memlinebbox(Point p0, Point p1, int end0, int end1,
148 int memlineendsize(int end)
152 Memsubfont* allocmemsubfont(char *name, int n, int height,
153 int ascent, Fontchar *info, Memimage *i)
154 Memsubfont* openmemsubfont(char *name)
155 void freememsubfont(Memsubfont *f)
156 Point memsubfontwidth(Memsubfont *f, char *s)
157 Memsubfont* getmemdefont(void)
158 Point memimagestring(Memimage *dst, Point p, Memimage *color,
159 Point cp, Memsubfont *f, char *cs)
163 int iprint(char *fmt, ...)
164 int hwdraw(Memdrawparam *param)
169 type defines memory-resident rectangular pictures and the methods to draw upon them;
175 in that they are manipulated directly in user memory rather than by
181 library is the basis for the kernel
183 driver and also used by a number of programs that must manipulate
184 images without a display.
193 structure elements are identical to
194 the ones of the same name
203 structure holds a number of bits of information about the image.
204 In particular, it subsumes the
212 initializes various static data that the library depends on,
213 as well as the replicated solid color images
219 It should be called before referring to any of these images
220 and before calling any of the other library functions. It
221 returns non-zero on error.
227 structure that in turn points at the actual pixel data for the image.
228 This allows multiple images to be associated with the same
230 The first word of the data pointed at by
237 structure, so that the
238 memory allocator (see
240 can compact image memory
244 Because images can have different coordinate systems,
249 structure contains the offset that must be added
252 element of the corresponding
254 structure in order to yield a pointer to the data for the pixel (0,0).
258 to this pointer moves it down one scan line.
261 element can be used to determine how to move the
262 pointer horizontally.
263 Note that this method works even for images whose rectangles
264 do not include the origin, although one should only dereference
265 pointers corresponding to pixels within the image rectangle.
269 perform these calculations,
270 returning pointers to the word and byte, respectively,
271 that contain the beginning of the data for a given pixel.
275 images with a given rectangle and channel descriptor
282 structure and associated storage.
284 is similar but uses the supplied
286 structure rather than a new one.
289 function reads an uncompressed bitmap
290 from the given file descriptor,
293 reads a compressed bitmap.
295 writes a compressed representation of
299 For more on bitmap formats, see
302 frees images returned by any of these routines.
305 structure contains some tables that are used
306 to store precomputed values depending on the channel descriptor.
310 element of the structure as well as these tables,
311 returning \-1 if passed a bad channel descriptor.
316 replace the pixel data for a given rectangle of an image
317 with the given buffer of uncompressed or compressed
321 the buffer must contain an
323 compressed chunks of data that exactly cover the rectangle.
325 retrieves the uncompressed pixel data for a given rectangle of an image.
326 All three return the number of bytes consumed on success,
327 and \-1 in case of an error.
330 fills an image with the given color, a 32-bit number as
349 routines described in
351 except that they operate on
356 .IR allocmemsubfont ,
359 .IR memsubfontwidth ,
369 .IR strsubfontwidth ,
377 except that they operate
384 takes the images involved in a draw operation,
385 together with the destination rectangle
388 and mask alignment points
393 clips them according to the clipping rectangles of the images involved.
394 It also fills in the rectangles
398 with rectangles congruent to the returned destination rectangle
399 but translated so the upper left corners are the returned
410 within the image rectangle of source and mask when replicated.
414 return zero when the clipped rectangle is empty.
416 returns a conservative bounding box containing a line between
418 with given end styles
421 calculates the extra length added to a line by attaching
422 an end of a given style.
428 functions are no-op stubs that may be overridden by clients
431 is called at each call to
433 with the current request's parameters.
434 If it can satisfy the request, it should do so
436 If it cannot satisfy the request, it should return 0.
437 This allows (for instance) the kernel to take advantage
438 of hardware acceleration.
440 should format and print its arguments;
441 it is given much debugging output when
442 the global integer variable
447 prints to a serial line rather than the screen, for obvious reasons.
449 .B /sys/src/libmemdraw
462 is unusual in using a subfont rather than a font,
463 and in having no parameter to align the source.