BeRTOS
gfx_p.h
Go to the documentation of this file.
00001 
00040 /*#*
00041  *#* $Log$
00042  *#* Revision 1.7  2006/07/19 12:56:26  bernie
00043  *#* Convert to new Doxygen style.
00044  *#*
00045  *#* Revision 1.6  2006/05/27 17:17:34  bernie
00046  *#* Optimize away divisions in RAST_ADDR/MASK macros.
00047  *#*
00048  *#* Revision 1.5  2006/05/25 23:35:40  bernie
00049  *#* Cleanup.
00050  *#*
00051  *#* Revision 1.4  2006/03/22 09:50:37  bernie
00052  *#* Use the same format for fonts and rasters.
00053  *#*
00054  *#* Revision 1.3  2006/02/15 09:10:15  bernie
00055  *#* Implement prop fonts; Fix algo styles.
00056  *#*
00057  *#* Revision 1.2  2006/02/10 12:28:33  bernie
00058  *#* Add font support in bitmaps; Make bitmap formats public.
00059  *#*
00060  *#* Revision 1.1  2006/01/26 00:32:49  bernie
00061  *#* Graphics private header.
00062  *#*
00063  *#*/
00064 
00065 #ifndef GFX_GFX_P_H
00066 #define GFX_GFX_P_H
00067 
00068 #include <gfx/gfx.h>
00069 
00070 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
00071 
00072     /* We use ucoord_t to let the compiler optimize away the division/modulo. */
00073     #define RAST_ADDR(raster, x, y, stride) \
00074             ((raster) + (ucoord_t)(y) * (ucoord_t)(stride) + (ucoord_t)(x) / 8)
00075     #define RAST_MASK(raster, x, y) \
00076             (1 << (7 - (ucoord_t)(x) % 8))
00077 
00078 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
00079 
00080     /* We use ucoord_t to let the compiler optimize away the division/modulo. */
00081     #define RAST_ADDR(raster, x, y, stride) \
00082             ((raster) + ((ucoord_t)(y) / 8) * (ucoord_t)(stride) + (ucoord_t)(x))
00083     #define RAST_MASK(raster, x, y) \
00084             (1 << ((ucoord_t)(y) % 8))
00085 
00086 #else
00087     #error Unknown value of CONFIG_BITMAP_FMT
00088 #endif /* CONFIG_BITMAP_FMT */
00089 
00090 #define BM_ADDR(bm, x, y)  RAST_ADDR((bm)->raster, (x), (y), (bm)->stride)
00091 #define BM_MASK(bm, x, y)  RAST_MASK((bm)->raster, (x), (y))
00092 
00099 #define BM_PLOT(bm, x, y) \
00100     ( *BM_ADDR(bm, x, y) |= BM_MASK(bm, x, y) )
00101 
00108 #define BM_CLEAR(bm, x, y) \
00109     ( *BM_ADDR(bm, x, y) &= ~BM_MASK(bm, x, y) )
00110 
00118 #define BM_DRAWPIXEL(bm, x, y, fg_pen) \
00119     do { \
00120         uint8_t *p = BM_ADDR(bm, x, y); \
00121         uint8_t mask = BM_MASK(bm, x, y); \
00122         *p = (*p & ~mask) | ((fg_pen) ? mask : 0); \
00123     } while (0)
00124 
00133 #define BM_READPIXEL(bm, x, y) \
00134     ( *BM_ADDR(bm, x, y) & BM_MASK(bm, x, y) ? 1 : 0 )
00135 
00136 #define RAST_READPIXEL(raster, x, y, stride) \
00137         ( *RAST_ADDR(raster, x, y, stride) & RAST_MASK(raster, x, y) ? 1 : 0 )
00138 
00139 #endif /* GFX_GFX_P_H */