3 * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
4 * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
5 * This file is part of DevLib - See README.devlib for information.
9 * \author Bernardo Innocenti <bernie@develer.com>
10 * \author Stefano Fedrigo <aleph@develer.com>
12 * \brief General pourpose graphics routines
17 *#* Revision 1.7 2006/01/26 00:36:48 bernie
18 *#* Const correctness for some new functions.
20 *#* Revision 1.6 2006/01/23 23:13:04 bernie
21 *#* RECT_WIDTH(), RECT_HEIGHT(), RASTER_SIZE(): New macros.
23 *#* Revision 1.5 2006/01/17 02:31:29 bernie
24 *#* Add bitmap format support; Improve some comments.
26 *#* Revision 1.4 2006/01/16 03:30:57 bernie
27 *#* Make header C++ friendly.
29 *#* Revision 1.3 2005/11/27 23:33:40 bernie
30 *#* Use appconfig.h instead of cfg/config.h.
32 *#* Revision 1.2 2005/11/04 18:17:45 bernie
33 *#* Fix header guards and includes for new location of gfx module.
35 *#* Revision 1.1 2005/11/04 18:11:35 bernie
36 *#* Move graphics stuff from mware/ to gfx/.
38 *#* Revision 1.12 2005/11/04 16:20:02 bernie
39 *#* Fix reference to README.devlib in header.
41 *#* Revision 1.11 2005/04/11 19:10:28 bernie
42 *#* Include top-level headers from cfg/ subdir.
44 *#* Revision 1.10 2005/03/01 23:26:45 bernie
45 *#* Use new CPU-neutral program-memory API.
47 *#* Revision 1.9 2005/01/20 18:46:31 aleph
48 *#* Fix progmem includes.
54 #include <appconfig.h>
55 #include <cfg/compiler.h>
60 /*! Common type for coordinates expressed in pixel units */
63 #if CONFIG_GFX_VCOORDS
64 /*! Common type for coordinates expressed in logical units */
65 typedef float vcoord_t;
66 #endif /* CONFIG_GFX_VCOORDS */
70 * Describe a rectangular area with coordinates expressed in pixels.
72 * The rectangle is represented in terms of its top/left and
73 * right/bottom borders.
75 * In some cases, rectangles are assumed to obey to the
76 * following invariants:
81 * Oddly, the xmin and ymin coordinates are inclusive, while the
82 * xmax and ymax coordinates are non-inclusive. This design
83 * decision makes several computations simpler and lets you
84 * specify empty (0x0) rectangles without breaking the
87 * Computing the size of a rectangle can be done by simply
88 * subtracting the maximum X or Y coordinate from the minimum
91 typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect;
94 * Return the width of a rectangle in pixels.
96 * \note The argument \a r is evaluated twice.
98 #define RECT_WIDTH(r) ((r)->xmax - (r)->xmin)
101 * Return the height of a rectangle in pixels.
103 * \note The argument \a r is evaluated twice.
105 #define RECT_HEIGHT(r) ((r)->ymax - (r)->ymin)
109 * Control structure to draw in a bitmap
111 typedef struct Bitmap
113 uint8_t *raster; /*!< Pointer to byte array to hold the data */
114 coord_t width, height; /*!< Width/Height in pixels */
115 coord_t stride; /*!< Bytes per row. */
116 coord_t penX, penY; /*!< Current pen position MoveTo()/LineTo() */
118 Rect cr; /*!< Clip drawing inside this rectangle */
120 #if CONFIG_GFX_VCOORDS
122 * \name Logical coordinate system
126 vcoord_t scaleX, scaleY;
128 #endif /* CONFIG_GFX_VCOORDS */
132 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
134 * Compute the size in bytes of a raster suitable for
135 * holding a bitmap of \a width x \a height pixels.
137 #define RASTER_SIZE(width, height) ( ((width) + 7 / 8) * (height) )
139 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
141 * Compute the size in bytes of a raster suitable for
142 * holding a bitmap of \a width x \a height pixels.
144 #define RASTER_SIZE(width, height) ( (width) * (((height) + 7) / 8) )
146 #error Unknown value of CONFIG_BITMAP_FMT
147 #endif /* CONFIG_BITMAP_FMT */
150 /* Function prototypes */
151 extern void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h);
152 extern void gfx_bitmapClear(Bitmap *bm);
153 extern void gfx_blit (Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy);
154 extern void gfx_line (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
155 extern void gfx_rectDraw (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
156 extern void gfx_rectFillC (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color);
157 extern void gfx_rectFill (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
158 extern void gfx_rectClear (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
159 extern void gfx_moveTo (Bitmap *bm, coord_t x, coord_t y);
160 extern void gfx_lineTo (Bitmap *bm, coord_t x, coord_t y);
161 extern void gfx_setClipRect(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax);
164 #include <mware/pgm.h>
165 extern void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster);
168 #if CONFIG_GFX_VCOORDS
169 extern void gfx_setViewRect(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
170 extern coord_t gfx_transformX(Bitmap *bm, vcoord_t x);
171 extern coord_t gfx_transformY(Bitmap *bm, vcoord_t y);
172 extern void gfx_vline(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
173 #endif /* CONFIG_GFX_VCOORDS */
177 #endif /* GFX_GFX_H */