4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
35 * \author Bernie Innocenti <bernie@codewiz.org>
37 * \brief Graphics private header.
42 *#* Revision 1.7 2006/07/19 12:56:26 bernie
43 *#* Convert to new Doxygen style.
45 *#* Revision 1.6 2006/05/27 17:17:34 bernie
46 *#* Optimize away divisions in RAST_ADDR/MASK macros.
48 *#* Revision 1.5 2006/05/25 23:35:40 bernie
51 *#* Revision 1.4 2006/03/22 09:50:37 bernie
52 *#* Use the same format for fonts and rasters.
54 *#* Revision 1.3 2006/02/15 09:10:15 bernie
55 *#* Implement prop fonts; Fix algo styles.
57 *#* Revision 1.2 2006/02/10 12:28:33 bernie
58 *#* Add font support in bitmaps; Make bitmap formats public.
60 *#* Revision 1.1 2006/01/26 00:32:49 bernie
61 *#* Graphics private header.
70 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
72 /* We use ucoord_t to let the compiler optimize away the division/modulo. */
73 #define RAST_ADDR(raster, x, y, stride) \
74 ((raster) + (ucoord_t)(y) * (ucoord_t)(stride) + (ucoord_t)(x) / 8)
75 #define RAST_MASK(raster, x, y) \
76 (1 << (7 - (ucoord_t)(x) % 8))
78 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
80 /* We use ucoord_t to let the compiler optimize away the division/modulo. */
81 #define RAST_ADDR(raster, x, y, stride) \
82 ((raster) + ((ucoord_t)(y) / 8) * (ucoord_t)(stride) + (ucoord_t)(x))
83 #define RAST_MASK(raster, x, y) \
84 (1 << ((ucoord_t)(y) % 8))
87 #error Unknown value of CONFIG_BITMAP_FMT
88 #endif /* CONFIG_BITMAP_FMT */
90 #define BM_ADDR(bm, x, y) RAST_ADDR((bm)->raster, (x), (y), (bm)->stride)
91 #define BM_MASK(bm, x, y) RAST_MASK((bm)->raster, (x), (y))
94 * Plot a pixel in bitmap \a bm.
96 * \note bm is evaluated twice.
97 * \see BM_CLEAR BM_DRAWPIXEL
99 #define BM_PLOT(bm, x, y) \
100 ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
103 * Clear a pixel in bitmap \a bm.
105 * \note bm is evaluated twice.
106 * \see BM_PLOT BM_DRAWPIXEL
108 #define BM_CLEAR(bm, x, y) \
109 ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
112 * Set a pixel in bitmap \a bm to the specified color.
114 * \note bm is evaluated twice.
115 * \note This macro is somewhat slower than BM_PLOT and BM_CLEAR.
116 * \see BM_PLOT BM_CLEAR
118 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
120 uint8_t *p = BM_ADDR(bm, x, y); \
121 uint8_t mask = BM_MASK(bm, x, y); \
122 *p = (*p & ~mask) | ((fg_pen) ? mask : 0); \
126 * Get the value of the pixel in bitmap \a bm.
128 * \return The returned value is either 0 or 1.
130 * \note bm is evaluated twice.
133 #define BM_READPIXEL(bm, x, y) \
134 ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
136 #define RAST_READPIXEL(raster, x, y, stride) \
137 ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
139 #endif /* GFX_GFX_P_H */