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 int 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 int drawclipnorepl(Memimage *dst, Rectangle *dr, Memimage *src,
143 Point *sp, Memimage *mask, Point *mp,
144 Rectangle *sr, Rectangle *mr)
145 Rectangle memlinebbox(Point p0, Point p1, int end0, int end1,
147 int memlineendsize(int end)
151 Memsubfont* allocmemsubfont(char *name, int n, int height,
152 int ascent, Fontchar *info, Memimage *i)
153 Memsubfont* openmemsubfont(char *name)
154 void freememsubfont(Memsubfont *f)
155 Point memsubfontwidth(Memsubfont *f, char *s)
156 Memsubfont* getmemdefont(void)
157 Point memimagestring(Memimage *dst, Point p, Memimage *color,
158 Point cp, Memsubfont *f, char *cs)
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. It
219 returns non-zero on error.
225 structure that in turn points at the actual pixel data for the image.
226 This allows multiple images to be associated with the same
228 The first word of the data pointed at by
235 structure, so that the
236 memory allocator (see
238 can compact image memory
242 Because images can have different coordinate systems,
247 structure contains the offset that must be added
250 element of the corresponding
252 structure in order to yield a pointer to the data for the pixel (0,0).
256 to this pointer moves it down one scan line.
259 element can be used to determine how to move the
260 pointer horizontally.
261 Note that this method works even for images whose rectangles
262 do not include the origin, although one should only dereference
263 pointers corresponding to pixels within the image rectangle.
267 perform these calculations,
268 returning pointers to the word and byte, respectively,
269 that contain the beginning of the data for a given pixel.
273 images with a given rectangle and channel descriptor
280 structure and associated storage.
282 is similar but uses the supplied
284 structure rather than a new one.
287 function reads an uncompressed bitmap
288 from the given file descriptor,
291 reads a compressed bitmap.
293 writes a compressed representation of
297 For more on bitmap formats, see
300 frees images returned by any of these routines.
303 structure contains some tables that are used
304 to store precomputed values depending on the channel descriptor.
308 element of the structure as well as these tables,
309 returning \-1 if passed a bad channel descriptor.
314 replace the pixel data for a given rectangle of an image
315 with the given buffer of uncompressed or compressed
319 the buffer must contain an
321 compressed chunks of data that exactly cover the rectangle.
323 retrieves the uncompressed pixel data for a given rectangle of an image.
324 All three return the number of bytes consumed on success,
325 and \-1 in case of an error.
328 fills an image with the given color, a 32-bit number as
347 routines described in
349 except that they operate on
354 .IR allocmemsubfont ,
357 .IR memsubfontwidth ,
367 .IR strsubfontwidth ,
375 except that they operate
382 takes the images involved in a draw operation,
383 together with the destination rectangle
386 and mask alignment points
391 clips them according to the clipping rectangles of the images involved.
392 It also fills in the rectangles
396 with rectangles congruent to the returned destination rectangle
397 but translated so the upper left corners are the returned
408 within the image rectangle of source and mask when replicated.
412 return zero when the clipped rectangle is empty.
414 returns a conservative bounding box containing a line between
416 with given end styles
419 calculates the extra length added to a line by attaching
420 an end of a given style.
424 function is a no-op stub that may be overridden by clients
427 is called at each call to
429 with the current request's parameters.
430 If it can satisfy the request, it should do so
432 If it cannot satisfy the request, it should return 0.
433 This allows (for instance) the kernel to take advantage
434 of hardware acceleration.
436 .B /sys/src/libmemdraw
449 is unusual in using a subfont rather than a font,
450 and in having no parameter to align the source.