BeRTOS
gfx.h
Go to the documentation of this file.
00001 
00046 #ifndef GFX_GFX_H
00047 #define GFX_GFX_H
00048 
00049 #include "cfg/cfg_gfx.h"    /* CONFIG_GFX_* */
00050 #include <cfg/compiler.h>
00051 
00052 #include <cpu/attr.h>       /* CPU_HARVARD */
00053 
00054 
00055 #define CONFIG_CHART_TYPE_X uint8_t ///< Type for the chart dataset
00056 #define CONFIG_CHART_TYPE_Y uint8_t ///< Type for the chart dataset
00057 
00063 #define BITMAP_FMT_PLANAR_H_MSB  1  
00064 #define BITMAP_FMT_PLANAR_V_LSB  2  
00065 /* \} */
00066 
00067 #if !defined(CONFIG_BITMAP_FMT) || (CONFIG_BITMAP_FMT != BITMAP_FMT_PLANAR_H_MSB && CONFIG_BITMAP_FMT != BITMAP_FMT_PLANAR_V_LSB)
00068     #error CONFIG_BITMAP_FMT must be defined to either BITMAP_FMT_PLANAR_H_LSB or BITMAP_FMT_PLANAR_V_LSB
00069 #endif
00070 #if !defined(CONFIG_GFX_CLIPPING) || (CONFIG_GFX_CLIPPING != 0 && CONFIG_GFX_CLIPPING != 1)
00071     #error CONFIG_GFX_CLIPPING must be defined to either 0 or 1
00072 #endif
00073 #if !defined(CONFIG_GFX_TEXT) || (CONFIG_GFX_TEXT != 0 && CONFIG_GFX_TEXT != 1)
00074     #error CONFIG_GFX_TEXT must be defined to either 0 or 1
00075 #endif
00076 
00077 EXTERN_C_BEGIN
00078 
00080 typedef int coord_t;
00081 typedef unsigned int ucoord_t;
00082 
00083 #if CONFIG_GFX_VCOORDS
00084 
00085 typedef float vcoord_t;
00086 #endif /* CONFIG_GFX_VCOORDS */
00087 
00088 
00111 typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect;
00112 
00118 #define RECT_WIDTH(r)   ((r)->xmax - (r)->xmin)
00119 
00125 #define RECT_HEIGHT(r)  ((r)->ymax - (r)->ymin)
00126 
00127 /* Fwd decl */
00128 struct Font;
00129 
00136 typedef struct Bitmap
00137 {
00138     uint8_t *raster;        
00139     coord_t width, height;  
00140     coord_t stride;         
00141     coord_t penX, penY;     
00143 #if CONFIG_GFX_CLIPPING || CONFIG_GFX_VCOORDS
00144     Rect cr;                
00145 #endif
00146 
00147 #if CONFIG_GFX_TEXT
00148     const struct Font *font;
00159     uint8_t styles;
00160 #endif /* CONFIG_GFX_TEXT */
00161 
00162 #if CONFIG_GFX_VCOORDS
00163 
00167     vcoord_t orgX, orgY;
00168     vcoord_t scaleX, scaleY;
00169     /*\}*/
00170 #endif /* CONFIG_GFX_VCOORDS */
00171 
00172 } Bitmap;
00173 
00179 typedef struct Image
00180 {
00181     const uint8_t *raster;   
00182     coord_t width;     
00183     coord_t height;    
00184     coord_t stride;    
00185 } Image;
00186 
00187 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
00188 
00192     #define RAST_SIZE(width, height) ( (((width) + 7) / 8) * (height) )
00193 
00194 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
00195 
00199     #define RAST_SIZE(width, height) ( (width) * (((height) + 7) / 8) )
00200 #else
00201     #error Unknown value of CONFIG_BITMAP_FMT
00202 #endif /* CONFIG_BITMAP_FMT */
00203 
00204 /* Function prototypes */
00205 void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h);
00206 void gfx_bitmapClear(Bitmap *bm);
00207 void gfx_blit       (Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy);
00208 void gfx_blitRaster (Bitmap *dst, coord_t dx, coord_t dy, const uint8_t *raster, coord_t w, coord_t h, coord_t stride);
00209 void gfx_blitImage  (Bitmap *dst, coord_t dx, coord_t dy, const Image *image);
00210 void gfx_line       (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00211 void gfx_rectDraw   (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00212 void gfx_rectFillC  (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color);
00213 void gfx_rectFill   (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00214 void gfx_rectClear  (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
00215 void gfx_moveTo     (Bitmap *bm, coord_t x,  coord_t y);
00216 void gfx_lineTo     (Bitmap *bm, coord_t x,  coord_t y);
00217 void gfx_setClipRect(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax);
00218 
00219 #if CPU_HARVARD
00220     #include <cpu/pgm.h>
00221     void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster);
00222 #endif
00223 
00224 #if CONFIG_GFX_TEXT
00225 INLINE void gfx_setFont(Bitmap *bm, const struct Font *font)
00226 {
00227     bm->font = font;
00228 }
00229 #endif
00230 
00231 #if CONFIG_GFX_VCOORDS
00232 void gfx_setViewRect(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
00233 coord_t gfx_transformX(Bitmap *bm, vcoord_t x);
00234 coord_t gfx_transformY(Bitmap *bm, vcoord_t y);
00235 void gfx_vline(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
00236 #endif /* CONFIG_GFX_VCOORDS */
00237 
00238 EXTERN_C_END
00239  //defgroup gfx
00241 #endif /* GFX_GFX_H */