00001
00015 #ifndef GFX_GFX_H
00016 #define GFX_GFX_H
00017
00018 #include <cfg/compiler.h>
00019 #include <cpu/attr.h>
00020
00021 #include <appconfig.h>
00022
00027 #define BITMAP_FMT_PLANAR_H_MSB 1
00028 #define BITMAP_FMT_PLANAR_V_LSB 2
00029
00030
00031 #if !defined(CONFIG_BITMAP_FMT) || (CONFIG_BITMAP_FMT != BITMAP_FMT_PLANAR_H_MSB && CONFIG_BITMAP_FMT != BITMAP_FMT_PLANAR_V_LSB)
00032 #error CONFIG_BITMAP_FMT must be defined to either BITMAP_FMT_PLANAR_H_LSB or BITMAP_FMT_PLANAR_V_LSB
00033 #endif
00034 #if !defined(CONFIG_GFX_CLIPPING) || (CONFIG_GFX_CLIPPING != 0 && CONFIG_GFX_CLIPPING != 1)
00035 #error CONFIG_GFX_CLIPPING must be defined to either 0 or 1
00036 #endif
00037 #if !defined(CONFIG_GFX_TEXT) || (CONFIG_GFX_TEXT != 0 && CONFIG_GFX_TEXT != 1)
00038 #error CONFIG_GFX_TEXT must be defined to either 0 or 1
00039 #endif
00040
00041 EXTERN_C_BEGIN
00042
00044 typedef int coord_t;
00045 typedef unsigned int ucoord_t;
00046
00047 #if CONFIG_GFX_VCOORDS
00048
00049 typedef float vcoord_t;
00050 #endif
00051
00052
00075 typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect;
00076
00082 #define RECT_WIDTH(r) ((r)->xmax - (r)->xmin)
00083
00089 #define RECT_HEIGHT(r) ((r)->ymax - (r)->ymin)
00090
00091
00092 struct Font;
00093
00100 typedef struct Bitmap
00101 {
00102 uint8_t *raster;
00103 coord_t width, height;
00104 coord_t stride;
00105 coord_t penX, penY;
00107 #if CONFIG_GFX_CLIPPING || CONFIG_GFX_VCOORDS
00108 Rect cr;
00109 #endif
00110
00111 #if CONFIG_GFX_TEXT
00112 const struct Font *font;
00123 uint8_t styles;
00124 #endif
00125
00126 #if CONFIG_GFX_VCOORDS
00127
00131 vcoord_t orgX, orgY;
00132 vcoord_t scaleX, scaleY;
00133
00134 #endif
00135
00136 } Bitmap;
00137
00143 typedef struct Image
00144 {
00145 const uint8_t *raster;
00146 coord_t width;
00147 coord_t height;
00148 coord_t stride;
00149 } Image;
00150
00151 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
00152
00156 #define RAST_SIZE(width, height) ( ((width) + 7 / 8) * (height) )
00157
00158 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
00159
00163 #define RAST_SIZE(width, height) ( (width) * (((height) + 7) / 8) )
00164 #else
00165 #error Unknown value of CONFIG_BITMAP_FMT
00166 #endif
00167
00168
00169 void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h);
00170 void gfx_bitmapClear(Bitmap *bm);
00171 void gfx_blit (Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy);
00172 void gfx_blitRaster (Bitmap *dst, coord_t dx, coord_t dy, const uint8_t *raster, coord_t w, coord_t h, coord_t stride);
00173 void gfx_blitImage (Bitmap *dst, coord_t dx, coord_t dy, const Image *image);
00174 void gfx_line (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00175 void gfx_rectDraw (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00176 void gfx_rectFillC (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color);
00177 void gfx_rectFill (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00178 void gfx_rectClear (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00179 void gfx_moveTo (Bitmap *bm, coord_t x, coord_t y);
00180 void gfx_lineTo (Bitmap *bm, coord_t x, coord_t y);
00181 void gfx_setClipRect(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax);
00182
00183 #if CPU_HARVARD
00184 #include <mware/pgm.h>
00185 void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster);
00186 #endif
00187
00188 #if CONFIG_GFX_TEXT
00189 INLINE void gfx_setFont(Bitmap *bm, const struct Font *font)
00190 {
00191 bm->font = font;
00192 }
00193 #endif
00194
00195 #if CONFIG_GFX_VCOORDS
00196 void gfx_setViewRect(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
00197 coord_t gfx_transformX(Bitmap *bm, vcoord_t x);
00198 coord_t gfx_transformY(Bitmap *bm, vcoord_t y);
00199 void gfx_vline(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
00200 #endif
00201
00202 EXTERN_C_END
00203
00204 #endif