Update preset.
[bertos.git] / bertos / gfx / gfx_p.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 1999 Bernie Innocenti <bernie@codewiz.org>
31  *
32  * -->
33  *
34  *
35  * \author Bernie Innocenti <bernie@codewiz.org>
36  *
37  * \brief Graphics private header.
38  */
39
40 /*#*
41  *#* $Log$
42  *#* Revision 1.7  2006/07/19 12:56:26  bernie
43  *#* Convert to new Doxygen style.
44  *#*
45  *#* Revision 1.6  2006/05/27 17:17:34  bernie
46  *#* Optimize away divisions in RAST_ADDR/MASK macros.
47  *#*
48  *#* Revision 1.5  2006/05/25 23:35:40  bernie
49  *#* Cleanup.
50  *#*
51  *#* Revision 1.4  2006/03/22 09:50:37  bernie
52  *#* Use the same format for fonts and rasters.
53  *#*
54  *#* Revision 1.3  2006/02/15 09:10:15  bernie
55  *#* Implement prop fonts; Fix algo styles.
56  *#*
57  *#* Revision 1.2  2006/02/10 12:28:33  bernie
58  *#* Add font support in bitmaps; Make bitmap formats public.
59  *#*
60  *#* Revision 1.1  2006/01/26 00:32:49  bernie
61  *#* Graphics private header.
62  *#*
63  *#*/
64
65 #ifndef GFX_GFX_P_H
66 #define GFX_GFX_P_H
67
68 #include <gfx/gfx.h>
69
70 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
71
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))
77
78 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
79
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))
85
86 #else
87         #error Unknown value of CONFIG_BITMAP_FMT
88 #endif /* CONFIG_BITMAP_FMT */
89
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))
92
93 /**
94  * Plot a pixel in bitmap \a bm.
95  *
96  * \note bm is evaluated twice.
97  * \see BM_CLEAR BM_DRAWPIXEL
98  */
99 #define BM_PLOT(bm, x, y) \
100         ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
101
102 /**
103  * Clear a pixel in bitmap \a bm.
104  *
105  * \note bm is evaluated twice.
106  * \see BM_PLOT BM_DRAWPIXEL
107  */
108 #define BM_CLEAR(bm, x, y) \
109         ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
110
111 /**
112  * Set a pixel in bitmap \a bm to the specified color.
113  *
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
117  */
118 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
119         do { \
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); \
123         } while (0)
124
125 /**
126  * Get the value of the pixel in bitmap \a bm.
127  *
128  * \return The returned value is either 0 or 1.
129  *
130  * \note bm is evaluated twice.
131  * \see BM_DRAWPIXEL
132  */
133 #define BM_READPIXEL(bm, x, y) \
134         ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
135
136 #define RAST_READPIXEL(raster, x, y, stride) \
137                 ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
138
139 #endif /* GFX_GFX_P_H */