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