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.1 2006/01/24 02:17:49 bernie
20 *#* Split out gfx.c into bitmap.c and line.c.
27 #include <cfg/debug.h> /* ASSERT() */
28 #include <cfg/cpu.h> /* CPU_HARVARD */
29 #include <cfg/macros.h> /* MIN() */
30 #include <appconfig.h> /* CONFIG_GFX_CLIPPING */
32 #include <string.h> /* memset() */
35 * Initialize a Bitmap structure with the provided parameters.
37 * \note The pen position is reset to the origin.
39 void gfx_bitmapInit(Bitmap *bm, uint8_t *raster, coord_t w, coord_t h)
44 #if (CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB)
45 bm->stride = (w + 7) / 8;
46 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
49 #error Unknown value of CONFIG_BITMAP_FMT
50 #endif /* CONFIG_BITMAP_FMT */
54 #if CONFIG_GFX_CLIPPING
59 #endif /* CONFIG_GFX_CLIPPING */
64 * Clear the whole bitmap surface to the background color.
66 * \note This function does \b not update the current pen position.
68 void gfx_bitmapClear(Bitmap *bm)
70 memset(bm->raster, 0, RASTER_SIZE(bm->width, bm->height));
76 #include <avr/pgmspace.h> /* FIXME: memcpy_P() */
79 * Copy a raster picture located in program memory in the bitmap.
80 * The size of the raster to copy *must* be the same of the raster bitmap.
82 * \note This function does \b not update the current pen position
84 void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster)
86 memcpy_P(bm->raster, raster, (bm->height / 8) * bm->width);
88 #endif /* CPU_HARVARD */
91 * Copy a rectangular area of a bitmap on another bitmap.
93 * Blitting is a common copy operation involving two bitmaps.
94 * A rectangular area of the source bitmap is copied bit-wise
95 * to a different position in the destination bitmap.
97 * \note Using the same bitmap for \a src and \a dst is unsupported.
99 * \param dst Bitmap where the operation writes
102 void gfx_blit(Bitmap *dst, Rect *rect, Bitmap *src, coord_t srcx, coord_t srcy)
104 coord_t dxmin, dymin, dxmax, dymax;
105 coord_t dx, dy, sx, sy;
108 * Clip coordinates inside dst->cr and src->width/height.
111 if (dxmin < dst->cr.xmin)
113 srcx += dst->cr.xmin - dxmin;
114 dxmin = dst->cr.xmin;
117 if (dymin < dst->cr.ymin)
119 srcy += dst->cr.ymin - dymin;
120 dymin = dst->cr.ymin;
122 dxmax = MIN(MIN(rect->xmax, rect->xmin + src->width), dst->cr.xmax);
123 dymax = MIN(MIN(rect->ymax, rect->ymin + src->height), dst->cr.ymax);
125 /* TODO: make it not as dog slow as this */
126 for (dx = dxmin, sx = srcx; dx < dxmax; ++dx, ++sx)
127 for (dy = dymin, sy = srcy; dy < dymax; ++dy, ++sy)
128 BM_DRAWPIXEL(dst, dx, dy, BM_READPIXEL(src, sx, sy));
133 * Set the bitmap clipping rectangle to the specified coordinates.
135 * All drawing performed on the bitmap will be clipped inside this
138 * \note Following the convention used in all other operations, the
139 * top-left pixels of the rectangle are included, while the
140 * bottom-right pixels are considered outside the clipping region.
142 void gfx_setClipRect(Bitmap *bm, coord_t minx, coord_t miny, coord_t maxx, coord_t maxy)
148 ASSERT(maxx <= bm->width);
149 ASSERT(maxy <= bm->height);
156 /* kprintf("cr.xmin = %d, cr.ymin = %d, cr.xmax = %d, cr.ymax = %d\n",
157 bm->cr.xMin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax);