Add bitmap format support; Improve some comments.
[bertos.git] / gfx / gfx.h
1 /*!
2  * \file
3  * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
4  * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
5  * This file is part of DevLib - See README.devlib for information.
6  *
7  * \version $Id$
8  *
9  * \author Bernardo Innocenti <bernie@develer.com>
10  * \author Stefano Fedrigo <aleph@develer.com>
11  *
12  * \brief General pourpose graphics routines
13  */
14
15 /*#*
16  *#* $Log$
17  *#* Revision 1.5  2006/01/17 02:31:29  bernie
18  *#* Add bitmap format support; Improve some comments.
19  *#*
20  *#* Revision 1.4  2006/01/16 03:30:57  bernie
21  *#* Make header C++ friendly.
22  *#*
23  *#* Revision 1.3  2005/11/27 23:33:40  bernie
24  *#* Use appconfig.h instead of cfg/config.h.
25  *#*
26  *#* Revision 1.2  2005/11/04 18:17:45  bernie
27  *#* Fix header guards and includes for new location of gfx module.
28  *#*
29  *#* Revision 1.1  2005/11/04 18:11:35  bernie
30  *#* Move graphics stuff from mware/ to gfx/.
31  *#*
32  *#* Revision 1.12  2005/11/04 16:20:02  bernie
33  *#* Fix reference to README.devlib in header.
34  *#*
35  *#* Revision 1.11  2005/04/11 19:10:28  bernie
36  *#* Include top-level headers from cfg/ subdir.
37  *#*
38  *#* Revision 1.10  2005/03/01 23:26:45  bernie
39  *#* Use new CPU-neutral program-memory API.
40  *#*
41  *#* Revision 1.9  2005/01/20 18:46:31  aleph
42  *#* Fix progmem includes.
43  *#*/
44
45 #ifndef GFX_GFX_H
46 #define GFX_GFX_H
47
48 #include <appconfig.h>
49 #include <cfg/compiler.h>
50 #include <cfg/cpu.h>
51
52 EXTERN_C_BEGIN
53
54 /*! Common type for coordinates expressed in pixel units */
55 typedef int coord_t;
56
57 #if CONFIG_GFX_VCOORDS
58 /*! Common type for coordinates expressed in logical units */
59 typedef float vcoord_t;
60 #endif /* CONFIG_GFX_VCOORDS */
61
62
63 typedef struct Rect { coord_t xmin, ymin, xmax, ymax; } Rect;
64
65
66 /*!
67  * Control structure to draw in a bitmap
68  */
69 typedef struct Bitmap
70 {
71         uint8_t *raster;        /*!< Pointer to byte array to hold the data */
72         coord_t width, height;  /*!< Width/Height in pixels */
73         coord_t stride;         /*!< Bytes per row. */
74         coord_t penX, penY;     /*!< Current pen position MoveTo()/LineTo() */
75
76         Rect cr;                /*!< Clip drawing inside this rectangle */
77
78 #if CONFIG_GFX_VCOORDS
79         /*!
80          * \name Logical coordinate system
81          * \{
82          */
83         vcoord_t orgX, orgY;
84         vcoord_t scaleX, scaleY;
85         /*\}*/
86 #endif /* CONFIG_GFX_VCOORDS */
87
88 } Bitmap;
89
90
91 /* Function prototypes */
92 extern void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h);
93 extern void gfx_bitmapClear(Bitmap *bm);
94 extern void gfx_line       (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
95 extern void gfx_rectDraw   (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
96 extern void gfx_rectFillC  (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color);
97 extern void gfx_rectFill   (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
98 extern void gfx_rectClear  (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2);
99 extern void gfx_moveTo     (Bitmap *bm, coord_t x,  coord_t y);
100 extern void gfx_lineTo     (Bitmap *bm, coord_t x,  coord_t y);
101 extern void gfx_setClipRect(Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax);
102
103 #if CPU_HARVARD
104         #include <mware/pgm.h>
105         extern void gfx_blit_P(Bitmap *bm, const pgm_uint8_t *raster);
106 #endif
107
108
109 #if CONFIG_GFX_VCOORDS
110 extern void gfx_setViewRect(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
111 extern coord_t gfx_transformX(Bitmap *bm, vcoord_t x);
112 extern coord_t gfx_transformY(Bitmap *bm, vcoord_t y);
113 extern void gfx_vline(Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2);
114 #endif /* CONFIG_GFX_VCOORDS */
115
116 EXTERN_C_END
117
118 #endif /* GFX_GFX_H */