Cleanup.
[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.5  2006/05/25 23:35:40  bernie
19  *#* Cleanup.
20  *#*
21  *#* Revision 1.4  2006/03/22 09:50:37  bernie
22  *#* Use the same format for fonts and rasters.
23  *#*
24  *#* Revision 1.3  2006/02/15 09:10:15  bernie
25  *#* Implement prop fonts; Fix algo styles.
26  *#*
27  *#* Revision 1.2  2006/02/10 12:28:33  bernie
28  *#* Add font support in bitmaps; Make bitmap formats public.
29  *#*
30  *#* Revision 1.1  2006/01/26 00:32:49  bernie
31  *#* Graphics private header.
32  *#*
33  *#*/
34
35 #ifndef GFX_GFX_P_H
36 #define GFX_GFX_P_H
37
38
39 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
40
41         #define RAST_ADDR(raster, x, y, stride)  ((raster) + (y) * (stride) + (x) / 8)
42         #define RAST_MASK(raster, x, y)          (1 << (7 - (x) % 8))
43
44 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
45
46         #define RAST_ADDR(raster, x, y, stride)  ((raster) + ((y) / 8) * (stride) + (x))
47         #define RAST_MASK(raster, x, y)          (1 << ((y) % 8))
48
49 #else
50         #error Unknown value of CONFIG_BITMAP_FMT
51 #endif /* CONFIG_BITMAP_FMT */
52
53 #define BM_ADDR(bm, x, y)  RAST_ADDR((bm)->raster, (x), (y), (bm)->stride)
54 #define BM_MASK(bm, x, y)  RAST_MASK((bm)->raster, (x), (y))
55
56 /*!
57  * Plot a pixel in bitmap \a bm.
58  *
59  * \note bm is evaluated twice.
60  * \see BM_CLEAR BM_DRAWPIXEL
61  */
62 #define BM_PLOT(bm, x, y) \
63         ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
64
65 /*!
66  * Clear a pixel in bitmap \a bm.
67  *
68  * \note bm is evaluated twice.
69  * \see BM_PLOT BM_DRAWPIXEL
70  */
71 #define BM_CLEAR(bm, x, y) \
72         ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
73
74 /*!
75  * Set a pixel in bitmap \a bm to the specified color.
76  *
77  * \note bm is evaluated twice.
78  * \note This macro is somewhat slower than BM_PLOT and BM_CLEAR.
79  * \see BM_PLOT BM_CLEAR
80  */
81 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
82         do { \
83                 uint8_t *p = BM_ADDR(bm, x, y); \
84                 uint8_t mask = BM_MASK(bm, x, y); \
85                 *p = (*p & ~mask) | ((fg_pen) ? mask : 0); \
86         } while (0)
87
88 /*!
89  * Get the value of the pixel in bitmap \a bm.
90  *
91  * \return The returned value is either 0 or 1.
92  *
93  * \note bm is evaluated twice.
94  * \see BM_DRAWPIXEL
95  */
96 #define BM_READPIXEL(bm, x, y) \
97         ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
98
99 #define RAST_READPIXEL(raster, x, y, stride) \
100                 ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
101
102 #endif /* GFX_GFX_P_H */