738eb09ebbb6819296b0d258dd444efc2a0ecf92
[bertos.git] / gfx / gfx_p.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
6  * This file is part of DevLib - See README.devlib for information.
7  * -->
8  *
9  * \version $Id$
10  *
11  * \author Bernardo Innocenti <bernie@develer.com>
12  *
13  * \brief Graphics private header.
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.7  2006/07/19 12:56:26  bernie
19  *#* Convert to new Doxygen style.
20  *#*
21  *#* Revision 1.6  2006/05/27 17:17:34  bernie
22  *#* Optimize away divisions in RAST_ADDR/MASK macros.
23  *#*
24  *#* Revision 1.5  2006/05/25 23:35:40  bernie
25  *#* Cleanup.
26  *#*
27  *#* Revision 1.4  2006/03/22 09:50:37  bernie
28  *#* Use the same format for fonts and rasters.
29  *#*
30  *#* Revision 1.3  2006/02/15 09:10:15  bernie
31  *#* Implement prop fonts; Fix algo styles.
32  *#*
33  *#* Revision 1.2  2006/02/10 12:28:33  bernie
34  *#* Add font support in bitmaps; Make bitmap formats public.
35  *#*
36  *#* Revision 1.1  2006/01/26 00:32:49  bernie
37  *#* Graphics private header.
38  *#*
39  *#*/
40
41 #ifndef GFX_GFX_P_H
42 #define GFX_GFX_P_H
43
44 #include <gfx/gfx.h>
45
46 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
47
48         /* We use ucoord_t to let the compiler optimize away the division/modulo. */
49         #define RAST_ADDR(raster, x, y, stride) \
50                         ((raster) + (ucoord_t)(y) * (ucoord_t)(stride) + (ucoord_t)(x) / 8)
51         #define RAST_MASK(raster, x, y) \
52                         (1 << (7 - (ucoord_t)(x) % 8))
53
54 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
55
56         /* We use ucoord_t to let the compiler optimize away the division/modulo. */
57         #define RAST_ADDR(raster, x, y, stride) \
58                         ((raster) + ((ucoord_t)(y) / 8) * (ucoord_t)(stride) + (ucoord_t)(x))
59         #define RAST_MASK(raster, x, y) \
60                         (1 << ((ucoord_t)(y) % 8))
61
62 #else
63         #error Unknown value of CONFIG_BITMAP_FMT
64 #endif /* CONFIG_BITMAP_FMT */
65
66 #define BM_ADDR(bm, x, y)  RAST_ADDR((bm)->raster, (x), (y), (bm)->stride)
67 #define BM_MASK(bm, x, y)  RAST_MASK((bm)->raster, (x), (y))
68
69 /**
70  * Plot a pixel in bitmap \a bm.
71  *
72  * \note bm is evaluated twice.
73  * \see BM_CLEAR BM_DRAWPIXEL
74  */
75 #define BM_PLOT(bm, x, y) \
76         ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
77
78 /**
79  * Clear a pixel in bitmap \a bm.
80  *
81  * \note bm is evaluated twice.
82  * \see BM_PLOT BM_DRAWPIXEL
83  */
84 #define BM_CLEAR(bm, x, y) \
85         ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
86
87 /**
88  * Set a pixel in bitmap \a bm to the specified color.
89  *
90  * \note bm is evaluated twice.
91  * \note This macro is somewhat slower than BM_PLOT and BM_CLEAR.
92  * \see BM_PLOT BM_CLEAR
93  */
94 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
95         do { \
96                 uint8_t *p = BM_ADDR(bm, x, y); \
97                 uint8_t mask = BM_MASK(bm, x, y); \
98                 *p = (*p & ~mask) | ((fg_pen) ? mask : 0); \
99         } while (0)
100
101 /**
102  * Get the value of the pixel in bitmap \a bm.
103  *
104  * \return The returned value is either 0 or 1.
105  *
106  * \note bm is evaluated twice.
107  * \see BM_DRAWPIXEL
108  */
109 #define BM_READPIXEL(bm, x, y) \
110         ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
111
112 #define RAST_READPIXEL(raster, x, y, stride) \
113                 ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
114
115 #endif /* GFX_GFX_P_H */