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.6 2006/01/23 23:13:04 bernie
18 *#* RECT_WIDTH(), RECT_HEIGHT(), RASTER_SIZE(): New macros.
20 *#* Revision 1.5 2006/01/17 02:31:29 bernie
21 *#* Add bitmap format support; Improve some comments.
23 *#* Revision 1.4 2006/01/16 03:30:57 bernie
24 *#* Make header C++ friendly.
26 *#* Revision 1.3 2005/11/27 23:33:40 bernie
27 *#* Use appconfig.h instead of cfg/config.h.
29 *#* Revision 1.2 2005/11/04 18:17:45 bernie
30 *#* Fix header guards and includes for new location of gfx module.
32 *#* Revision 1.1 2005/11/04 18:11:35 bernie
33 *#* Move graphics stuff from mware/ to gfx/.
35 *#* Revision 1.12 2005/11/04 16:20:02 bernie
36 *#* Fix reference to README.devlib in header.
38 *#* Revision 1.11 2005/04/11 19:10:28 bernie
39 *#* Include top-level headers from cfg/ subdir.
41 *#* Revision 1.10 2005/03/01 23:26:45 bernie
42 *#* Use new CPU-neutral program-memory API.
44 *#* Revision 1.9 2005/01/20 18:46:31 aleph
45 *#* Fix progmem includes.
51 #include <appconfig.h>
52 #include <cfg/compiler.h>
57 /*! Common type for coordinates expressed in pixel units */
60 #if CONFIG_GFX_VCOORDS
61 /*! Common type for coordinates expressed in logical units */
62 typedef float vcoord_t;
63 #endif /* CONFIG_GFX_VCOORDS */
67 * Describe a rectangular area with coordinates expressed in pixels.
69 * The rectangle is represented in terms of its top/left and
70 * right/bottom borders.
72 * In some cases, rectangles are assumed to obey to the
73 * following invariants:
78 * Oddly, the xmin and ymin coordinates are inclusive, while the
79 * xmax and ymax coordinates are non-inclusive. This design
80 * decision makes several computations simpler and lets you
81 * specify empty (0x0) rectangles without breaking the
84 * Computing the size of a rectangle can be done by simply
85 * subtracting the maximum X or Y coordinate from the minimum
88 typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect;
91 * Return the width of a rectangle in pixels.
93 * \note The argument \a r is evaluated twice.
95 #define RECT_WIDTH(r) ((r)->xmax - (r)->xmin)
98 * Return the height of a rectangle in pixels.
100 * \note The argument \a r is evaluated twice.
102 #define RECT_HEIGHT(r) ((r)->ymax - (r)->ymin)
106 * Control structure to draw in a bitmap
108 typedef struct Bitmap
110 uint8_t *raster; /*!< Pointer to byte array to hold the data */
111 coord_t width, height; /*!< Width/Height in pixels */
112 coord_t stride; /*!< Bytes per row. */
113 coord_t penX, penY; /*!< Current pen position MoveTo()/LineTo() */
115 Rect cr; /*!< Clip drawing inside this rectangle */
117 #if CONFIG_GFX_VCOORDS
119 * \name Logical coordinate system
123 vcoord_t scaleX, scaleY;
125 #endif /* CONFIG_GFX_VCOORDS */
129 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
131 * Compute the size in bytes of a raster suitable for
132 * holding a bitmap of \a width x \a height pixels.
134 #define RASTER_SIZE(width, height) ( ((width) + 7 / 8) * (height) )
136 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
138 * Compute the size in bytes of a raster suitable for
139 * holding a bitmap of \a width x \a height pixels.
141 #define RASTER_SIZE(width, height) ( (width) * (((height) + 7) / 8) )
143 #error Unknown value of CONFIG_BITMAP_FMT
144 #endif /* CONFIG_BITMAP_FMT */
147 /* Function prototypes */
148 extern void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h);
149 extern void gfx_bitmapClear(Bitmap *bm);
150 extern void gfx_blit (Bitmap *dst, Rect *rect, Bitmap *src, coord_t srcx, coord_t srcy);
151 extern void gfx_line (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
152 extern void gfx_rectDraw (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
153 extern void gfx_rectFillC (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color);
154 extern void gfx_rectFill (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
155 extern void gfx_rectClear (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
156 extern void gfx_moveTo (Bitmap *bm, coord_t x, coord_t y);
157 extern void gfx_lineTo (Bitmap *bm, coord_t x, coord_t y);
158 extern void gfx_setClipRect(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax);
161 #include <mware/pgm.h>
162 extern void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster);
165 #if CONFIG_GFX_VCOORDS
166 extern void gfx_setViewRect(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
167 extern coord_t gfx_transformX(Bitmap *bm, vcoord_t x);
168 extern coord_t gfx_transformY(Bitmap *bm, vcoord_t y);
169 extern void gfx_vline(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
170 #endif /* CONFIG_GFX_VCOORDS */
174 #endif /* GFX_GFX_H */