|
1 /* |
|
2 |
|
3 u8g2_ll_hvline.c |
|
4 |
|
5 low level hvline |
|
6 |
|
7 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
|
8 |
|
9 Copyright (c) 2016, olikraus@gmail.com |
|
10 All rights reserved. |
|
11 |
|
12 Redistribution and use in source and binary forms, with or without modification, |
|
13 are permitted provided that the following conditions are met: |
|
14 |
|
15 * Redistributions of source code must retain the above copyright notice, this list |
|
16 of conditions and the following disclaimer. |
|
17 |
|
18 * Redistributions in binary form must reproduce the above copyright notice, this |
|
19 list of conditions and the following disclaimer in the documentation and/or other |
|
20 materials provided with the distribution. |
|
21 |
|
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
35 |
|
36 |
|
37 *ptr |= or_mask |
|
38 *ptr ^= xor_mask |
|
39 |
|
40 color = 0: or_mask = 1, xor_mask = 1 |
|
41 color = 1: or_mask = 1, xor_mask = 0 |
|
42 color = 2: or_mask = 0, xor_mask = 1 |
|
43 |
|
44 if ( color <= 1 ) |
|
45 or_mask = mask; |
|
46 if ( color != 1 ) |
|
47 xor_mask = mask; |
|
48 |
|
49 */ |
|
50 |
|
51 #include "u8g2.h" |
|
52 #include <assert.h> |
|
53 |
|
54 /*=================================================*/ |
|
55 /* |
|
56 u8g2_ll_hvline_vertical_top_lsb |
|
57 SSD13xx |
|
58 UC1701 |
|
59 */ |
|
60 |
|
61 |
|
62 #ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION |
|
63 |
|
64 /* |
|
65 x,y Upper left position of the line within the local buffer (not the display!) |
|
66 len length of the line in pixel, len must not be 0 |
|
67 dir 0: horizontal line (left to right) |
|
68 1: vertical line (top to bottom) |
|
69 asumption: |
|
70 all clipping done |
|
71 */ |
|
72 void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir) |
|
73 { |
|
74 uint16_t offset; |
|
75 uint8_t *ptr; |
|
76 uint8_t bit_pos, mask; |
|
77 uint8_t or_mask, xor_mask; |
|
78 #ifdef __unix |
|
79 uint8_t *max_ptr = u8g2->tile_buf_ptr + u8g2_GetU8x8(u8g2)->display_info->tile_width*u8g2->tile_buf_height*8; |
|
80 #endif |
|
81 |
|
82 //assert(x >= u8g2->buf_x0); |
|
83 //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8); |
|
84 //assert(y >= u8g2->buf_y0); |
|
85 //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8); |
|
86 |
|
87 /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */ |
|
88 bit_pos = y; /* overflow truncate is ok here... */ |
|
89 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */ |
|
90 mask = 1; |
|
91 mask <<= bit_pos; |
|
92 |
|
93 or_mask = 0; |
|
94 xor_mask = 0; |
|
95 if ( u8g2->draw_color <= 1 ) |
|
96 or_mask = mask; |
|
97 if ( u8g2->draw_color != 1 ) |
|
98 xor_mask = mask; |
|
99 |
|
100 |
|
101 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */ |
|
102 offset &= ~7; |
|
103 offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width; |
|
104 ptr = u8g2->tile_buf_ptr; |
|
105 ptr += offset; |
|
106 ptr += x; |
|
107 |
|
108 if ( dir == 0 ) |
|
109 { |
|
110 do |
|
111 { |
|
112 #ifdef __unix |
|
113 assert(ptr < max_ptr); |
|
114 #endif |
|
115 *ptr |= or_mask; |
|
116 *ptr ^= xor_mask; |
|
117 ptr++; |
|
118 len--; |
|
119 } while( len != 0 ); |
|
120 } |
|
121 else |
|
122 { |
|
123 do |
|
124 { |
|
125 #ifdef __unix |
|
126 assert(ptr < max_ptr); |
|
127 #endif |
|
128 *ptr |= or_mask; |
|
129 *ptr ^= xor_mask; |
|
130 |
|
131 bit_pos++; |
|
132 bit_pos &= 7; |
|
133 |
|
134 len--; |
|
135 |
|
136 if ( bit_pos == 0 ) |
|
137 { |
|
138 ptr+=u8g2->pixel_buf_width; /* 6 Jan 17: Changed u8g2->width to u8g2->pixel_buf_width, issue #148 */ |
|
139 |
|
140 if ( u8g2->draw_color <= 1 ) |
|
141 or_mask = 1; |
|
142 if ( u8g2->draw_color != 1 ) |
|
143 xor_mask = 1; |
|
144 } |
|
145 else |
|
146 { |
|
147 or_mask <<= 1; |
|
148 xor_mask <<= 1; |
|
149 } |
|
150 } while( len != 0 ); |
|
151 } |
|
152 } |
|
153 |
|
154 |
|
155 |
|
156 #else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */ |
|
157 |
|
158 /* |
|
159 x,y position within the buffer |
|
160 */ |
|
161 static void u8g2_draw_pixel_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y) |
|
162 { |
|
163 uint16_t offset; |
|
164 uint8_t *ptr; |
|
165 uint8_t bit_pos, mask; |
|
166 |
|
167 //assert(x >= u8g2->buf_x0); |
|
168 //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8); |
|
169 //assert(y >= u8g2->buf_y0); |
|
170 //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8); |
|
171 |
|
172 /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */ |
|
173 bit_pos = y; /* overflow truncate is ok here... */ |
|
174 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */ |
|
175 mask = 1; |
|
176 mask <<= bit_pos; |
|
177 |
|
178 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */ |
|
179 offset &= ~7; |
|
180 offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width; |
|
181 ptr = u8g2->tile_buf_ptr; |
|
182 ptr += offset; |
|
183 ptr += x; |
|
184 |
|
185 |
|
186 if ( u8g2->draw_color <= 1 ) |
|
187 *ptr |= mask; |
|
188 if ( u8g2->draw_color != 1 ) |
|
189 *ptr ^= mask; |
|
190 |
|
191 } |
|
192 |
|
193 /* |
|
194 x,y Upper left position of the line within the local buffer (not the display!) |
|
195 len length of the line in pixel, len must not be 0 |
|
196 dir 0: horizontal line (left to right) |
|
197 1: vertical line (top to bottom) |
|
198 asumption: |
|
199 all clipping done |
|
200 */ |
|
201 void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir) |
|
202 { |
|
203 if ( dir == 0 ) |
|
204 { |
|
205 do |
|
206 { |
|
207 u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y); |
|
208 x++; |
|
209 len--; |
|
210 } while( len != 0 ); |
|
211 } |
|
212 else |
|
213 { |
|
214 do |
|
215 { |
|
216 u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y); |
|
217 y++; |
|
218 len--; |
|
219 } while( len != 0 ); |
|
220 } |
|
221 } |
|
222 |
|
223 |
|
224 #endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */ |
|
225 |
|
226 /*=================================================*/ |
|
227 /* |
|
228 u8g2_ll_hvline_horizontal_right_lsb |
|
229 ST7920 |
|
230 */ |
|
231 |
|
232 #ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION |
|
233 |
|
234 /* |
|
235 x,y Upper left position of the line within the local buffer (not the display!) |
|
236 len length of the line in pixel, len must not be 0 |
|
237 dir 0: horizontal line (left to right) |
|
238 1: vertical line (top to bottom) |
|
239 asumption: |
|
240 all clipping done |
|
241 */ |
|
242 |
|
243 void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir) |
|
244 { |
|
245 uint16_t offset; |
|
246 uint8_t *ptr; |
|
247 uint8_t bit_pos; |
|
248 uint8_t mask; |
|
249 uint8_t tile_width = u8g2_GetU8x8(u8g2)->display_info->tile_width; |
|
250 |
|
251 bit_pos = x; /* overflow truncate is ok here... */ |
|
252 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */ |
|
253 mask = 128; |
|
254 mask >>= bit_pos; |
|
255 |
|
256 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */ |
|
257 offset *= tile_width; |
|
258 offset += x>>3; |
|
259 ptr = u8g2->tile_buf_ptr; |
|
260 ptr += offset; |
|
261 |
|
262 if ( dir == 0 ) |
|
263 { |
|
264 |
|
265 do |
|
266 { |
|
267 |
|
268 if ( u8g2->draw_color <= 1 ) |
|
269 *ptr |= mask; |
|
270 if ( u8g2->draw_color != 1 ) |
|
271 *ptr ^= mask; |
|
272 |
|
273 mask >>= 1; |
|
274 if ( mask == 0 ) |
|
275 { |
|
276 mask = 128; |
|
277 ptr++; |
|
278 } |
|
279 |
|
280 //x++; |
|
281 len--; |
|
282 } while( len != 0 ); |
|
283 } |
|
284 else |
|
285 { |
|
286 do |
|
287 { |
|
288 if ( u8g2->draw_color <= 1 ) |
|
289 *ptr |= mask; |
|
290 if ( u8g2->draw_color != 1 ) |
|
291 *ptr ^= mask; |
|
292 |
|
293 ptr += tile_width; |
|
294 //y++; |
|
295 len--; |
|
296 } while( len != 0 ); |
|
297 } |
|
298 } |
|
299 |
|
300 #else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */ |
|
301 |
|
302 |
|
303 /* |
|
304 x,y position within the buffer |
|
305 */ |
|
306 static void u8g2_draw_pixel_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y) |
|
307 { |
|
308 uint16_t offset; |
|
309 uint8_t *ptr; |
|
310 uint8_t bit_pos, mask; |
|
311 |
|
312 //assert(x >= u8g2->buf_x0); |
|
313 //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8); |
|
314 //assert(y >= u8g2->buf_y0); |
|
315 //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8); |
|
316 |
|
317 /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */ |
|
318 bit_pos = x; /* overflow truncate is ok here... */ |
|
319 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */ |
|
320 mask = 128; |
|
321 mask >>= bit_pos; |
|
322 x >>= 3; |
|
323 |
|
324 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */ |
|
325 offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width; |
|
326 offset += x; |
|
327 ptr = u8g2->tile_buf_ptr; |
|
328 ptr += offset; |
|
329 |
|
330 |
|
331 if ( u8g2->draw_color <= 1 ) |
|
332 *ptr |= mask; |
|
333 if ( u8g2->draw_color != 1 ) |
|
334 *ptr ^= mask; |
|
335 |
|
336 } |
|
337 |
|
338 /* |
|
339 x,y Upper left position of the line within the local buffer (not the display!) |
|
340 len length of the line in pixel, len must not be 0 |
|
341 dir 0: horizontal line (left to right) |
|
342 1: vertical line (top to bottom) |
|
343 asumption: |
|
344 all clipping done |
|
345 */ |
|
346 void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir) |
|
347 { |
|
348 if ( dir == 0 ) |
|
349 { |
|
350 do |
|
351 { |
|
352 u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y); |
|
353 x++; |
|
354 len--; |
|
355 } while( len != 0 ); |
|
356 } |
|
357 else |
|
358 { |
|
359 do |
|
360 { |
|
361 u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y); |
|
362 y++; |
|
363 len--; |
|
364 } while( len != 0 ); |
|
365 } |
|
366 } |
|
367 |
|
368 #endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */ |