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