GUI_Paint.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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.1
  12. * | Date : 2020-07-08
  13. * | Info :
  14. * -----------------------------------------------------------------------------
  15. * V3.1(2020-07-08):
  16. * 1.Change: Paint_SetScale(UBYTE scale)
  17. * Add scale 7 for 5.65f e-Parper
  18. * 2.Change: Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  19. * Add the branch for scale 7
  20. * 3.Change: Paint_Clear(UWORD Color)
  21. * Add the branch for scale 7
  22. *
  23. * -----------------------------------------------------------------------------
  24. * V3.0(2019-04-18):
  25. * 1.Change:
  26. * Paint_DrawPoint(..., DOT_STYLE DOT_STYLE)
  27. * => Paint_DrawPoint(..., DOT_STYLE Dot_Style)
  28. * Paint_DrawLine(..., LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
  29. * => Paint_DrawLine(..., DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  30. * Paint_DrawRectangle(..., DRAW_FILL Filled, DOT_PIXEL Dot_Pixel)
  31. * => Paint_DrawRectangle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  32. * Paint_DrawCircle(..., DRAW_FILL Draw_Fill, DOT_PIXEL Dot_Pixel)
  33. * => Paint_DrawCircle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Filll)
  34. *
  35. * -----------------------------------------------------------------------------
  36. * V2.0(2018-11-15):
  37. * 1.add: Paint_NewImage()
  38. * Create an image's properties
  39. * 2.add: Paint_SelectImage()
  40. * Select the picture to be drawn
  41. * 3.add: Paint_SetRotate()
  42. * Set the direction of the cache
  43. * 4.add: Paint_RotateImage()
  44. * Can flip the picture, Support 0-360 degrees,
  45. * but only 90.180.270 rotation is better
  46. * 4.add: Paint_SetMirroring()
  47. * Can Mirroring the picture, horizontal, vertical, origin
  48. * 5.add: Paint_DrawString_CN()
  49. * Can display Chinese(GB1312)
  50. *
  51. * -----------------------------------------------------------------------------
  52. * V1.0(2018-07-17):
  53. * Create library
  54. *
  55. * Permission is hereby granted, free of charge, to any person obtaining a copy
  56. * of this software and associated documnetation files (the "Software"), to deal
  57. * in the Software without restriction, including without limitation the rights
  58. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  59. * copies of the Software, and to permit persons to whom the Software is
  60. * furished to do so, subject to the following conditions:
  61. *
  62. * The above copyright notice and this permission notice shall be included in
  63. * all copies or substantial portions of the Software.
  64. *
  65. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  66. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  67. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  68. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  69. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  70. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  71. * THE SOFTWARE.
  72. *
  73. ******************************************************************************/
  74. #include "GUI_Paint.h"
  75. #include "DEV_Config.h"
  76. #include "Debug.h"
  77. #include <stdint.h>
  78. #include <stdlib.h>
  79. #include <string.h> //memset()
  80. #include <math.h>
  81. PAINT Paint;
  82. /******************************************************************************
  83. function: Create Image
  84. parameter:
  85. image : Pointer to the image cache
  86. width : The width of the picture
  87. Height : The height of the picture
  88. Color : Whether the picture is inverted
  89. ******************************************************************************/
  90. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
  91. {
  92. Paint.Image = NULL;
  93. Paint.Image = image;
  94. Paint.WidthMemory = Width;
  95. Paint.HeightMemory = Height;
  96. Paint.Color = Color;
  97. Paint.Scale = 2;
  98. Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1);
  99. Paint.HeightByte = Height;
  100. // printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
  101. // printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8);
  102. Paint.Rotate = Rotate;
  103. Paint.Mirror = MIRROR_NONE;
  104. if(Rotate == ROTATE_0 || Rotate == ROTATE_180) {
  105. Paint.Width = Width;
  106. Paint.Height = Height;
  107. } else {
  108. Paint.Width = Height;
  109. Paint.Height = Width;
  110. }
  111. }
  112. /******************************************************************************
  113. function: Select Image
  114. parameter:
  115. image : Pointer to the image cache
  116. ******************************************************************************/
  117. void Paint_SelectImage(UBYTE *image)
  118. {
  119. Paint.Image = image;
  120. }
  121. /******************************************************************************
  122. function: Select Image Rotate
  123. parameter:
  124. Rotate : 0,90,180,270
  125. ******************************************************************************/
  126. void Paint_SetRotate(UWORD Rotate)
  127. {
  128. if(Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) {
  129. Debug("Set image Rotate %d\r\n", Rotate);
  130. Paint.Rotate = Rotate;
  131. } else {
  132. Debug("rotate = 0, 90, 180, 270\r\n");
  133. }
  134. }
  135. void Paint_SetScale(UBYTE scale)
  136. {
  137. if(scale == 2){
  138. Paint.Scale = scale;
  139. Paint.WidthByte = (Paint.WidthMemory % 8 == 0)? (Paint.WidthMemory / 8 ): (Paint.WidthMemory / 8 + 1);
  140. }else if(scale == 4){
  141. Paint.Scale = scale;
  142. Paint.WidthByte = (Paint.WidthMemory % 4 == 0)? (Paint.WidthMemory / 4 ): (Paint.WidthMemory / 4 + 1);
  143. }else if(scale == 7){//Only applicable with 5in65 e-Paper
  144. Paint.Scale = scale;
  145. Paint.WidthByte = (Paint.WidthMemory % 2 == 0)? (Paint.WidthMemory / 2 ): (Paint.WidthMemory / 2 + 1);;
  146. }else{
  147. Debug("Set Scale Input parameter error\r\n");
  148. Debug("Scale Only support: 2 4 7\r\n");
  149. }
  150. }
  151. /******************************************************************************
  152. function: Select Image mirror
  153. parameter:
  154. mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror
  155. ******************************************************************************/
  156. void Paint_SetMirroring(UBYTE mirror)
  157. {
  158. if(mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL ||
  159. mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN) {
  160. Debug("mirror image x:%s, y:%s\r\n",(mirror & 0x01)? "mirror":"none", ((mirror >> 1) & 0x01)? "mirror":"none");
  161. Paint.Mirror = mirror;
  162. } else {
  163. Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \
  164. MIRROR_VERTICAL or MIRROR_ORIGIN\r\n");
  165. }
  166. }
  167. /******************************************************************************
  168. function: Draw Pixels
  169. parameter:
  170. Xpoint : At point X
  171. Ypoint : At point Y
  172. Color : Painted colors
  173. ******************************************************************************/
  174. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  175. {
  176. if(Xpoint > Paint.Width || Ypoint > Paint.Height){
  177. Debug("Exceeding display boundaries\r\n");
  178. return;
  179. }
  180. UWORD X, Y;
  181. switch(Paint.Rotate) {
  182. case 0:
  183. X = Xpoint;
  184. Y = Ypoint;
  185. break;
  186. case 90:
  187. X = Paint.WidthMemory - Ypoint - 1;
  188. Y = Xpoint;
  189. break;
  190. case 180:
  191. X = Paint.WidthMemory - Xpoint - 1;
  192. Y = Paint.HeightMemory - Ypoint - 1;
  193. break;
  194. case 270:
  195. X = Ypoint;
  196. Y = Paint.HeightMemory - Xpoint - 1;
  197. break;
  198. default:
  199. return;
  200. }
  201. switch(Paint.Mirror) {
  202. case MIRROR_NONE:
  203. break;
  204. case MIRROR_HORIZONTAL:
  205. X = Paint.WidthMemory - X - 1;
  206. break;
  207. case MIRROR_VERTICAL:
  208. Y = Paint.HeightMemory - Y - 1;
  209. break;
  210. case MIRROR_ORIGIN:
  211. X = Paint.WidthMemory - X - 1;
  212. Y = Paint.HeightMemory - Y - 1;
  213. break;
  214. default:
  215. return;
  216. }
  217. if(X > Paint.WidthMemory || Y > Paint.HeightMemory){
  218. Debug("Exceeding display boundaries\r\n");
  219. return;
  220. }
  221. if(Paint.Scale == 2){
  222. UDOUBLE Addr = X / 8 + Y * Paint.WidthByte;
  223. UBYTE Rdata = Paint.Image[Addr];
  224. if(Color == BLACK)
  225. Paint.Image[Addr] = Rdata & ~(0x80 >> (X % 8));
  226. else
  227. Paint.Image[Addr] = Rdata | (0x80 >> (X % 8));
  228. }else if(Paint.Scale == 4){
  229. UDOUBLE Addr = X / 4 + Y * Paint.WidthByte;
  230. Color = Color % 4;//Guaranteed color scale is 4 --- 0~3
  231. UBYTE Rdata = Paint.Image[Addr];
  232. Rdata = Rdata & (~(0xC0 >> ((X % 4)*2)));
  233. Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2));
  234. }else if(Paint.Scale == 7){
  235. UDOUBLE Addr = X / 2 + Y * Paint.WidthByte;
  236. UBYTE Rdata = Paint.Image[Addr];
  237. Rdata = Rdata & (~(0xF0 >> ((X % 2)*4)));//Clear first, then set value
  238. Paint.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2)*4));
  239. //printf("Add = %d ,data = %d\r\n",Addr,Rdata);
  240. }
  241. }
  242. /******************************************************************************
  243. function: Clear the color of the picture
  244. parameter:
  245. Color : Painted colors
  246. ******************************************************************************/
  247. void Paint_Clear(UWORD Color)
  248. {
  249. if(Paint.Scale == 2 || Paint.Scale == 4){
  250. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  251. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  252. UDOUBLE Addr = X + Y*Paint.WidthByte;
  253. Paint.Image[Addr] = Color;
  254. }
  255. }
  256. }else if(Paint.Scale == 7){
  257. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  258. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {
  259. UDOUBLE Addr = X + Y*Paint.WidthByte;
  260. Paint.Image[Addr] = (Color<<4)|Color;
  261. }
  262. }
  263. }
  264. }
  265. /******************************************************************************
  266. function: Clear the color of a window
  267. parameter:
  268. Xstart : x starting point
  269. Ystart : Y starting point
  270. Xend : x end point
  271. Yend : y end point
  272. Color : Painted colors
  273. ******************************************************************************/
  274. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  275. {
  276. UWORD X, Y;
  277. for (Y = Ystart; Y < Yend; Y++) {
  278. for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte
  279. Paint_SetPixel(X, Y, Color);
  280. }
  281. }
  282. }
  283. /******************************************************************************
  284. function: Draw Point(Xpoint, Ypoint) Fill the color
  285. parameter:
  286. Xpoint : The Xpoint coordinate of the point
  287. Ypoint : The Ypoint coordinate of the point
  288. Color : Painted color
  289. Dot_Pixel : point size
  290. Dot_Style : point Style
  291. ******************************************************************************/
  292. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
  293. DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  294. {
  295. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  296. Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
  297. printf("Xpoint = %d , Paint.Width = %d \r\n ",Xpoint,Paint.Width);
  298. printf("Ypoint = %d , Paint.Height = %d \r\n ",Ypoint,Paint.Height);
  299. return;
  300. }
  301. int16_t XDir_Num , YDir_Num;
  302. if (Dot_Style == DOT_FILL_AROUND) {
  303. for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
  304. for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
  305. if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)
  306. break;
  307. // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
  308. Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
  309. }
  310. }
  311. } else {
  312. for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
  313. for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
  314. Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
  315. }
  316. }
  317. }
  318. }
  319. /******************************************************************************
  320. function: Draw a line of arbitrary slope
  321. parameter:
  322. Xstart :Starting Xpoint point coordinates
  323. Ystart :Starting Xpoint point coordinates
  324. Xend :End point Xpoint coordinate
  325. Yend :End point Ypoint coordinate
  326. Color :The color of the line segment
  327. Line_width : Line width
  328. Line_Style: Solid and dotted lines
  329. ******************************************************************************/
  330. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  331. UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  332. {
  333. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  334. Xend > Paint.Width || Yend > Paint.Height) {
  335. Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
  336. return;
  337. }
  338. UWORD Xpoint = Xstart;
  339. UWORD Ypoint = Ystart;
  340. int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
  341. int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
  342. // Increment direction, 1 is positive, -1 is counter;
  343. int XAddway = Xstart < Xend ? 1 : -1;
  344. int YAddway = Ystart < Yend ? 1 : -1;
  345. //Cumulative error
  346. int Esp = dx + dy;
  347. char Dotted_Len = 0;
  348. for (;;) {
  349. Dotted_Len++;
  350. //Painted dotted line, 2 point is really virtual
  351. if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {
  352. //Debug("LINE_DOTTED\r\n");
  353. Paint_DrawPoint(Xpoint, Ypoint, IMAGE_BACKGROUND, Line_width, DOT_STYLE_DFT);
  354. Dotted_Len = 0;
  355. } else {
  356. Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);
  357. }
  358. if (2 * Esp >= dy) {
  359. if (Xpoint == Xend)
  360. break;
  361. Esp += dy;
  362. Xpoint += XAddway;
  363. }
  364. if (2 * Esp <= dx) {
  365. if (Ypoint == Yend)
  366. break;
  367. Esp += dx;
  368. Ypoint += YAddway;
  369. }
  370. }
  371. }
  372. /******************************************************************************
  373. function: Draw a rectangle
  374. parameter:
  375. Xstart :Rectangular Starting Xpoint point coordinates
  376. Ystart :Rectangular Starting Xpoint point coordinates
  377. Xend :Rectangular End point Xpoint coordinate
  378. Yend :Rectangular End point Ypoint coordinate
  379. Color :The color of the Rectangular segment
  380. Line_width: Line width
  381. Draw_Fill : Whether to fill the inside of the rectangle
  382. ******************************************************************************/
  383. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  384. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  385. {
  386. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  387. Xend > Paint.Width || Yend > Paint.Height) {
  388. Debug("Input exceeds the normal display range\r\n");
  389. return;
  390. }
  391. if (Draw_Fill) {
  392. UWORD Ypoint;
  393. for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
  394. Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);
  395. }
  396. } else {
  397. Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  398. Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  399. Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  400. Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  401. }
  402. }
  403. /******************************************************************************
  404. function: Use the 8-point method to draw a circle of the
  405. specified size at the specified position->
  406. parameter:
  407. X_Center :Center X coordinate
  408. Y_Center :Center Y coordinate
  409. Radius :circle Radius
  410. Color :The color of the :circle segment
  411. Line_width: Line width
  412. Draw_Fill : Whether to fill the inside of the Circle
  413. ******************************************************************************/
  414. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
  415. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  416. {
  417. if (X_Center > Paint.Width || Y_Center >= Paint.Height) {
  418. Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
  419. return;
  420. }
  421. //Draw a circle from(0, R) as a starting point
  422. int16_t XCurrent, YCurrent;
  423. XCurrent = 0;
  424. YCurrent = Radius;
  425. //Cumulative error,judge the next point of the logo
  426. int16_t Esp = 3 - (Radius << 1 );
  427. int16_t sCountY;
  428. if (Draw_Fill == DRAW_FILL_FULL) {
  429. while (XCurrent <= YCurrent ) { //Realistic circles
  430. for (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
  431. Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1
  432. Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2
  433. Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3
  434. Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4
  435. Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5
  436. Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6
  437. Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7
  438. Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  439. }
  440. if (Esp < 0 )
  441. Esp += 4 * XCurrent + 6;
  442. else {
  443. Esp += 10 + 4 * (XCurrent - YCurrent );
  444. YCurrent --;
  445. }
  446. XCurrent ++;
  447. }
  448. } else { //Draw a hollow circle
  449. while (XCurrent <= YCurrent ) {
  450. Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1
  451. Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2
  452. Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3
  453. Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4
  454. Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5
  455. Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6
  456. Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7
  457. Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0
  458. if (Esp < 0 )
  459. Esp += 4 * XCurrent + 6;
  460. else {
  461. Esp += 10 + 4 * (XCurrent - YCurrent );
  462. YCurrent --;
  463. }
  464. XCurrent ++;
  465. }
  466. }
  467. }
  468. /******************************************************************************
  469. function: Display monochrome bitmap
  470. parameter:
  471. image_buffer :A picture data converted to a bitmap
  472. info:
  473. Use a computer to convert the image into a corresponding array,
  474. and then embed the array directly into Imagedata.cpp as a .c file.
  475. ******************************************************************************/
  476. void Paint_DrawBitMap(const unsigned char* image_buffer)
  477. {
  478. UWORD x, y;
  479. UDOUBLE Addr = 0;
  480. for (y = 0; y < Paint.HeightByte; y++) {
  481. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  482. Addr = x + y * Paint.WidthByte;
  483. Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  484. }
  485. }
  486. }
  487. ///******************************************************************************
  488. //function: SDisplay half of monochrome bitmap
  489. //parameter:
  490. // Region : 1 Upper half
  491. // 2 Lower half
  492. //info:
  493. //******************************************************************************/
  494. //void Paint_DrawBitMap_Half(const unsigned char* image_buffer, UBYTE Region)
  495. //{
  496. // UWORD x, y;
  497. // UDOUBLE Addr = 0;
  498. //
  499. // if(Region == 1){
  500. // for (y = 0; y < Paint.HeightByte; y++) {
  501. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  502. // Addr = x + y * Paint.WidthByte;
  503. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  504. // }
  505. // }
  506. // }else{
  507. // for (y = 0; y < Paint.HeightByte; y++) {
  508. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  509. // Addr = x + y * Paint.WidthByte ;
  510. // Paint.Image[Addr] = \
  511. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  512. // }
  513. // }
  514. // }
  515. //}
  516. ///******************************************************************************
  517. //function: SDisplay half of monochrome bitmap
  518. //parameter:
  519. // Region : 1 Upper half
  520. // 2 Lower half
  521. //info:
  522. //******************************************************************************/
  523. //void Paint_DrawBitMap_OneQuarter(const unsigned char* image_buffer, UBYTE Region)
  524. //{
  525. // UWORD x, y;
  526. // UDOUBLE Addr = 0;
  527. //
  528. // if(Region == 1){
  529. // for (y = 0; y < Paint.HeightByte; y++) {
  530. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  531. // Addr = x + y * Paint.WidthByte;
  532. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  533. // }
  534. // }
  535. // }else if(Region == 2){
  536. // for (y = 0; y < Paint.HeightByte; y++) {
  537. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  538. // Addr = x + y * Paint.WidthByte ;
  539. // Paint.Image[Addr] = \
  540. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  541. // }
  542. // }
  543. // }else if(Region == 3){
  544. // for (y = 0; y < Paint.HeightByte; y++) {
  545. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  546. // Addr = x + y * Paint.WidthByte ;
  547. // Paint.Image[Addr] = \
  548. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*2];
  549. // }
  550. // }
  551. // }else if(Region == 4){
  552. // for (y = 0; y < Paint.HeightByte; y++) {
  553. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  554. // Addr = x + y * Paint.WidthByte ;
  555. // Paint.Image[Addr] = \
  556. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*3];
  557. // }
  558. // }
  559. // }
  560. //}
  561. void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region)
  562. {
  563. UWORD x, y;
  564. UDOUBLE Addr = 0;
  565. for (y = 0; y < Paint.HeightByte; y++) {
  566. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  567. Addr = x + y * Paint.WidthByte ;
  568. Paint.Image[Addr] = \
  569. (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*(Region - 1)];
  570. }
  571. }
  572. }