u8g2_ll_hvline.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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(
  55. u8g2_t* u8g2,
  56. u8g2_uint_t x,
  57. u8g2_uint_t y,
  58. u8g2_uint_t len,
  59. uint8_t dir) {
  60. uint16_t offset;
  61. uint8_t* ptr;
  62. uint8_t bit_pos, mask;
  63. uint8_t or_mask, xor_mask;
  64. #ifdef __unix
  65. uint8_t* max_ptr = u8g2->tile_buf_ptr +
  66. u8g2_GetU8x8(u8g2)->display_info->tile_width * u8g2->tile_buf_height * 8;
  67. #endif
  68. //assert(x >= u8g2->buf_x0);
  69. //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
  70. //assert(y >= u8g2->buf_y0);
  71. //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
  72. /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
  73. bit_pos = y; /* overflow truncate is ok here... */
  74. bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
  75. mask = 1;
  76. mask <<= bit_pos;
  77. or_mask = 0;
  78. xor_mask = 0;
  79. if(u8g2->draw_color <= 1) or_mask = mask;
  80. if(u8g2->draw_color != 1) xor_mask = mask;
  81. offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
  82. offset &= ~7;
  83. offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
  84. ptr = u8g2->tile_buf_ptr;
  85. ptr += offset;
  86. ptr += x;
  87. if(dir == 0) {
  88. do {
  89. #ifdef __unix
  90. assert(ptr < max_ptr);
  91. #endif
  92. *ptr |= or_mask;
  93. *ptr ^= xor_mask;
  94. ptr++;
  95. len--;
  96. } while(len != 0);
  97. } else {
  98. do {
  99. #ifdef __unix
  100. assert(ptr < max_ptr);
  101. #endif
  102. *ptr |= or_mask;
  103. *ptr ^= xor_mask;
  104. bit_pos++;
  105. bit_pos &= 7;
  106. len--;
  107. if(bit_pos == 0) {
  108. ptr +=
  109. u8g2->pixel_buf_width; /* 6 Jan 17: Changed u8g2->width to u8g2->pixel_buf_width, issue #148 */
  110. if(u8g2->draw_color <= 1) or_mask = 1;
  111. if(u8g2->draw_color != 1) xor_mask = 1;
  112. } else {
  113. or_mask <<= 1;
  114. xor_mask <<= 1;
  115. }
  116. } while(len != 0);
  117. }
  118. }
  119. #else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
  120. /*
  121. x,y position within the buffer
  122. */
  123. static void u8g2_draw_pixel_vertical_top_lsb(u8g2_t* u8g2, u8g2_uint_t x, u8g2_uint_t y) {
  124. uint16_t offset;
  125. uint8_t* ptr;
  126. uint8_t bit_pos, mask;
  127. //assert(x >= u8g2->buf_x0);
  128. //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
  129. //assert(y >= u8g2->buf_y0);
  130. //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
  131. /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
  132. bit_pos = y; /* overflow truncate is ok here... */
  133. bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
  134. mask = 1;
  135. mask <<= bit_pos;
  136. offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
  137. offset &= ~7;
  138. offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
  139. ptr = u8g2->tile_buf_ptr;
  140. ptr += offset;
  141. ptr += x;
  142. if(u8g2->draw_color <= 1) *ptr |= mask;
  143. if(u8g2->draw_color != 1) *ptr ^= mask;
  144. }
  145. /*
  146. x,y Upper left position of the line within the local buffer (not the display!)
  147. len length of the line in pixel, len must not be 0
  148. dir 0: horizontal line (left to right)
  149. 1: vertical line (top to bottom)
  150. asumption:
  151. all clipping done
  152. */
  153. void u8g2_ll_hvline_vertical_top_lsb(
  154. u8g2_t* u8g2,
  155. u8g2_uint_t x,
  156. u8g2_uint_t y,
  157. u8g2_uint_t len,
  158. uint8_t dir) {
  159. if(dir == 0) {
  160. do {
  161. u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
  162. x++;
  163. len--;
  164. } while(len != 0);
  165. } else {
  166. do {
  167. u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
  168. y++;
  169. len--;
  170. } while(len != 0);
  171. }
  172. }
  173. #endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
  174. /*=================================================*/
  175. /*
  176. u8g2_ll_hvline_horizontal_right_lsb
  177. ST7920
  178. */
  179. #ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION
  180. /*
  181. x,y Upper left position of the line within the local buffer (not the display!)
  182. len length of the line in pixel, len must not be 0
  183. dir 0: horizontal line (left to right)
  184. 1: vertical line (top to bottom)
  185. asumption:
  186. all clipping done
  187. */
  188. /* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
  189. void u8g2_ll_hvline_horizontal_right_lsb(
  190. u8g2_t* u8g2,
  191. u8g2_uint_t x,
  192. u8g2_uint_t y,
  193. u8g2_uint_t len,
  194. uint8_t dir) {
  195. uint16_t offset;
  196. uint8_t* ptr;
  197. uint8_t bit_pos;
  198. uint8_t mask;
  199. uint8_t tile_width = u8g2_GetU8x8(u8g2)->display_info->tile_width;
  200. bit_pos = x; /* overflow truncate is ok here... */
  201. bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
  202. mask = 128;
  203. mask >>= bit_pos;
  204. offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
  205. offset *= tile_width;
  206. offset += x >> 3;
  207. ptr = u8g2->tile_buf_ptr;
  208. ptr += offset;
  209. if(dir == 0) {
  210. do {
  211. if(u8g2->draw_color <= 1) *ptr |= mask;
  212. if(u8g2->draw_color != 1) *ptr ^= mask;
  213. mask >>= 1;
  214. if(mask == 0) {
  215. mask = 128;
  216. ptr++;
  217. }
  218. //x++;
  219. len--;
  220. } while(len != 0);
  221. } else {
  222. do {
  223. if(u8g2->draw_color <= 1) *ptr |= mask;
  224. if(u8g2->draw_color != 1) *ptr ^= mask;
  225. ptr += tile_width;
  226. //y++;
  227. len--;
  228. } while(len != 0);
  229. }
  230. }
  231. #else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
  232. /*
  233. x,y position within the buffer
  234. */
  235. /* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
  236. static void u8g2_draw_pixel_horizontal_right_lsb(u8g2_t* u8g2, u8g2_uint_t x, u8g2_uint_t y) {
  237. uint16_t offset;
  238. uint8_t* ptr;
  239. uint8_t bit_pos, mask;
  240. //assert(x >= u8g2->buf_x0);
  241. //assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
  242. //assert(y >= u8g2->buf_y0);
  243. //assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
  244. /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
  245. bit_pos = x; /* overflow truncate is ok here... */
  246. bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
  247. mask = 128;
  248. mask >>= bit_pos;
  249. x >>= 3;
  250. offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
  251. offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
  252. offset += x;
  253. ptr = u8g2->tile_buf_ptr;
  254. ptr += offset;
  255. if(u8g2->draw_color <= 1) *ptr |= mask;
  256. if(u8g2->draw_color != 1) *ptr ^= mask;
  257. }
  258. /*
  259. x,y Upper left position of the line within the local buffer (not the display!)
  260. len length of the line in pixel, len must not be 0
  261. dir 0: horizontal line (left to right)
  262. 1: vertical line (top to bottom)
  263. asumption:
  264. all clipping done
  265. */
  266. /* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
  267. void u8g2_ll_hvline_horizontal_right_lsb(
  268. u8g2_t* u8g2,
  269. u8g2_uint_t x,
  270. u8g2_uint_t y,
  271. u8g2_uint_t len,
  272. uint8_t dir) {
  273. if(dir == 0) {
  274. do {
  275. u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
  276. x++;
  277. len--;
  278. } while(len != 0);
  279. } else {
  280. do {
  281. u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
  282. y++;
  283. len--;
  284. } while(len != 0);
  285. }
  286. }
  287. #endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */