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>
36 * \author Bernie Innocenti <bernie@codewiz.org>
38 * \brief Graphics private header.
43 *#* Revision 1.7 2006/07/19 12:56:26 bernie
44 *#* Convert to new Doxygen style.
46 *#* Revision 1.6 2006/05/27 17:17:34 bernie
47 *#* Optimize away divisions in RAST_ADDR/MASK macros.
49 *#* Revision 1.5 2006/05/25 23:35:40 bernie
52 *#* Revision 1.4 2006/03/22 09:50:37 bernie
53 *#* Use the same format for fonts and rasters.
55 *#* Revision 1.3 2006/02/15 09:10:15 bernie
56 *#* Implement prop fonts; Fix algo styles.
58 *#* Revision 1.2 2006/02/10 12:28:33 bernie
59 *#* Add font support in bitmaps; Make bitmap formats public.
61 *#* Revision 1.1 2006/01/26 00:32:49 bernie
62 *#* Graphics private header.
71 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
73 /* We use ucoord_t to let the compiler optimize away the division/modulo. */
74 #define RAST_ADDR(raster, x, y, stride) \
75 ((raster) + (ucoord_t)(y) * (ucoord_t)(stride) + (ucoord_t)(x) / 8)
76 #define RAST_MASK(raster, x, y) \
77 (1 << (7 - (ucoord_t)(x) % 8))
79 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
81 /* We use ucoord_t to let the compiler optimize away the division/modulo. */
82 #define RAST_ADDR(raster, x, y, stride) \
83 ((raster) + ((ucoord_t)(y) / 8) * (ucoord_t)(stride) + (ucoord_t)(x))
84 #define RAST_MASK(raster, x, y) \
85 (1 << ((ucoord_t)(y) % 8))
88 #error Unknown value of CONFIG_BITMAP_FMT
89 #endif /* CONFIG_BITMAP_FMT */
91 #define BM_ADDR(bm, x, y) RAST_ADDR((bm)->raster, (x), (y), (bm)->stride)
92 #define BM_MASK(bm, x, y) RAST_MASK((bm)->raster, (x), (y))
95 * Plot a pixel in bitmap \a bm.
97 * \note bm is evaluated twice.
98 * \see BM_CLEAR BM_DRAWPIXEL
100 #define BM_PLOT(bm, x, y) \
101 ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
104 * Clear a pixel in bitmap \a bm.
106 * \note bm is evaluated twice.
107 * \see BM_PLOT BM_DRAWPIXEL
109 #define BM_CLEAR(bm, x, y) \
110 ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
113 * Set a pixel in bitmap \a bm to the specified color.
115 * \note bm is evaluated twice.
116 * \note This macro is somewhat slower than BM_PLOT and BM_CLEAR.
117 * \see BM_PLOT BM_CLEAR
119 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
121 uint8_t *p = BM_ADDR(bm, x, y); \
122 uint8_t mask = BM_MASK(bm, x, y); \
123 *p = (*p & ~mask) | ((fg_pen) ? mask : 0); \
127 * Get the value of the pixel in bitmap \a bm.
129 * \return The returned value is either 0 or 1.
131 * \note bm is evaluated twice.
134 #define BM_READPIXEL(bm, x, y) \
135 ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
137 #define RAST_READPIXEL(raster, x, y, stride) \
138 ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
140 #endif /* GFX_GFX_P_H */