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.2 2006/01/24 21:55:43 aleph
20 *#* gfx_blit_P(): use RASTER_SIZE() to calculate raster size
22 *#* Revision 1.1 2006/01/24 02:17:49 bernie
23 *#* Split out gfx.c into bitmap.c and line.c.
30 #include <cfg/debug.h> /* ASSERT() */
31 #include <cfg/cpu.h> /* CPU_HARVARD */
32 #include <cfg/macros.h> /* MIN() */
33 #include <appconfig.h> /* CONFIG_GFX_CLIPPING */
35 #include <string.h> /* memset() */
38 * Initialize a Bitmap structure with the provided parameters.
40 * \note The pen position is reset to the origin.
42 void gfx_bitmapInit(Bitmap *bm, uint8_t *raster, coord_t w, coord_t h)
47 #if (CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB)
48 bm->stride = (w + 7) / 8;
49 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
52 #error Unknown value of CONFIG_BITMAP_FMT
53 #endif /* CONFIG_BITMAP_FMT */
57 #if CONFIG_GFX_CLIPPING
62 #endif /* CONFIG_GFX_CLIPPING */
67 * Clear the whole bitmap surface to the background color.
69 * \note This function does \b not update the current pen position.
71 void gfx_bitmapClear(Bitmap *bm)
73 memset(bm->raster, 0, RASTER_SIZE(bm->width, bm->height));
79 #include <avr/pgmspace.h> /* FIXME: memcpy_P() */
82 * Copy a raster picture located in program memory in the bitmap.
83 * The size of the raster to copy *must* be the same of the raster bitmap.
85 * \note This function does \b not update the current pen position
87 void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster)
89 memcpy_P(bm->raster, raster, RASTER_SIZE(bm->width, bm->height));
91 #endif /* CPU_HARVARD */
94 * Copy a rectangular area of a bitmap on another bitmap.
96 * Blitting is a common copy operation involving two bitmaps.
97 * A rectangular area of the source bitmap is copied bit-wise
98 * to a different position in the destination bitmap.
100 * \note Using the same bitmap for \a src and \a dst is unsupported.
102 * \param dst Bitmap where the operation writes
105 void gfx_blit(Bitmap *dst, Rect *rect, Bitmap *src, coord_t srcx, coord_t srcy)
107 coord_t dxmin, dymin, dxmax, dymax;
108 coord_t dx, dy, sx, sy;
111 * Clip coordinates inside dst->cr and src->width/height.
114 if (dxmin < dst->cr.xmin)
116 srcx += dst->cr.xmin - dxmin;
117 dxmin = dst->cr.xmin;
120 if (dymin < dst->cr.ymin)
122 srcy += dst->cr.ymin - dymin;
123 dymin = dst->cr.ymin;
125 dxmax = MIN(MIN(rect->xmax, rect->xmin + src->width), dst->cr.xmax);
126 dymax = MIN(MIN(rect->ymax, rect->ymin + src->height), dst->cr.ymax);
128 /* TODO: make it not as dog slow as this */
129 for (dx = dxmin, sx = srcx; dx < dxmax; ++dx, ++sx)
130 for (dy = dymin, sy = srcy; dy < dymax; ++dy, ++sy)
131 BM_DRAWPIXEL(dst, dx, dy, BM_READPIXEL(src, sx, sy));
136 * Set the bitmap clipping rectangle to the specified coordinates.
138 * All drawing performed on the bitmap will be clipped inside this
141 * \note Following the convention used in all other operations, the
142 * top-left pixels of the rectangle are included, while the
143 * bottom-right pixels are considered outside the clipping region.
145 void gfx_setClipRect(Bitmap *bm, coord_t minx, coord_t miny, coord_t maxx, coord_t maxy)
151 ASSERT(maxx <= bm->width);
152 ASSERT(maxy <= bm->height);
159 /* kprintf("cr.xmin = %d, cr.ymin = %d, cr.xmax = %d, cr.ymax = %d\n",
160 bm->cr.xMin, bm->cr.ymin, bm->cr.xmax, bm->cr.ymax);