00001
00041 #include "gfx.h"
00042 #include "gfx_p.h"
00043
00044 #include "cfg/cfg_gfx.h"
00045 #include <cfg/macros.h>
00046 #include <cfg/debug.h>
00047
00048 #include <cpu/attr.h>
00049
00050 #include <string.h>
00051
00052 #if CONFIG_GFX_TEXT
00053 #include <gfx/font.h>
00054 #endif
00055
00056
00062 void gfx_bitmapInit(Bitmap *bm, uint8_t *raster, coord_t w, coord_t h)
00063 {
00064 bm->raster = raster;
00065 bm->width = w;
00066 bm->height = h;
00067 #if (CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB)
00068 bm->stride = (w + 7) / 8;
00069 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
00070 bm->stride = w;
00071 #else
00072 #error Unknown value of CONFIG_BITMAP_FMT
00073 #endif
00074 bm->penX = 0;
00075 bm->penY = 0;
00076
00077 #if CONFIG_GFX_TEXT
00078 gfx_setFont(bm, &default_font);
00079 bm->styles = 0;
00080 #endif
00081
00082 #if CONFIG_GFX_CLIPPING
00083 bm->cr.xmin = 0;
00084 bm->cr.ymin = 0;
00085 bm->cr.xmax = w;
00086 bm->cr.ymax = h;
00087 #endif
00088 }
00089
00090
00097 void gfx_bitmapClear(Bitmap *bm)
00098 {
00099 memset(bm->raster, 0, RAST_SIZE(bm->width, bm->height));
00100 }
00101
00102
00103 #if CPU_HARVARD
00104
00105 #include <avr/pgmspace.h>
00106
00113 void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster)
00114 {
00115 memcpy_P(bm->raster, raster, RAST_SIZE(bm->width, bm->height));
00116 }
00117 #endif
00118
00119 #if CONFIG_GFX_CLIPPING
00120
00130 #define gfx_clip(dmin, dmax, smin, cmin, cmax) \
00131 do { \
00132 if ((dmin) < (cmin)) \
00133 { \
00134 (smin) += (cmin) - (dmin); \
00135 (dmin) = (cmin); \
00136 } \
00137 (dmax) = MIN((dmax), (cmax)); \
00138 } while(0)
00139
00140 #else
00141
00142 #define gfx_clip(dmin, dmax, smin, cmin, cmax) do { } while (0)
00143
00144 #endif
00145
00146
00164 void gfx_blit(Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy)
00165 {
00166 coord_t dxmin, dymin, dxmax, dymax;
00167 coord_t dx, dy, sx, sy;
00168
00169
00170
00171
00172 dxmin = rect->xmin;
00173 dymin = rect->ymin;
00174 dxmax = MIN(rect->xmax, rect->xmin + src->width);
00175 dymax = MIN(rect->ymax, rect->ymin + src->height);
00176
00177
00178 gfx_clip(dxmin, dxmax, srcx, dst->cr.xmin, dst->cr.xmax);
00179 gfx_clip(dymin, dymax, srcy, dst->cr.ymin, dst->cr.ymax);
00180
00181
00182
00183
00184
00185 for (dx = dxmin, sx = srcx; dx < dxmax; ++dx, ++sx)
00186 for (dy = dymin, sy = srcy; dy < dymax; ++dy, ++sy)
00187 BM_DRAWPIXEL(dst, dx, dy, BM_READPIXEL(src, sx, sy));
00188 }
00189
00197 void gfx_blitRaster(Bitmap *dst, coord_t dxmin, coord_t dymin,
00198 const uint8_t *raster, coord_t w, coord_t h, coord_t stride)
00199 {
00200 coord_t dxmax = dxmin + w, dymax = dymin + h;
00201 coord_t sxmin = 0, symin = 0;
00202 coord_t dx, dy, sx, sy;
00203
00204
00205 gfx_clip(dxmin, dxmax, sxmin, dst->cr.xmin, dst->cr.xmax);
00206 gfx_clip(dymin, dymax, symin, dst->cr.ymin, dst->cr.ymax);
00207
00208
00209
00210
00211
00212 for (dx = dxmin, sx = sxmin; dx < dxmax; ++dx, ++sx)
00213 for (dy = dymin, sy = symin; dy < dymax; ++dy, ++sy)
00214 BM_DRAWPIXEL(dst, dx, dy, RAST_READPIXEL(raster, sx, sy, stride));
00215 }
00216
00222 void gfx_blitImage(Bitmap *dst, coord_t dxmin, coord_t dymin, const Image *image)
00223 {
00224 ASSERT(image);
00225
00226 gfx_blitRaster(dst, dxmin, dymin,
00227 image->raster, image->width, image->height, image->stride);
00228 }
00229
00230
00231 #if CONFIG_GFX_CLIPPING || CONFIG_GFX_VCOORDS
00232
00248 void gfx_setClipRect(Bitmap *bm, coord_t minx, coord_t miny, coord_t maxx, coord_t maxy)
00249 {
00250 ASSERT(minx < maxx);
00251 ASSERT(miny < maxy);
00252 ASSERT(miny >= 0);
00253 ASSERT(minx >= 0);
00254 ASSERT(maxx <= bm->width);
00255 ASSERT(maxy <= bm->height);
00256
00257 bm->cr.xmin = minx;
00258 bm->cr.ymin = miny;
00259 bm->cr.xmax = maxx;
00260 bm->cr.ymax = maxy;
00261
00262
00263
00264 }
00265
00266 #endif
00267