GUI_Paint.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. /******************************************************************************
  2. * | File : GUI_Paint.c
  3. * | Author : Waveshare electronics
  4. * | Function : Achieve drawing: draw points, lines, boxes, circles and
  5. * their size, solid dotted line, solid rectangle hollow
  6. * rectangle, solid circle hollow circle.
  7. * | Info :
  8. * Achieve display characters: Display a single character, string, number
  9. * Achieve time display: adaptive size display time minutes and seconds
  10. *----------------
  11. * | This version: V3.2
  12. * | Date : 2020-08-18
  13. * | Info :
  14. * -----------------------------------------------------------------------------
  15. * V3.2(2020-08-18):
  16. * 1.Change: Paint_SetScale(UBYTE scale)
  17. * Add scale 65K
  18. * 2.Change: Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  19. * Add the branch for scale 65K
  20. * 3.Change: Paint_Clear(UWORD Color)
  21. * Add the branch for scale 65K
  22. * -----------------------------------------------------------------------------
  23. * V3.1(2020-08-14):
  24. * 1.Change: Paint_SetScale(UBYTE scale)
  25. * Add scale 16
  26. * 2.Change: Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  27. * Add the branch for scale 16
  28. * 3.Change: Paint_Clear(UWORD Color)
  29. * Add the branch for scale 16
  30. * -----------------------------------------------------------------------------
  31. * V3.0(2019-04-18):
  32. * 1.Change:
  33. * Paint_DrawPoint(..., DOT_STYLE DOT_STYLE)
  34. * => Paint_DrawPoint(..., DOT_STYLE Dot_Style)
  35. * Paint_DrawLine(..., LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
  36. * => Paint_DrawLine(..., DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  37. * Paint_DrawRectangle(..., DRAW_FILL Filled, DOT_PIXEL Dot_Pixel)
  38. * => Paint_DrawRectangle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  39. * Paint_DrawCircle(..., DRAW_FILL Draw_Fill, DOT_PIXEL Dot_Pixel)
  40. * => Paint_DrawCircle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Filll)
  41. *
  42. * -----------------------------------------------------------------------------
  43. * V2.0(2018-11-15):
  44. * 1.add: Paint_NewImage()
  45. * Create an image's properties
  46. * 2.add: Paint_SelectImage()
  47. * Select the picture to be drawn
  48. * 3.add: Paint_SetRotate()
  49. * Set the direction of the cache
  50. * 4.add: Paint_RotateImage()
  51. * Can flip the picture, Support 0-360 degrees,
  52. * but only 90.180.270 rotation is better
  53. * 4.add: Paint_SetMirroring()
  54. * Can Mirroring the picture, horizontal, vertical, origin
  55. * 5.add: Paint_DrawString_CN()
  56. * Can display Chinese(GB1312)
  57. *
  58. * -----------------------------------------------------------------------------
  59. * V1.0(2018-07-17):
  60. * Create library
  61. *
  62. * Permission is hereby granted, free of charge, to any person obtaining a copy
  63. * of this software and associated documnetation files (the "Software"), to deal
  64. * in the Software without restriction, including without limitation the rights
  65. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  66. * copies of the Software, and to permit persons to whom the Software is
  67. * furished to do so, subject to the following conditions:
  68. *
  69. * The above copyright notice and this permission notice shall be included in
  70. * all copies or substantial portions of the Software.
  71. *
  72. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  73. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  74. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  75. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  76. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  77. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  78. * THE SOFTWARE.
  79. *
  80. ******************************************************************************/
  81. #include "GUI_Paint.h"
  82. #include "DEV_Config.h"
  83. #include "Debug.h"
  84. #include <stdio.h>
  85. #include <stdint.h>
  86. #include <stdlib.h>
  87. #include <string.h> //memset()
  88. #include <math.h>
  89. PAINT Paint;
  90. static uint8_t pgm_read_byte(unsigned char const *ptr);
  91. static int16_t pgm_read_word(unsigned char const *ptr);
  92. static uint8_t pgm_read_byte(unsigned char const *ptr)
  93. {
  94. return *ptr;
  95. }
  96. static int16_t pgm_read_word(unsigned char const *ptr)
  97. {
  98. return ptr[0] + (ptr[1]<<8);
  99. }
  100. /******************************************************************************
  101. function: Create Image
  102. parameter:
  103. image : Pointer to the image cache
  104. width : The width of the picture
  105. Height : The height of the picture
  106. Color : Whether the picture is inverted
  107. ******************************************************************************/
  108. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
  109. {
  110. Paint.Image = NULL;
  111. Paint.Image = image;
  112. Paint.WidthMemory = Width;
  113. Paint.HeightMemory = Height;
  114. Paint.Color = Color;
  115. Paint.Scale = 2;
  116. Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1);
  117. Paint.HeightByte = Height;
  118. // printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
  119. // printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8);
  120. Paint.Rotate = Rotate;
  121. Paint.Mirror = MIRROR_NONE;
  122. if(Rotate == ROTATE_0 || Rotate == ROTATE_180) {
  123. Paint.Width = Width;
  124. Paint.Height = Height;
  125. } else {
  126. Paint.Width = Height;
  127. Paint.Height = Width;
  128. }
  129. }
  130. /******************************************************************************
  131. function: Select Image
  132. parameter:
  133. image : Pointer to the image cache
  134. ******************************************************************************/
  135. void Paint_SelectImage(UBYTE *image)
  136. {
  137. Paint.Image = image;
  138. }
  139. /******************************************************************************
  140. function: Select Image Rotate
  141. parameter:
  142. Rotate : 0,90,180,270
  143. ******************************************************************************/
  144. void Paint_SetRotate(UWORD Rotate)
  145. {
  146. if(Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) {
  147. Debug("Set image Rotate %d\r\n", Rotate);
  148. Paint.Rotate = Rotate;
  149. } else {
  150. Debug("rotate = 0, 90, 180, 270\r\n");
  151. }
  152. }
  153. void Paint_SetScale(UBYTE scale)
  154. {
  155. if(scale == 2){
  156. Paint.Scale = scale;
  157. Paint.WidthByte = (Paint.WidthMemory % 8 == 0)? (Paint.WidthMemory / 8 ): (Paint.WidthMemory / 8 + 1);
  158. }else if(scale == 4){
  159. Paint.Scale = scale;
  160. Paint.WidthByte = (Paint.WidthMemory % 4 == 0)? (Paint.WidthMemory / 4 ): (Paint.WidthMemory / 4 + 1);
  161. }else if(scale ==16) {
  162. Paint.Scale = scale;
  163. Paint.WidthByte = (Paint.WidthMemory%2==0) ? (Paint.WidthMemory/2) : (Paint.WidthMemory/2+1);
  164. }else if(scale ==65) {
  165. Paint.Scale = scale;
  166. Paint.WidthByte = Paint.WidthMemory*2;
  167. }else{
  168. Debug("Set Scale Input parameter error\r\n");
  169. Debug("Scale Only support: 2 4 16 65\r\n");
  170. }
  171. }
  172. /******************************************************************************
  173. function: Select Image mirror
  174. parameter:
  175. mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror
  176. ******************************************************************************/
  177. void Paint_SetMirroring(UBYTE mirror)
  178. {
  179. if(mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL ||
  180. mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN) {
  181. Debug("mirror image x:%s, y:%s\r\n",(mirror & 0x01)? "mirror":"none", ((mirror >> 1) & 0x01)? "mirror":"none");
  182. Paint.Mirror = mirror;
  183. } else {
  184. Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \
  185. MIRROR_VERTICAL or MIRROR_ORIGIN\r\n");
  186. }
  187. }
  188. /******************************************************************************
  189. function: Draw Pixels
  190. parameter:
  191. Xpoint : At point X
  192. Ypoint : At point Y
  193. Color : Painted colors
  194. ******************************************************************************/
  195. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  196. {
  197. if(Xpoint > Paint.Width || Ypoint > Paint.Height){
  198. Debug("Exceeding display boundaries\r\n");
  199. return;
  200. }
  201. UWORD X, Y;
  202. switch(Paint.Rotate) {
  203. case 0:
  204. X = Xpoint;
  205. Y = Ypoint;
  206. break;
  207. case 90:
  208. X = Paint.WidthMemory - Ypoint - 1;
  209. Y = Xpoint;
  210. break;
  211. case 180:
  212. X = Paint.WidthMemory - Xpoint - 1;
  213. Y = Paint.HeightMemory - Ypoint - 1;
  214. break;
  215. case 270:
  216. X = Ypoint;
  217. Y = Paint.HeightMemory - Xpoint - 1;
  218. break;
  219. default:
  220. return;
  221. }
  222. switch(Paint.Mirror) {
  223. case MIRROR_NONE:
  224. break;
  225. case MIRROR_HORIZONTAL:
  226. X = Paint.WidthMemory - X - 1;
  227. break;
  228. case MIRROR_VERTICAL:
  229. Y = Paint.HeightMemory - Y - 1;
  230. break;
  231. case MIRROR_ORIGIN:
  232. X = Paint.WidthMemory - X - 1;
  233. Y = Paint.HeightMemory - Y - 1;
  234. break;
  235. default:
  236. return;
  237. }
  238. if(X > Paint.WidthMemory || Y > Paint.HeightMemory){
  239. Debug("Exceeding display boundaries\r\n");
  240. return;
  241. }
  242. if(Paint.Scale == 2){
  243. UDOUBLE Addr = X / 8 + Y * Paint.WidthByte;
  244. UBYTE Rdata = Paint.Image[Addr];
  245. if(Color == BLACK)
  246. Paint.Image[Addr] = Rdata & ~(0x80 >> (X % 8));
  247. else
  248. Paint.Image[Addr] = Rdata | (0x80 >> (X % 8));
  249. }else if(Paint.Scale == 4){
  250. UDOUBLE Addr = X / 4 + Y * Paint.WidthByte;
  251. Color = Color % 4;//Guaranteed color scale is 4 --- 0~3
  252. UBYTE Rdata = Paint.Image[Addr];
  253. Rdata = Rdata & (~(0xC0 >> ((X % 4)*2)));
  254. Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2));
  255. }else if(Paint.Scale == 16) {
  256. UDOUBLE Addr = X / 2 + Y * Paint.WidthByte;
  257. UBYTE Rdata = Paint.Image[Addr];
  258. Color = Color % 16;
  259. Rdata = Rdata & (~(0xf0 >> ((X % 2)*4)));
  260. Paint.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2)*4));
  261. }else if(Paint.Scale == 65) {
  262. UDOUBLE Addr = X*2 + Y*Paint.WidthByte;
  263. Paint.Image[Addr] = 0xff & (Color>>8);
  264. Paint.Image[Addr+1] = 0xff & Color;
  265. }
  266. }
  267. /******************************************************************************
  268. function: Clear the color of the picture
  269. parameter:
  270. Color : Painted colors
  271. ******************************************************************************/
  272. void Paint_Clear(UWORD Color)
  273. {
  274. if(Paint.Scale == 2 || Paint.Scale == 4) {
  275. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  276. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  277. UDOUBLE Addr = X + Y*Paint.WidthByte;
  278. Paint.Image[Addr] = Color;
  279. }
  280. }
  281. }else if(Paint.Scale == 16) {
  282. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  283. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  284. UDOUBLE Addr = X + Y*Paint.WidthByte;
  285. Color = Color & 0x0f;
  286. Paint.Image[Addr] = (Color<<4) | Color;
  287. }
  288. }
  289. }else if(Paint.Scale == 65) {
  290. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  291. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  292. UDOUBLE Addr = X*2 + Y*Paint.WidthByte;
  293. Paint.Image[Addr] = 0x0f & (Color>>8);
  294. Paint.Image[Addr+1] = 0x0f & Color;
  295. }
  296. }
  297. }
  298. }
  299. /******************************************************************************
  300. function: Clear the color of a window
  301. parameter:
  302. Xstart : x starting point
  303. Ystart : Y starting point
  304. Xend : x end point
  305. Yend : y end point
  306. Color : Painted colors
  307. ******************************************************************************/
  308. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  309. {
  310. UWORD X, Y;
  311. for (Y = Ystart; Y < Yend; Y++) {
  312. for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte
  313. Paint_SetPixel(X, Y, Color);
  314. }
  315. }
  316. }
  317. /******************************************************************************
  318. function: Draw Point(Xpoint, Ypoint) Fill the color
  319. parameter:
  320. Xpoint : The Xpoint coordinate of the point
  321. Ypoint : The Ypoint coordinate of the point
  322. Color : Painted color
  323. Dot_Pixel : point size
  324. Dot_Style : point Style
  325. ******************************************************************************/
  326. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
  327. DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  328. {
  329. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  330. Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
  331. printf("Xpoint = %d , Paint.Width = %d \r\n ",Xpoint,Paint.Width);
  332. printf("Ypoint = %d , Paint.Height = %d \r\n ",Ypoint,Paint.Height);
  333. return;
  334. }
  335. int16_t XDir_Num , YDir_Num;
  336. if (Dot_Style == DOT_FILL_AROUND) {
  337. for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
  338. for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
  339. if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)
  340. break;
  341. // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
  342. Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
  343. }
  344. }
  345. } else {
  346. for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
  347. for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
  348. Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
  349. }
  350. }
  351. }
  352. }
  353. /******************************************************************************
  354. function: Draw a line of arbitrary slope
  355. parameter:
  356. Xstart :Starting Xpoint point coordinates
  357. Ystart :Starting Xpoint point coordinates
  358. Xend :End point Xpoint coordinate
  359. Yend :End point Ypoint coordinate
  360. Color :The color of the line segment
  361. Line_width : Line width
  362. Line_Style: Solid and dotted lines
  363. ******************************************************************************/
  364. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  365. UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  366. {
  367. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  368. Xend > Paint.Width || Yend > Paint.Height) {
  369. Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
  370. return;
  371. }
  372. UWORD Xpoint = Xstart;
  373. UWORD Ypoint = Ystart;
  374. int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
  375. int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
  376. // Increment direction, 1 is positive, -1 is counter;
  377. int XAddway = Xstart < Xend ? 1 : -1;
  378. int YAddway = Ystart < Yend ? 1 : -1;
  379. //Cumulative error
  380. int Esp = dx + dy;
  381. char Dotted_Len = 0;
  382. for (;;) {
  383. Dotted_Len++;
  384. //Painted dotted line, 2 point is really virtual
  385. if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {
  386. //Debug("LINE_DOTTED\r\n");
  387. if(Color)
  388. Paint_DrawPoint(Xpoint, Ypoint, BLACK, Line_width, DOT_STYLE_DFT);
  389. else
  390. Paint_DrawPoint(Xpoint, Ypoint, WHITE, Line_width, DOT_STYLE_DFT);
  391. Dotted_Len = 0;
  392. } else {
  393. Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);
  394. }
  395. if (2 * Esp >= dy) {
  396. if (Xpoint == Xend)
  397. break;
  398. Esp += dy;
  399. Xpoint += XAddway;
  400. }
  401. if (2 * Esp <= dx) {
  402. if (Ypoint == Yend)
  403. break;
  404. Esp += dx;
  405. Ypoint += YAddway;
  406. }
  407. }
  408. }
  409. /******************************************************************************
  410. function: Draw a rectangle
  411. parameter:
  412. Xstart :Rectangular Starting Xpoint point coordinates
  413. Ystart :Rectangular Starting Xpoint point coordinates
  414. Xend :Rectangular End point Xpoint coordinate
  415. Yend :Rectangular End point Ypoint coordinate
  416. Color :The color of the Rectangular segment
  417. Line_width: Line width
  418. Draw_Fill : Whether to fill the inside of the rectangle
  419. ******************************************************************************/
  420. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  421. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  422. {
  423. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  424. Xend > Paint.Width || Yend > Paint.Height) {
  425. Debug("Input exceeds the normal display range\r\n");
  426. return;
  427. }
  428. if (Draw_Fill) {
  429. UWORD Ypoint;
  430. for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
  431. Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);
  432. }
  433. } else {
  434. Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  435. Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  436. Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  437. Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  438. }
  439. }
  440. /******************************************************************************
  441. function: Use the 8-point method to draw a circle of the
  442. specified size at the specified position->
  443. parameter:
  444. X_Center :Center X coordinate
  445. Y_Center :Center Y coordinate
  446. Radius :circle Radius
  447. Color :The color of the :circle segment
  448. Line_width: Line width
  449. Draw_Fill : Whether to fill the inside of the Circle
  450. ******************************************************************************/
  451. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
  452. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  453. {
  454. if (X_Center > Paint.Width || Y_Center >= Paint.Height) {
  455. Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
  456. return;
  457. }
  458. //Draw a circle from(0, R) as a starting point
  459. int16_t XCurrent, YCurrent;
  460. XCurrent = 0;
  461. YCurrent = Radius;
  462. //Cumulative error,judge the next point of the logo
  463. int16_t Esp = 3 - (Radius << 1 );
  464. int16_t sCountY;
  465. if (Draw_Fill == DRAW_FILL_FULL) {
  466. while (XCurrent <= YCurrent ) { //Realistic circles
  467. for (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
  468. Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1
  469. Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2
  470. Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3
  471. Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4
  472. Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5
  473. Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6
  474. Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7
  475. Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  476. }
  477. if (Esp < 0 )
  478. Esp += 4 * XCurrent + 6;
  479. else {
  480. Esp += 10 + 4 * (XCurrent - YCurrent );
  481. YCurrent --;
  482. }
  483. XCurrent ++;
  484. }
  485. } else { //Draw a hollow circle
  486. while (XCurrent <= YCurrent ) {
  487. Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1
  488. Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2
  489. Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3
  490. Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4
  491. Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5
  492. Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6
  493. Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7
  494. Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0
  495. if (Esp < 0 )
  496. Esp += 4 * XCurrent + 6;
  497. else {
  498. Esp += 10 + 4 * (XCurrent - YCurrent );
  499. YCurrent --;
  500. }
  501. XCurrent ++;
  502. }
  503. }
  504. }
  505. /******************************************************************************
  506. function: Show English characters
  507. parameter:
  508. Xpoint :X coordinate
  509. Ypoint :Y coordinate
  510. Acsii_Char :To display the English characters
  511. Font :A structure pointer that displays a character size
  512. Color_Foreground : Select the foreground color
  513. Color_Background : Select the background color
  514. ******************************************************************************/
  515. void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char,
  516. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  517. {
  518. UWORD Page, Column;
  519. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  520. //Debug("Paint_DrawChar Input exceeds the normal display range\r\n");
  521. return;
  522. }
  523. uint32_t Char_Offset = (Acsii_Char - ' ') * Font->Height * (Font->Width / 8 + (Font->Width % 8 ? 1 : 0));
  524. const unsigned char *ptr = &Font->table[Char_Offset];
  525. for ( Page = 0; Page < Font->Height; Page ++ ) {
  526. for ( Column = 0; Column < Font->Width; Column ++ ) {
  527. //To determine whether the font background color and screen background color is consistent
  528. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  529. if (pgm_read_byte(ptr) & (0x80 >> (Column % 8)))
  530. Paint_SetPixel (Xpoint + Column, Ypoint + Page, Color_Foreground );
  531. } else {
  532. if (pgm_read_byte(ptr) & (0x80 >> (Column % 8))) {
  533. Paint_SetPixel (Xpoint + Column, Ypoint + Page, Color_Foreground );
  534. } else {
  535. Paint_SetPixel (Xpoint + Column, Ypoint + Page, Color_Background );
  536. }
  537. }
  538. //One pixel is 8 bits
  539. if (Column % 8 == 7) {
  540. ptr++;
  541. }
  542. }/* Write a line */
  543. if (Font->Width % 8 != 0) {
  544. ptr++;
  545. }
  546. }/* Write all */
  547. }
  548. /******************************************************************************
  549. function: Display the string
  550. parameter:
  551. Xstart :X coordinate
  552. Ystart :Y coordinate
  553. pString :The first address of the English string to be displayed
  554. Font :A structure pointer that displays a character size
  555. Color_Foreground : Select the foreground color
  556. Color_Background : Select the background color
  557. ******************************************************************************/
  558. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
  559. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  560. {
  561. UWORD Xpoint = Xstart;
  562. UWORD Ypoint = Ystart;
  563. if (Xstart > Paint.Width || Ystart > Paint.Height) {
  564. Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
  565. return;
  566. }
  567. while (* pString != '\0') {
  568. //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  569. if ((Xpoint + Font->Width ) > Paint.Width ) {
  570. Xpoint = Xstart;
  571. Ypoint += Font->Height;
  572. }
  573. // If the Y direction is full, reposition to(Xstart, Ystart)
  574. if ((Ypoint + Font->Height ) > Paint.Height ) {
  575. Xpoint = Xstart;
  576. Ypoint = Ystart;
  577. }
  578. Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
  579. //The next character of the address
  580. pString ++;
  581. //The next word of the abscissa increases the font of the broadband
  582. Xpoint += Font->Width;
  583. }
  584. }
  585. /******************************************************************************
  586. function: Display the string
  587. parameter:
  588. Xstart :X coordinate
  589. Ystart :Y coordinate
  590. pString :The first address of the Chinese string and English
  591. string to be displayed
  592. Font :A structure pointer that displays a character size
  593. Color_Foreground : Select the foreground color
  594. Color_Background : Select the background color
  595. ******************************************************************************/
  596. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Background, UWORD Color_Foreground)
  597. {
  598. const unsigned char* p_text = pString;
  599. int refcolumn = Xstart;
  600. int i, j, Num;
  601. /* Send the string character by character on EPD */
  602. while (*p_text != 0) {
  603. if (*p_text < 0x7F) { //ASCII
  604. for (Num = 0; Num < font->size ; Num++) {
  605. if (*p_text == pgm_read_byte(&font->table[Num].index[0])) {
  606. const char* ptr = &font->table[Num].matrix[0];
  607. for (j = 0; j < font->Height; j++) {
  608. for (i = 0; i < font->Width; i++) {
  609. if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
  610. Paint_SetPixel(refcolumn + i,Ystart + j, Color_Foreground);
  611. }
  612. if (i % 8 == 7) {
  613. ptr++;
  614. }
  615. }
  616. if (font->Width % 8 != 0) {
  617. ptr++;
  618. }
  619. }
  620. break;
  621. }
  622. }
  623. /* Point on the next character */
  624. p_text += 1;
  625. /* Decrement the column position by 16 */
  626. refcolumn += font->ASCII_Width;
  627. } else { //中文
  628. for (Num = 0; Num < font->size ; Num++) {
  629. if ((*p_text == pgm_read_byte(&font->table[Num].index[0])) && (*(p_text + 1) == pgm_read_byte(&font->table[Num].index[1])) && (*(p_text + 2) == pgm_read_byte(&font->table[Num].index[2]))) {
  630. const char* ptr = &font->table[Num].matrix[0];
  631. for (j = 0; j < font->Height; j++) {
  632. for (i = 0; i < font->Width; i++) {
  633. if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
  634. Paint_SetPixel(refcolumn + i,Ystart + j, Color_Foreground);
  635. }
  636. if (i % 8 == 7) {
  637. ptr++;
  638. }
  639. }
  640. if (font->Width % 8 != 0) {
  641. ptr++;
  642. }
  643. }
  644. break;
  645. }
  646. }
  647. /* Point on the next character */
  648. p_text += 3;
  649. /* Decrement the column position by 16 */
  650. refcolumn += font->Width;
  651. }
  652. }
  653. }
  654. /******************************************************************************
  655. function: Display nummber
  656. parameter:
  657. Xstart :X coordinate
  658. Ystart : Y coordinate
  659. Number : The number displayed
  660. Font :A structure pointer that displays a character size
  661. Digit : Fractional width
  662. Color_Foreground : Select the foreground color
  663. Color_Background : Select the background color
  664. ******************************************************************************/
  665. #define ARRAY_LEN 255
  666. #if 0
  667. void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint,const char * Number,
  668. sFONT* Font, UWORD Digit,UWORD Color_Foreground, UWORD Color_Background)
  669. {
  670. uint8_t Str_Array[ARRAY_LEN] = {0};
  671. uint8_t *pStr = Str_Array;
  672. uint8_t i, len = 0;
  673. int16_t arr[3] = {0, 0, 0};
  674. int16_t *p = arr;
  675. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  676. Debug("Paint_DisNum Input exceeds the normal display range\r\n");
  677. return;
  678. }
  679. while(Number[len] != '\0') {
  680. len++; //get total length
  681. (*p)++; //get the integer part length
  682. if(Number[len] == '.') {
  683. arr[2] = 1;
  684. arr[0]--;
  685. p++; //get fractional part length
  686. }
  687. }
  688. if(Digit > 0) {
  689. if(Digit <= arr[1]) {
  690. for(i=0; i<=len-(arr[1]-Digit); i++) //cut some Number
  691. Str_Array[i] = Number[i];
  692. }
  693. else {
  694. for(i=0; i<=len+Digit-arr[1]; i++) {
  695. if(i == len && arr[2] == 0)
  696. Str_Array[i] = '.';
  697. else if(i >= len) //add '0'
  698. Str_Array[i] = '0';
  699. else
  700. Str_Array[i] = Number[i];
  701. }
  702. }
  703. }
  704. else
  705. for(i=0; i<=len-arr[1]-arr[2]; i++) {
  706. Str_Array[i] = Number[i];
  707. }
  708. //show
  709. Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
  710. }
  711. #endif
  712. /******************************************************************************
  713. function: Display time
  714. parameter:
  715. Xstart :X coordinate
  716. Ystart : Y coordinate
  717. pTime : Time-related structures
  718. Font :A structure pointer that displays a character size
  719. Color_Foreground : Select the foreground color
  720. Color_Background : Select the background color
  721. ******************************************************************************/
  722. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font,
  723. UWORD Color_Foreground, UWORD Color_Background)
  724. {
  725. uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  726. UWORD Dx = Font->Width;
  727. //Write data into the cache
  728. Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font, Color_Background, Color_Foreground);
  729. Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font, Color_Background, Color_Foreground);
  730. Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font, Color_Background, Color_Foreground);
  731. Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font, Color_Background, Color_Foreground);
  732. Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font, Color_Background, Color_Foreground);
  733. Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font, Color_Background, Color_Foreground);
  734. Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font, Color_Background, Color_Foreground);
  735. Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font, Color_Background, Color_Foreground);
  736. }
  737. /******************************************************************************
  738. function: Display monochrome bitmap
  739. parameter:
  740. image_buffer :A picture data converted to a bitmap
  741. info:
  742. Use a computer to convert the image into a corresponding array,
  743. and then embed the array directly into Imagedata.cpp as a .c file.
  744. ******************************************************************************/
  745. void Paint_DrawBitMap(const unsigned char* image_buffer)
  746. {
  747. UWORD x, y;
  748. UDOUBLE Addr = 0;
  749. for (y = 0; y < Paint.HeightByte; y++) {
  750. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  751. Addr = x + y * Paint.WidthByte;
  752. Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  753. }
  754. }
  755. }
  756. ///******************************************************************************
  757. //function: SDisplay half of monochrome bitmap
  758. //parameter:
  759. // Region : 1 Upper half
  760. // 2 Lower half
  761. //info:
  762. //******************************************************************************/
  763. //void Paint_DrawBitMap_Half(const unsigned char* image_buffer, UBYTE Region)
  764. //{
  765. // UWORD x, y;
  766. // UDOUBLE Addr = 0;
  767. //
  768. // if(Region == 1){
  769. // for (y = 0; y < Paint.HeightByte; y++) {
  770. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  771. // Addr = x + y * Paint.WidthByte;
  772. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  773. // }
  774. // }
  775. // }else{
  776. // for (y = 0; y < Paint.HeightByte; y++) {
  777. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  778. // Addr = x + y * Paint.WidthByte ;
  779. // Paint.Image[Addr] = \
  780. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  781. // }
  782. // }
  783. // }
  784. //}
  785. ///******************************************************************************
  786. //function: SDisplay half of monochrome bitmap
  787. //parameter:
  788. // Region : 1 Upper half
  789. // 2 Lower half
  790. //info:
  791. //******************************************************************************/
  792. //void Paint_DrawBitMap_OneQuarter(const unsigned char* image_buffer, UBYTE Region)
  793. //{
  794. // UWORD x, y;
  795. // UDOUBLE Addr = 0;
  796. //
  797. // if(Region == 1){
  798. // for (y = 0; y < Paint.HeightByte; y++) {
  799. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  800. // Addr = x + y * Paint.WidthByte;
  801. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  802. // }
  803. // }
  804. // }else if(Region == 2){
  805. // for (y = 0; y < Paint.HeightByte; y++) {
  806. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  807. // Addr = x + y * Paint.WidthByte ;
  808. // Paint.Image[Addr] = \
  809. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  810. // }
  811. // }
  812. // }else if(Region == 3){
  813. // for (y = 0; y < Paint.HeightByte; y++) {
  814. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  815. // Addr = x + y * Paint.WidthByte ;
  816. // Paint.Image[Addr] = \
  817. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*2];
  818. // }
  819. // }
  820. // }else if(Region == 4){
  821. // for (y = 0; y < Paint.HeightByte; y++) {
  822. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  823. // Addr = x + y * Paint.WidthByte ;
  824. // Paint.Image[Addr] = \
  825. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*3];
  826. // }
  827. // }
  828. // }
  829. //}
  830. void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region)
  831. {
  832. UWORD x, y;
  833. UDOUBLE Addr = 0;
  834. for (y = 0; y < Paint.HeightByte; y++) {
  835. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  836. Addr = x + y * Paint.WidthByte ;
  837. Paint.Image[Addr] = \
  838. (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*(Region - 1)];
  839. }
  840. }
  841. }