36524f98476033ff3edf6061429b59df4fb944e2
[fw/altos] / src / draw / ao_draw.h
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #ifndef _AO_DRAW_H_
16 #define _AO_DRAW_H_
17
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include "ao_font.h"
21
22 struct ao_bitmap {
23         uint32_t        *base;
24         int16_t         stride; /* in units */
25         int16_t         width;  /* in pixels */
26         int16_t         height; /* in pixels */
27 };
28
29 struct ao_pattern {
30         uint8_t         pattern[8];
31 };
32
33 struct ao_glyph_metrics {
34         int8_t  width;
35         int8_t  height;
36         int8_t  x_off;
37         int8_t  y_off;
38         int8_t  advance;
39 };
40
41 struct ao_font {
42         const uint8_t   *bytes;
43         const uint16_t  *pos;
44         const struct ao_glyph_metrics *metrics;
45         int     max_width;
46         int     max_height;
47         int     ascent;
48 };
49
50 void
51 ao_copy(const struct ao_bitmap  *dst,
52         int16_t                 dst_x,
53         int16_t                 dst_y,
54         int16_t                 width,
55         int16_t                 height,
56         const struct ao_bitmap  *src,
57         int16_t                 src_x,
58         int16_t                 src_y,
59         uint8_t                 rop);
60
61 void
62 ao_rect(const struct ao_bitmap  *dst,
63         int16_t                 x,
64         int16_t                 y,
65         int16_t                 width,
66         int16_t                 height,
67         uint32_t                fill,
68         uint8_t                 rop);
69
70 void
71 ao_pattern(const struct ao_bitmap       *dst,
72            int16_t                      x,
73            int16_t                      y,
74            int16_t                      width,
75            int16_t                      height,
76            const struct ao_pattern      *pattern,
77            int16_t                      pat_x,
78            int16_t                      pat_y,
79            uint8_t                      rop);
80
81 void
82 ao_line(const struct ao_bitmap  *dst,
83         int16_t                 x1,
84         int16_t                 y1,
85         int16_t                 x2,
86         int16_t                 y2,
87         uint32_t                fill,
88         uint8_t                 rop);
89
90 void
91 ao_text(const struct ao_bitmap  *dst,
92         const struct ao_font    *font,
93         int16_t                 x,
94         int16_t                 y,
95         char                    *string,
96         uint32_t                fill,
97         uint8_t                 rop);
98
99 extern const struct ao_font FrutigerLT_Roman_50_font;
100
101 #define AO_SHIFT        5
102 #define AO_UNIT         (1 << AO_SHIFT)
103 #define AO_MASK         (AO_UNIT - 1)
104 #define AO_ALLONES      ((uint32_t) -1)
105
106 /*
107  *          dst
108  *         0   1
109  *
110  *      0  a   b
111  *  src
112  *      1  c   d
113  *
114  *      ROP = abcd
115  */
116
117 #define AO_CLEAR         0x0    /* 0 */
118 #define AO_AND           0x1    /* src AND dst */
119 #define AO_AND_REVERSE   0x2    /* src AND NOT dst */
120 #define AO_COPY          0x3    /* src */
121 #define AO_AND_INVERTED  0x4    /* NOT src AND dst */
122 #define AO_NOOP          0x5    /* dst */
123 #define AO_XOR           0x6    /* src XOR dst */
124 #define AO_OR            0x7    /* src OR dst */
125 #define AO_NOR           0x8    /* NOT src AND NOT dst */
126 #define AO_EQUIV         0x9    /* NOT src XOR dst */
127 #define AO_INVERT        0xa    /* NOT dst */
128 #define AO_OR_REVERSE    0xb    /* src OR NOT dst */
129 #define AO_COPY_INVERTED 0xc    /* NOT src */
130 #define AO_OR_INVERTED   0xd    /* NOT src OR dst */
131 #define AO_NAND          0xe    /* NOT src OR NOT dst */
132 #define AO_SET           0xf    /* 1 */
133
134 #endif /* _AO_DRAW_H_ */