u8g2_ll_hvline.c 8.9 KB

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