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.1 2006/01/26 00:32:49 bernie
19 *#* Graphics private header.
27 * \name Known pixel formats for bitmap representation.
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. */
34 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
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))
39 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
41 #define BM_ADDR(bm, x, y) ((bm)->raster + ((y) / 8) * (bm)->stride + (x))
42 #define BM_MASK(bm, x, y) (1 << ((y) % 8))
45 #error Unknown value of CONFIG_BITMAP_FMT
46 #endif /* CONFIG_BITMAP_FMT */
49 * Plot a pixel in bitmap \a bm.
51 * \note bm is evaluated twice.
52 * \see BM_CLEAR BM_DRAWPIXEL
54 #define BM_PLOT(bm, x, y) \
55 ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
58 * Clear a pixel in bitmap \a bm.
60 * \note bm is evaluated twice.
61 * \see BM_PLOT BM_DRAWPIXEL
63 #define BM_CLEAR(bm, x, y) \
64 ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
67 * Set a pixel in bitmap \a bm to the specified color.
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
73 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
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); \
81 * Get the value of the pixel in bitmap \a bm.
83 * \return The returned value is either 0 or 1.
85 * \note bm is evaluated twice.
88 #define BM_READPIXEL(bm, x, y) \
89 ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
92 #endif /* GFX_GFX_P_H */