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>
12 * \author Stefano Fedrigo <aleph@develer.com>
14 * \brief Bitmap manipulation routines.
19 *#* Revision 1.3 2006/01/26 00:36:48 bernie
20 *#* Const correctness for some new functions.
22 *#* Revision 1.2 2006/01/24 21:55:43 aleph
23 *#* gfx_blit_P(): use RASTER_SIZE() to calculate raster size
25 *#* Revision 1.1 2006/01/24 02:17:49 bernie
26 *#* Split out gfx.c into bitmap.c and line.c.
33 #include <cfg/debug.h> /* ASSERT() */
34 #include <cfg/cpu.h> /* CPU_HARVARD */
35 #include <cfg/macros.h> /* MIN() */
36 #include <appconfig.h> /* CONFIG_GFX_CLIPPING */
38 #include <string.h> /* memset() */
41 * Initialize a Bitmap structure with the provided parameters.
43 * \note The pen position is reset to the origin.
45 void gfx_bitmapInit(Bitmap *bm, uint8_t *raster, coord_t w, coord_t h)
50 #if (CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB)
51 bm->stride = (w + 7) / 8;
52 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
55 #error Unknown value of CONFIG_BITMAP_FMT
56 #endif /* CONFIG_BITMAP_FMT */
60 #if CONFIG_GFX_CLIPPING
65 #endif /* CONFIG_GFX_CLIPPING */
70 * Clear the whole bitmap surface to the background color.
72 * \note This function does \b not update the current pen position.
74 void gfx_bitmapClear(Bitmap *bm)
76 memset(bm->raster, 0, RASTER_SIZE(bm->width, bm->height));
82 #include <avr/pgmspace.h> /* FIXME: memcpy_P() */
85 * Copy a raster picture located in program memory in the bitmap.
86 * The size of the raster to copy *must* be the same of the raster bitmap.
88 * \note This function does \b not update the current pen position
90 void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster)
92 memcpy_P(bm->raster, raster, RASTER_SIZE(bm->width, bm->height));
94 #endif /* CPU_HARVARD */
97 * Copy a rectangular area of a bitmap on another bitmap.
99 * Blitting is a common copy operation involving two bitmaps.
100 * A rectangular area of the source bitmap is copied bit-wise
101 * to a different position in the destination bitmap.
103 * \note Using the same bitmap for \a src and \a dst is unsupported.
105 * \param dst Bitmap where the operation writes
108 void gfx_blit(Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy)
110 coord_t dxmin, dymin, dxmax, dymax;
111 coord_t dx, dy, sx, sy;
114 * Clip coordinates inside dst->cr and src->width/height.
117 if (dxmin < dst->cr.xmin)
119 srcx += dst->cr.xmin - dxmin;
120 dxmin = dst->cr.xmin;
123 if (dymin < dst->cr.ymin)
125 srcy += dst->cr.ymin - dymin;
126 dymin = dst->cr.ymin;
128 dxmax = MIN(MIN(rect->xmax, rect->xmin + src->width), dst->cr.xmax);
129 dymax = MIN(MIN(rect->ymax, rect->ymin + src->height), dst->cr.ymax);
131 /* TODO: make it not as dog slow as this */
132 for (dx = dxmin, sx = srcx; dx < dxmax; ++dx, ++sx)
133 for (dy = dymin, sy = srcy; dy < dymax; ++dy, ++sy)
134 BM_DRAWPIXEL(dst, dx, dy, BM_READPIXEL(src, sx, sy));
139 * Set the bitmap clipping rectangle to the specified coordinates.
141 * All drawing performed on the bitmap will be clipped inside this
144 * \note Following the convention used in all other operations, the
145 * top-left pixels of the rectangle are included, while the
146 * bottom-right pixels are considered outside the clipping region.
148 void gfx_setClipRect(Bitmap *bm, coord_t minx, coord_t miny, coord_t maxx, coord_t maxy)
154 ASSERT(maxx <= bm->width);
155 ASSERT(maxy <= bm->height);
162 /* kprintf("cr.xmin = %d, cr.ymin = %d, cr.xmax = %d, cr.ymax = %d\n",
163 bm->cr.xMin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax);