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.
11 * \author Bernardo Innocenti <bernie@develer.com>
13 * \brief Graphics private header.
18 *#* Revision 1.4 2006/03/22 09:50:37 bernie
19 *#* Use the same format for fonts and rasters.
21 *#* Revision 1.3 2006/02/15 09:10:15 bernie
22 *#* Implement prop fonts; Fix algo styles.
24 *#* Revision 1.2 2006/02/10 12:28:33 bernie
25 *#* Add font support in bitmaps; Make bitmap formats public.
27 *#* Revision 1.1 2006/01/26 00:32:49 bernie
28 *#* Graphics private header.
36 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
38 #define RAST_ADDR(raster, x, y, stride) ((raster) + (y) * (stride) + (x) / 8)
39 #define RAST_MASK(raster, x, y) (1 << (7 - (x) % 8))
41 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
43 #define RAST_ADDR(raster, x, y, stride) ((raster) + ((y) / 8) * (stride) + (x))
44 #define RAST_MASK(raster, x, y) (1 << ((y) % 8))
46 #error Unknown value of CONFIG_BITMAP_FMT
47 #endif /* CONFIG_BITMAP_FMT */
49 #define BM_ADDR(bm, x, y) RAST_ADDR((bm)->raster, (x), (y), (bm)->stride)
50 #define BM_MASK(bm, x, y) RAST_MASK((bm)->raster, (x), (y))
53 * Plot a pixel in bitmap \a bm.
55 * \note bm is evaluated twice.
56 * \see BM_CLEAR BM_DRAWPIXEL
58 #define BM_PLOT(bm, x, y) \
59 ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
62 * Clear a pixel in bitmap \a bm.
64 * \note bm is evaluated twice.
65 * \see BM_PLOT BM_DRAWPIXEL
67 #define BM_CLEAR(bm, x, y) \
68 ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
71 * Set a pixel in bitmap \a bm to the specified color.
73 * \note bm is evaluated twice.
74 * \note This macro is somewhat slower than BM_PLOT and BM_CLEAR.
75 * \see BM_PLOT BM_CLEAR
77 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
79 uint8_t *p = BM_ADDR(bm, x, y); \
80 uint8_t mask = BM_MASK(bm, x, y); \
81 *p = (*p & ~mask) | ((fg_pen) ? mask : 0); \
85 * Get the value of the pixel in bitmap \a bm.
87 * \return The returned value is either 0 or 1.
89 * \note bm is evaluated twice.
92 #define BM_READPIXEL(bm, x, y) \
93 ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
95 #define RAST_READPIXEL(raster, x, y, stride) \
96 ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
98 #endif /* GFX_GFX_P_H */