My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

u8g_pbxh24.c 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. u8g_pbxh24.c
  3. x lines per page, horizontal, 24 bits per pixel (true color modes)
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2013, 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. struct _u8g_pb_t
  28. {
  29. u8g_page_t p;
  30. u8g_uint_t width;
  31. void *buf;
  32. };
  33. typedef struct _u8g_pb_t u8g_pb_t;
  34. uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
  35. u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
  36. u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
  37. */
  38. #include "u8g.h"
  39. /*
  40. #define WIDTH_BITS 7
  41. #define WIDTH (1<<WIDTH_BITS)
  42. #define PAGE_HEIGHT_BITS 3
  43. #define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
  44. */
  45. void u8g_pbxh24_Clear(u8g_pb_t *b)
  46. {
  47. uint8_t *ptr = (uint8_t *)b->buf;
  48. uint8_t *end_ptr = ptr;
  49. uint8_t cnt = b->p.page_height;
  50. do
  51. {
  52. end_ptr += b->width*3;
  53. cnt--;
  54. } while( cnt > 0 );
  55. do
  56. {
  57. *ptr++ = 0;
  58. } while( ptr != end_ptr );
  59. }
  60. void u8g_pbxh24_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
  61. {
  62. b->buf = buf;
  63. b->width = width;
  64. u8g_pbxh24_Clear(b);
  65. }
  66. #ifdef OBSOLETE
  67. static void u8g_pbxh24_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t r, uint8_t g, uint8_t b)
  68. {
  69. uint16_t tmp;
  70. uint8_t *ptr = b->buf;
  71. y -= b->p.page_y0;
  72. tmp = y;
  73. tmp *= b->width;
  74. tmp += x;
  75. tmp *= 3;
  76. ptr += tmp;
  77. *ptr = r;
  78. ptr++;
  79. *ptr = g;
  80. ptr++;
  81. *ptr = b;
  82. }
  83. #endif
  84. /*
  85. intensity
  86. 0..3 intensity value
  87. 4 replace color
  88. */
  89. static void u8g_pbxh24_set_tpixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t red, uint8_t green, uint8_t blue, uint8_t intensity)
  90. {
  91. uint16_t tmp;
  92. uint8_t *ptr = b->buf;
  93. if ( intensity == 0 )
  94. return;
  95. y -= b->p.page_y0;
  96. tmp = y;
  97. tmp *= b->width;
  98. tmp += x;
  99. tmp *= 3;
  100. ptr += tmp;
  101. if ( intensity == 4 )
  102. {
  103. *ptr = red;
  104. ptr++;
  105. *ptr = green;
  106. ptr++;
  107. *ptr = blue;
  108. return;
  109. }
  110. if ( intensity == 2 )
  111. {
  112. /*
  113. red = red/4 + red/2;
  114. green = green/4 + green/2;
  115. blue = blue/4 + blue/2;
  116. */
  117. red >>= 1;
  118. green >>= 1;
  119. blue >>= 1;
  120. }
  121. else if ( intensity == 1 )
  122. {
  123. red >>= 2;
  124. green >>= 2;
  125. blue >>= 2;
  126. }
  127. if ( *ptr >= 255-red ) *ptr = 255;
  128. else *ptr += red;
  129. ptr++;
  130. if ( *ptr >= 255-green ) *ptr = 255;
  131. else *ptr += green;
  132. ptr++;
  133. if ( *ptr >= 255-blue ) *ptr = 255;
  134. else *ptr += blue;
  135. /*
  136. if ( *ptr < red ) *ptr = red;
  137. ptr++;
  138. if ( *ptr < green ) *ptr = green;
  139. ptr++;
  140. if ( *ptr < blue ) *ptr = blue;
  141. */
  142. }
  143. void u8g_pbxh24_SetTPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel, uint8_t intensity)
  144. {
  145. if ( arg_pixel->y < b->p.page_y0 )
  146. return;
  147. if ( arg_pixel->y > b->p.page_y1 )
  148. return;
  149. if ( arg_pixel->x >= b->width )
  150. return;
  151. u8g_pbxh24_set_tpixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color, arg_pixel->blue, intensity);
  152. }
  153. void u8g_pbxh24_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
  154. {
  155. register uint8_t pixel = arg_pixel->pixel;
  156. u8g_uint_t dx = 0;
  157. u8g_uint_t dy = 0;
  158. switch( arg_pixel->dir )
  159. {
  160. case 0: dx++; break;
  161. case 1: dy++; break;
  162. case 2: dx--; break;
  163. case 3: dy--; break;
  164. }
  165. do
  166. {
  167. if ( pixel & 128 )
  168. u8g_pbxh24_SetTPixel(b, arg_pixel, 4);
  169. arg_pixel->x += dx;
  170. arg_pixel->y += dy;
  171. pixel <<= 1;
  172. } while( pixel != 0 );
  173. }
  174. void u8g_pbxh24_Set4TPixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
  175. {
  176. register uint8_t pixel = arg_pixel->pixel;
  177. u8g_uint_t dx = 0;
  178. u8g_uint_t dy = 0;
  179. switch( arg_pixel->dir )
  180. {
  181. case 0: dx++; break;
  182. case 1: dy++; break;
  183. case 2: dx--; break;
  184. case 3: dy--; break;
  185. }
  186. do
  187. {
  188. u8g_pbxh24_SetTPixel(b, arg_pixel, pixel >> 6);
  189. arg_pixel->x += dx;
  190. arg_pixel->y += dy;
  191. pixel <<= 2;
  192. } while( pixel != 0 );
  193. }
  194. uint8_t u8g_dev_pbxh24_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  195. {
  196. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  197. switch(msg)
  198. {
  199. case U8G_DEV_MSG_SET_8PIXEL:
  200. if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
  201. u8g_pbxh24_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
  202. break;
  203. case U8G_DEV_MSG_SET_PIXEL:
  204. u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, 4);
  205. break;
  206. case U8G_DEV_MSG_SET_4TPIXEL:
  207. u8g_pbxh24_Set4TPixel(pb, (u8g_dev_arg_pixel_t *)arg);
  208. break;
  209. case U8G_DEV_MSG_SET_TPIXEL:
  210. u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, ((u8g_dev_arg_pixel_t *)arg)->pixel&3);
  211. break;
  212. case U8G_DEV_MSG_INIT:
  213. break;
  214. case U8G_DEV_MSG_STOP:
  215. break;
  216. case U8G_DEV_MSG_PAGE_FIRST:
  217. u8g_pbxh24_Clear(pb);
  218. u8g_page_First(&(pb->p));
  219. break;
  220. case U8G_DEV_MSG_PAGE_NEXT:
  221. if ( u8g_page_Next(&(pb->p)) == 0 )
  222. return 0;
  223. u8g_pbxh24_Clear(pb);
  224. break;
  225. #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
  226. case U8G_DEV_MSG_IS_BBX_INTERSECTION:
  227. return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
  228. #endif
  229. case U8G_DEV_MSG_GET_PAGE_BOX:
  230. u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
  231. break;
  232. case U8G_DEV_MSG_GET_WIDTH:
  233. *((u8g_uint_t *)arg) = pb->width;
  234. break;
  235. case U8G_DEV_MSG_GET_HEIGHT:
  236. *((u8g_uint_t *)arg) = pb->p.total_height;
  237. break;
  238. case U8G_DEV_MSG_SET_COLOR_ENTRY:
  239. break;
  240. case U8G_DEV_MSG_SET_XY_CB:
  241. break;
  242. case U8G_DEV_MSG_GET_MODE:
  243. return U8G_MODE_TRUECOLOR;
  244. }
  245. return 1;
  246. }