|
1 /* |
|
2 |
|
3 u8g2_bitmap.c |
|
4 |
|
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
|
6 |
|
7 Copyright (c) 2016, olikraus@gmail.com |
|
8 All rights reserved. |
|
9 |
|
10 Redistribution and use in source and binary forms, with or without modification, |
|
11 are permitted provided that the following conditions are met: |
|
12 |
|
13 * Redistributions of source code must retain the above copyright notice, this list |
|
14 of conditions and the following disclaimer. |
|
15 |
|
16 * Redistributions in binary form must reproduce the above copyright notice, this |
|
17 list of conditions and the following disclaimer in the documentation and/or other |
|
18 materials provided with the distribution. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
33 |
|
34 */ |
|
35 |
|
36 #include "u8g2.h" |
|
37 |
|
38 |
|
39 void u8g2_SetBitmapMode(u8g2_t *u8g2, uint8_t is_transparent) { |
|
40 u8g2->bitmap_transparency = is_transparent; |
|
41 } |
|
42 |
|
43 /* |
|
44 x,y Position on the display |
|
45 len Length of bitmap line in pixel. Note: This differs from u8glib which had a bytecount here. |
|
46 b Pointer to the bitmap line. |
|
47 Only draw pixels which are set. |
|
48 */ |
|
49 |
|
50 void u8g2_DrawHorizontalBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b) |
|
51 { |
|
52 uint8_t mask; |
|
53 uint8_t color = u8g2->draw_color; |
|
54 uint8_t ncolor = (color == 0 ? 1 : 0); |
|
55 |
|
56 #ifdef U8G2_WITH_INTERSECTION |
|
57 if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 ) |
|
58 return; |
|
59 #endif /* U8G2_WITH_INTERSECTION */ |
|
60 |
|
61 mask = 128; |
|
62 while(len > 0) |
|
63 { |
|
64 if ( *b & mask ) { |
|
65 u8g2->draw_color = color; |
|
66 u8g2_DrawHVLine(u8g2, x, y, 1, 0); |
|
67 } else if ( u8g2->bitmap_transparency == 0 ) { |
|
68 u8g2->draw_color = ncolor; |
|
69 u8g2_DrawHVLine(u8g2, x, y, 1, 0); |
|
70 } |
|
71 |
|
72 x++; |
|
73 mask >>= 1; |
|
74 if ( mask == 0 ) |
|
75 { |
|
76 mask = 128; |
|
77 b++; |
|
78 } |
|
79 len--; |
|
80 } |
|
81 u8g2->draw_color = color; |
|
82 } |
|
83 |
|
84 |
|
85 /* u8glib compatible bitmap draw function */ |
|
86 void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap) |
|
87 { |
|
88 u8g2_uint_t w; |
|
89 w = cnt; |
|
90 w *= 8; |
|
91 #ifdef U8G2_WITH_INTERSECTION |
|
92 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 ) |
|
93 return; |
|
94 #endif /* U8G2_WITH_INTERSECTION */ |
|
95 |
|
96 while( h > 0 ) |
|
97 { |
|
98 u8g2_DrawHorizontalBitmap(u8g2, x, y, w, bitmap); |
|
99 bitmap += cnt; |
|
100 y++; |
|
101 h--; |
|
102 } |
|
103 } |
|
104 |
|
105 |
|
106 |
|
107 void u8g2_DrawHXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b) |
|
108 { |
|
109 uint8_t mask; |
|
110 uint8_t color = u8g2->draw_color; |
|
111 uint8_t ncolor = (color == 0 ? 1 : 0); |
|
112 #ifdef U8G2_WITH_INTERSECTION |
|
113 if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 ) |
|
114 return; |
|
115 #endif /* U8G2_WITH_INTERSECTION */ |
|
116 |
|
117 mask = 1; |
|
118 while(len > 0) { |
|
119 if ( *b & mask ) { |
|
120 u8g2->draw_color = color; |
|
121 u8g2_DrawHVLine(u8g2, x, y, 1, 0); |
|
122 } else if ( u8g2->bitmap_transparency == 0 ) { |
|
123 u8g2->draw_color = ncolor; |
|
124 u8g2_DrawHVLine(u8g2, x, y, 1, 0); |
|
125 } |
|
126 x++; |
|
127 mask <<= 1; |
|
128 if ( mask == 0 ) |
|
129 { |
|
130 mask = 1; |
|
131 b++; |
|
132 } |
|
133 len--; |
|
134 } |
|
135 u8g2->draw_color = color; |
|
136 } |
|
137 |
|
138 |
|
139 void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap) |
|
140 { |
|
141 u8g2_uint_t blen; |
|
142 blen = w; |
|
143 blen += 7; |
|
144 blen >>= 3; |
|
145 #ifdef U8G2_WITH_INTERSECTION |
|
146 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 ) |
|
147 return; |
|
148 #endif /* U8G2_WITH_INTERSECTION */ |
|
149 |
|
150 while( h > 0 ) |
|
151 { |
|
152 u8g2_DrawHXBM(u8g2, x, y, w, bitmap); |
|
153 bitmap += blen; |
|
154 y++; |
|
155 h--; |
|
156 } |
|
157 } |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 void u8g2_DrawHXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b) |
|
165 { |
|
166 uint8_t mask; |
|
167 uint8_t color = u8g2->draw_color; |
|
168 uint8_t ncolor = (color == 0 ? 1 : 0); |
|
169 #ifdef U8G2_WITH_INTERSECTION |
|
170 if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 ) |
|
171 return; |
|
172 #endif /* U8G2_WITH_INTERSECTION */ |
|
173 |
|
174 mask = 1; |
|
175 while(len > 0) |
|
176 { |
|
177 if( u8x8_pgm_read(b) & mask ) { |
|
178 u8g2->draw_color = color; |
|
179 u8g2_DrawHVLine(u8g2, x, y, 1, 0); |
|
180 } else if( u8g2->bitmap_transparency == 0 ) { |
|
181 u8g2->draw_color = ncolor; |
|
182 u8g2_DrawHVLine(u8g2, x, y, 1, 0); |
|
183 } |
|
184 |
|
185 x++; |
|
186 mask <<= 1; |
|
187 if ( mask == 0 ) |
|
188 { |
|
189 mask = 1; |
|
190 b++; |
|
191 } |
|
192 len--; |
|
193 } |
|
194 u8g2->draw_color = color; |
|
195 } |
|
196 |
|
197 |
|
198 void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap) |
|
199 { |
|
200 u8g2_uint_t blen; |
|
201 blen = w; |
|
202 blen += 7; |
|
203 blen >>= 3; |
|
204 #ifdef U8G2_WITH_INTERSECTION |
|
205 if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 ) |
|
206 return; |
|
207 #endif /* U8G2_WITH_INTERSECTION */ |
|
208 |
|
209 while( h > 0 ) |
|
210 { |
|
211 u8g2_DrawHXBMP(u8g2, x, y, w, bitmap); |
|
212 bitmap += blen; |
|
213 y++; |
|
214 h--; |
|
215 } |
|
216 } |
|
217 |
|
218 |