gfx.h

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