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