Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8g2_ll_hvline.c

372 lines · 9.0 KB · C

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*/
72void 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 (void)max_ptr; /* silence unused variable warning if asserts are disabled */
81#endif
82
83 //assert(x >= u8g2->buf_x0);
84 //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
85 //assert(y >= u8g2->buf_y0);
86 //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
87
88 /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
89 bit_pos = y; /* overflow truncate is ok here... */
90 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
91 mask = 1;
92 mask <<= bit_pos;
93
94 or_mask = 0;
95 xor_mask = 0;
96 if ( u8g2->draw_color <= 1 )
97 or_mask = mask;
98 if ( u8g2->draw_color != 1 )
99 xor_mask = mask;
100
101
102 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
103 offset &= ~7;
104 offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
105 ptr = u8g2->tile_buf_ptr;
106 ptr += offset;
107 ptr += x;
108
109 if ( dir == 0 )
110 {
111 do
112 {
113#ifdef __unix
114 assert(ptr < max_ptr);
115#endif
116 *ptr |= or_mask;
117 *ptr ^= xor_mask;
118 ptr++;
119 len--;
120 } while( len != 0 );
121 }
122 else
123 {
124 do
125 {
126#ifdef __unix
127 assert(ptr < max_ptr);
128#endif
129 *ptr |= or_mask;
130 *ptr ^= xor_mask;
131
132 bit_pos++;
133 bit_pos &= 7;
134
135 len--;
136
137 if ( bit_pos == 0 )
138 {
139 ptr+=u8g2->pixel_buf_width; /* 6 Jan 17: Changed u8g2->width to u8g2->pixel_buf_width, issue #148 */
140
141 if ( u8g2->draw_color <= 1 )
142 or_mask = 1;
143 if ( u8g2->draw_color != 1 )
144 xor_mask = 1;
145 }
146 else
147 {
148 or_mask <<= 1;
149 xor_mask <<= 1;
150 }
151 } while( len != 0 );
152 }
153}
154
155
156
157#else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
158
159/*
160 x,y position within the buffer
161*/
162static void u8g2_draw_pixel_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
163{
164 uint16_t offset;
165 uint8_t *ptr;
166 uint8_t bit_pos, mask;
167
168 //assert(x >= u8g2->buf_x0);
169 //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
170 //assert(y >= u8g2->buf_y0);
171 //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
172
173 /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
174 bit_pos = y; /* overflow truncate is ok here... */
175 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
176 mask = 1;
177 mask <<= bit_pos;
178
179 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
180 offset &= ~7;
181 offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
182 ptr = u8g2->tile_buf_ptr;
183 ptr += offset;
184 ptr += x;
185
186
187 if ( u8g2->draw_color <= 1 )
188 *ptr |= mask;
189 if ( u8g2->draw_color != 1 )
190 *ptr ^= mask;
191
192}
193
194/*
195 x,y Upper left position of the line within the local buffer (not the display!)
196 len length of the line in pixel, len must not be 0
197 dir 0: horizontal line (left to right)
198 1: vertical line (top to bottom)
199 asumption:
200 all clipping done
201*/
202void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
203{
204 if ( dir == 0 )
205 {
206 do
207 {
208 u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
209 x++;
210 len--;
211 } while( len != 0 );
212 }
213 else
214 {
215 do
216 {
217 u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
218 y++;
219 len--;
220 } while( len != 0 );
221 }
222}
223
224
225#endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
226
227/*=================================================*/
228/*
229 u8g2_ll_hvline_horizontal_right_lsb
230 ST7920
231*/
232
233#ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION
234
235/*
236 x,y Upper left position of the line within the local buffer (not the display!)
237 len length of the line in pixel, len must not be 0
238 dir 0: horizontal line (left to right)
239 1: vertical line (top to bottom)
240 asumption:
241 all clipping done
242*/
243
244/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
245void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
246{
247 uint16_t offset;
248 uint8_t *ptr;
249 uint8_t bit_pos;
250 uint8_t mask;
251 uint8_t tile_width = u8g2_GetU8x8(u8g2)->display_info->tile_width;
252
253 bit_pos = x; /* overflow truncate is ok here... */
254 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
255 mask = 128;
256 mask >>= bit_pos;
257
258 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
259 offset *= tile_width;
260 offset += x>>3;
261 ptr = u8g2->tile_buf_ptr;
262 ptr += offset;
263
264 if ( dir == 0 )
265 {
266
267 do
268 {
269
270 if ( u8g2->draw_color <= 1 )
271 *ptr |= mask;
272 if ( u8g2->draw_color != 1 )
273 *ptr ^= mask;
274
275 mask >>= 1;
276 if ( mask == 0 )
277 {
278 mask = 128;
279 ptr++;
280 }
281
282 //x++;
283 len--;
284 } while( len != 0 );
285 }
286 else
287 {
288 do
289 {
290 if ( u8g2->draw_color <= 1 )
291 *ptr |= mask;
292 if ( u8g2->draw_color != 1 )
293 *ptr ^= mask;
294
295 ptr += tile_width;
296 //y++;
297 len--;
298 } while( len != 0 );
299 }
300}
301
302#else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
303
304
305/*
306 x,y position within the buffer
307*/
308/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
309static void u8g2_draw_pixel_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
310{
311 uint16_t offset;
312 uint8_t *ptr;
313 uint8_t bit_pos, mask;
314
315 //assert(x >= u8g2->buf_x0);
316 //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
317 //assert(y >= u8g2->buf_y0);
318 //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
319
320 /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
321 bit_pos = x; /* overflow truncate is ok here... */
322 bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
323 mask = 128;
324 mask >>= bit_pos;
325 x >>= 3;
326
327 offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
328 offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
329 offset += x;
330 ptr = u8g2->tile_buf_ptr;
331 ptr += offset;
332
333
334 if ( u8g2->draw_color <= 1 )
335 *ptr |= mask;
336 if ( u8g2->draw_color != 1 )
337 *ptr ^= mask;
338
339}
340
341/*
342 x,y Upper left position of the line within the local buffer (not the display!)
343 len length of the line in pixel, len must not be 0
344 dir 0: horizontal line (left to right)
345 1: vertical line (top to bottom)
346 asumption:
347 all clipping done
348*/
349/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
350void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
351{
352 if ( dir == 0 )
353 {
354 do
355 {
356 u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
357 x++;
358 len--;
359 } while( len != 0 );
360 }
361 else
362 {
363 do
364 {
365 u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
366 y++;
367 len--;
368 } while( len != 0 );
369 }
370}
371
372#endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */