3 * Copyright 2003, 2004, 2005, 2006 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.10 2006/02/17 22:24:40 bernie
18 *#* Fix undefined preprocessor symbol.
20 *#* Revision 1.9 2006/02/15 09:10:15 bernie
21 *#* Implement prop fonts; Fix algo styles.
23 *#* Revision 1.8 2006/02/10 12:28:33 bernie
24 *#* Add font support in bitmaps; Make bitmap formats public.
26 *#* Revision 1.7 2006/01/26 00:36:48 bernie
27 *#* Const correctness for some new functions.
29 *#* Revision 1.6 2006/01/23 23:13:04 bernie
30 *#* RECT_WIDTH(), RECT_HEIGHT(), RASTER_SIZE(): New macros.
32 *#* Revision 1.5 2006/01/17 02:31:29 bernie
33 *#* Add bitmap format support; Improve some comments.
39 #include <cfg/compiler.h>
40 #include <cfg/cpu.h> /* CPU_HARVARD */
42 #include <appconfig.h> /* CONFIG_GFX_* */
45 * \name Known pixel formats for bitmap representation.
48 #define BITMAP_FMT_PLANAR_H_MSB 1 /**< Planar pixels, horizontal bytes, MSB left. */
49 #define BITMAP_FMT_PLANAR_V_LSB 2 /**< Planar pixels, vertical bytes, LSB top. */
52 #if !defined(CONFIG_BITMAP_FMT) || (CONFIG_BITMAP_FMT != BITMAP_FMT_PLANAR_H_MSB && CONFIG_BITMAP_FMT != BITMAP_FMT_PLANAR_V_LSB)
53 #error CONFIG_BITMAP_FMT must be defined to either BITMAP_FMT_PLANAR_H_LSB or BITMAP_FMT_PLANAR_V_LSB
55 #if !defined(CONFIG_GFX_CLIPPING) || (CONFIG_GFX_CLIPPING != 0 && CONFIG_GFX_CLIPPING != 1)
56 #error CONFIG_GFX_CLIPPING must be defined to either 0 or 1
58 #if !defined(CONFIG_GFX_TEXT) || (CONFIG_GFX_TEXT != 0 && CONFIG_GFX_TEXT != 1)
59 #error CONFIG_GFX_TEXT must be defined to either 0 or 1
64 /*! Common type for coordinates expressed in pixel units */
67 #if CONFIG_GFX_VCOORDS
68 /*! Common type for coordinates expressed in logical units */
69 typedef float vcoord_t;
70 #endif /* CONFIG_GFX_VCOORDS */
74 * Describe a rectangular area with coordinates expressed in pixels.
76 * The rectangle is represented in terms of its top/left and
77 * right/bottom borders.
79 * In some cases, rectangles are assumed to obey to the
80 * following invariants:
85 * Oddly, the xmin and ymin coordinates are inclusive, while the
86 * xmax and ymax coordinates are non-inclusive. This design
87 * decision makes several computations simpler and lets you
88 * specify empty (0x0) rectangles without breaking the
91 * Computing the size of a rectangle can be done by simply
92 * subtracting the maximum X or Y coordinate from the minimum
95 typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect;
98 * Return the width of a rectangle in pixels.
100 * \note The argument \a r is evaluated twice.
102 #define RECT_WIDTH(r) ((r)->xmax - (r)->xmin)
105 * Return the height of a rectangle in pixels.
107 * \note The argument \a r is evaluated twice.
109 #define RECT_HEIGHT(r) ((r)->ymax - (r)->ymin)
115 * Control structure to draw in a bitmap
117 typedef struct Bitmap
119 uint8_t *raster; /*!< Pointer to byte array to hold the data */
120 coord_t width, height; /*!< Width/Height in pixels */
121 coord_t stride; /*!< Bytes per row. */
122 coord_t penX, penY; /*!< Current pen position MoveTo()/LineTo() */
124 Rect cr; /*!< Clip drawing inside this rectangle */
127 const struct Font *font;/**< Current font for text rendering. */
129 #if CONFIG_GFX_VCOORDS
131 * \name Logical coordinate system
135 vcoord_t scaleX, scaleY;
137 #endif /* CONFIG_GFX_VCOORDS */
141 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
143 * Compute the size in bytes of a raster suitable for
144 * holding a bitmap of \a width x \a height pixels.
146 #define RASTER_SIZE(width, height) ( ((width) + 7 / 8) * (height) )
148 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
150 * Compute the size in bytes of a raster suitable for
151 * holding a bitmap of \a width x \a height pixels.
153 #define RASTER_SIZE(width, height) ( (width) * (((height) + 7) / 8) )
155 #error Unknown value of CONFIG_BITMAP_FMT
156 #endif /* CONFIG_BITMAP_FMT */
159 /* Function prototypes */
160 void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h);
161 void gfx_bitmapClear(Bitmap *bm);
162 void gfx_blit (Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy);
163 void gfx_blitRaster (Bitmap *dst, coord_t dx, coord_t dy, const uint8_t *raster, coord_t w, coord_t h, coord_t stride);
164 void gfx_line (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
165 void gfx_rectDraw (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
166 void gfx_rectFillC (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color);
167 void gfx_rectFill (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
168 void gfx_rectClear (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
169 void gfx_moveTo (Bitmap *bm, coord_t x, coord_t y);
170 void gfx_lineTo (Bitmap *bm, coord_t x, coord_t y);
171 void gfx_setClipRect(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax);
174 #include <mware/pgm.h>
175 void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster);
179 INLINE void gfx_setFont(Bitmap *bm, const struct Font *font)
185 #if CONFIG_GFX_VCOORDS
186 void gfx_setViewRect(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
187 coord_t gfx_transformX(Bitmap *bm, vcoord_t x);
188 coord_t gfx_transformY(Bitmap *bm, vcoord_t y);
189 void gfx_vline(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
190 #endif /* CONFIG_GFX_VCOORDS */
194 #endif /* GFX_GFX_H */