GUI_Paint.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  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 "esp_log.h"
  77. #include <stdint.h>
  78. #include <stdlib.h>
  79. #include <string.h> //memset()
  80. #include <math.h>
  81. #include "GT5DL32A3W.h"
  82. static const char *LOG_TAG = "GUI_PAINT";
  83. PAINT Paint_info;
  84. PAINT_TIME Paint_time_info;
  85. FONT_TYPE_T ascii_type_5x7 = {
  86. "ascii_type_5x7",
  87. ASCII_5X7,
  88. 5,
  89. 7,
  90. };
  91. FONT_TYPE_T ascii_type_7x8 = {
  92. "ascii_type_7x8",
  93. ASCII_7X8,
  94. 7,
  95. 8,
  96. };
  97. FONT_TYPE_T ascii_type_6x12 = {
  98. "ascii_type_6x12",
  99. ASCII_6X12,
  100. 6,
  101. 12,
  102. };
  103. FONT_TYPE_T ascii_type_8x16 = {
  104. "ascii_type_8x16",
  105. ASCII_8X16,
  106. 8,
  107. 16,
  108. };
  109. FONT_TYPE_T ascii_type_12x24 = {
  110. "ascii_type_12x24",
  111. ASCII_12X24,
  112. 12,
  113. 24,
  114. };
  115. FONT_TYPE_T ascii_type_12x24_b = {
  116. "ascii_type_12x24_b",
  117. ASCII_12X24_B,
  118. 12,
  119. 24,
  120. };
  121. FONT_TYPE_T ascii_type_16x32 = {
  122. "ascii_type_16x32",
  123. ASCII_16X32,
  124. 16,
  125. 32,
  126. };
  127. FONT_TYPE_T chinese_type_12 = {
  128. "chinese_type_12",
  129. 0,
  130. 12,
  131. 12,
  132. };
  133. FONT_TYPE_T chinese_type_16 = {
  134. "chinese_type_16",
  135. 0,
  136. 16,
  137. 16,
  138. };
  139. FONT_TYPE_T chinese_type_24 = {
  140. "chinese_type_24",
  141. 0,
  142. 24,
  143. 24,
  144. };
  145. FONT_TYPE_T chinese_type_32 = {
  146. "chinese_type_32",
  147. 0,
  148. 32,
  149. 32,
  150. };
  151. /******************************************************************************
  152. function: Create Image
  153. parameter:
  154. image : Pointer to the image cache
  155. width : The width of the picture
  156. Height : The height of the picture
  157. Color : Whether the picture is inverted
  158. ******************************************************************************/
  159. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
  160. {
  161. memset(&Paint_info, 0, sizeof(Paint_info));
  162. Paint_info.Image = NULL;
  163. Paint_info.Image = image;
  164. Paint_info.WidthMemory = Width;
  165. Paint_info.HeightMemory = Height;
  166. Paint_info.Color = Color;
  167. Paint_info.Scale = 2;
  168. Paint_info.WidthByte = (Width % 8 == 0) ? (Width / 8) : (Width / 8 + 1);
  169. Paint_info.HeightByte = Height;
  170. // printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
  171. // printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8);
  172. Paint_info.Rotate = Rotate;
  173. Paint_info.Mirror = MIRROR_NONE; // MIRROR_NONE;
  174. if (Rotate == ROTATE_0 || Rotate == ROTATE_180)
  175. {
  176. Paint_info.Width = Width;
  177. Paint_info.Height = Height;
  178. }
  179. else
  180. {
  181. Paint_info.Width = Height;
  182. Paint_info.Height = Width;
  183. }
  184. }
  185. /******************************************************************************
  186. function: Select Image
  187. parameter:
  188. image : Pointer to the image cache
  189. ******************************************************************************/
  190. void Paint_SelectImage(UBYTE *image)
  191. {
  192. Paint_info.Image = image;
  193. }
  194. /******************************************************************************
  195. function: Select Image Rotate
  196. parameter:
  197. Rotate : 0,90,180,270
  198. ******************************************************************************/
  199. void Paint_SetRotate(UWORD Rotate)
  200. {
  201. if (Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270)
  202. {
  203. Debug("Set image Rotate %d\r\n", Rotate);
  204. Paint_info.Rotate = Rotate;
  205. }
  206. else
  207. {
  208. Debug("rotate = 0, 90, 180, 270\r\n");
  209. }
  210. }
  211. void Paint_SetScale(UBYTE scale)
  212. {
  213. if (scale == 2)
  214. {
  215. Paint_info.Scale = scale;
  216. Paint_info.WidthByte = (Paint_info.WidthMemory % 8 == 0) ? (Paint_info.WidthMemory / 8) : (Paint_info.WidthMemory / 8 + 1);
  217. }
  218. else if (scale == 4)
  219. {
  220. Paint_info.Scale = scale;
  221. Paint_info.WidthByte = (Paint_info.WidthMemory % 4 == 0) ? (Paint_info.WidthMemory / 4) : (Paint_info.WidthMemory / 4 + 1);
  222. }
  223. else if (scale == 7)
  224. { // Only applicable with 5in65 e-Paper
  225. Paint_info.Scale = scale;
  226. Paint_info.WidthByte = (Paint_info.WidthMemory % 2 == 0) ? (Paint_info.WidthMemory / 2) : (Paint_info.WidthMemory / 2 + 1);
  227. ;
  228. }
  229. else
  230. {
  231. Debug("Set Scale Input parameter error\r\n");
  232. Debug("Scale Only support: 2 4 7\r\n");
  233. }
  234. }
  235. /******************************************************************************
  236. function: Select Image mirror
  237. parameter:
  238. mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror
  239. ******************************************************************************/
  240. void Paint_SetMirroring(UBYTE mirror)
  241. {
  242. if (mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL ||
  243. mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN)
  244. {
  245. Debug("mirror image x:%s, y:%s\r\n", (mirror & 0x01) ? "mirror" : "none", ((mirror >> 1) & 0x01) ? "mirror" : "none");
  246. Paint_info.Mirror = mirror;
  247. }
  248. else
  249. {
  250. Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \
  251. MIRROR_VERTICAL or MIRROR_ORIGIN\r\n");
  252. }
  253. }
  254. /******************************************************************************
  255. function: Draw Pixels
  256. parameter:
  257. Xpoint : At point X
  258. Ypoint : At point Y
  259. Color : Painted colors
  260. ******************************************************************************/
  261. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  262. {
  263. if (Xpoint > Paint_info.Width || Ypoint > Paint_info.Height)
  264. {
  265. Debug("Exceeding display boundaries\r\n");
  266. return;
  267. }
  268. UWORD X, Y;
  269. switch (Paint_info.Rotate)
  270. {
  271. case 0:
  272. X = Xpoint;
  273. Y = Ypoint;
  274. break;
  275. case 90:
  276. X = Paint_info.WidthMemory - Ypoint - 1;
  277. Y = Xpoint;
  278. break;
  279. case 180:
  280. X = Paint_info.WidthMemory - Xpoint - 1;
  281. Y = Paint_info.HeightMemory - Ypoint - 1;
  282. break;
  283. case 270:
  284. X = Ypoint;
  285. Y = Paint_info.HeightMemory - Xpoint - 1;
  286. break;
  287. default:
  288. return;
  289. }
  290. switch (Paint_info.Mirror)
  291. {
  292. case MIRROR_NONE:
  293. break;
  294. case MIRROR_HORIZONTAL:
  295. X = Paint_info.WidthMemory - X - 1;
  296. break;
  297. case MIRROR_VERTICAL:
  298. Y = Paint_info.HeightMemory - Y - 1;
  299. break;
  300. case MIRROR_ORIGIN:
  301. X = Paint_info.WidthMemory - X - 1;
  302. Y = Paint_info.HeightMemory - Y - 1;
  303. break;
  304. default:
  305. return;
  306. }
  307. if (X > Paint_info.WidthMemory || Y > Paint_info.HeightMemory)
  308. {
  309. Debug("Exceeding display boundaries\r\n");
  310. return;
  311. }
  312. if (Paint_info.Scale == 2)
  313. {
  314. UDOUBLE Addr = X / 8 + Y * Paint_info.WidthByte;
  315. if (Addr > (Paint_info.WidthMemory * Paint_info.HeightMemory))
  316. {
  317. printf("------数组溢出-----------\n");
  318. return;
  319. }
  320. UBYTE Rdata = Paint_info.Image[Addr];
  321. if (Color == BLACK)
  322. Paint_info.Image[Addr] = Rdata & ~(0x80 >> (X % 8));
  323. else
  324. Paint_info.Image[Addr] = Rdata | (0x80 >> (X % 8));
  325. }
  326. else if (Paint_info.Scale == 4)
  327. {
  328. UDOUBLE Addr = X / 4 + Y * Paint_info.WidthByte;
  329. Color = Color % 4; // Guaranteed color scale is 4 --- 0~3
  330. UBYTE Rdata = Paint_info.Image[Addr];
  331. Rdata = Rdata & (~(0xC0 >> ((X % 4) * 2)));
  332. Paint_info.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4) * 2));
  333. }
  334. else if (Paint_info.Scale == 7)
  335. {
  336. UDOUBLE Addr = X / 2 + Y * Paint_info.WidthByte;
  337. UBYTE Rdata = Paint_info.Image[Addr];
  338. Rdata = Rdata & (~(0xF0 >> ((X % 2) * 4))); // Clear first, then set value
  339. Paint_info.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2) * 4));
  340. // printf("Add = %d ,data = %d\r\n",Addr,Rdata);
  341. }
  342. }
  343. /******************************************************************************
  344. function: Clear the color of the picture
  345. parameter:
  346. Color : Painted colors
  347. ******************************************************************************/
  348. void Paint_Clear(UWORD Color)
  349. {
  350. if (Paint_info.Scale == 2)
  351. {
  352. for (UWORD Y = 0; Y < Paint_info.HeightByte; Y++)
  353. {
  354. for (UWORD X = 0; X < Paint_info.WidthByte; X++)
  355. { // 8 pixel = 1 byte
  356. UDOUBLE Addr = X + Y * Paint_info.WidthByte;
  357. Paint_info.Image[Addr] = Color;
  358. }
  359. }
  360. }
  361. else if (Paint_info.Scale == 4)
  362. {
  363. for (UWORD Y = 0; Y < Paint_info.HeightByte; Y++)
  364. {
  365. for (UWORD X = 0; X < Paint_info.WidthByte; X++)
  366. {
  367. UDOUBLE Addr = X + Y * Paint_info.WidthByte;
  368. Paint_info.Image[Addr] = (Color << 6) | (Color << 4) | (Color << 2) | Color;
  369. }
  370. }
  371. }
  372. else if (Paint_info.Scale == 7)
  373. {
  374. for (UWORD Y = 0; Y < Paint_info.HeightByte; Y++)
  375. {
  376. for (UWORD X = 0; X < Paint_info.WidthByte; X++)
  377. {
  378. UDOUBLE Addr = X + Y * Paint_info.WidthByte;
  379. Paint_info.Image[Addr] = (Color << 4) | Color;
  380. }
  381. }
  382. }
  383. }
  384. /******************************************************************************
  385. function: Clear the color of a window
  386. parameter:
  387. Xstart : x starting point
  388. Ystart : Y starting point
  389. Xend : x end point
  390. Yend : y end point
  391. Color : Painted colors
  392. ******************************************************************************/
  393. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  394. {
  395. UWORD X, Y;
  396. for (Y = Ystart; Y < Yend; Y++)
  397. {
  398. for (X = Xstart; X < Xend; X++)
  399. { // 8 pixel = 1 byte
  400. Paint_SetPixel(X, Y, Color);
  401. }
  402. }
  403. }
  404. /******************************************************************************
  405. function: Draw Point(Xpoint, Ypoint) Fill the color
  406. parameter:
  407. Xpoint : The Xpoint coordinate of the point
  408. Ypoint : The Ypoint coordinate of the point
  409. Color : Painted color
  410. Dot_Pixel : point size
  411. Dot_Style : point Style
  412. ******************************************************************************/
  413. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
  414. DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  415. {
  416. if (Xpoint > Paint_info.Width || Ypoint > Paint_info.Height)
  417. {
  418. Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
  419. // printf("Xpoint = %d , Paint_info.Width = %d \r\n ",Xpoint .Width);
  420. // printf("Ypoint = %d , Paint_info.Height = %d \r\n ",Ypoint .Height);
  421. return;
  422. }
  423. int16_t XDir_Num, YDir_Num;
  424. if (Dot_Style == DOT_FILL_AROUND)
  425. {
  426. for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++)
  427. {
  428. for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++)
  429. {
  430. if ((Xpoint + XDir_Num - Dot_Pixel) < 0 || (Ypoint + YDir_Num - Dot_Pixel) < 0)
  431. break;
  432. // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
  433. Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
  434. }
  435. }
  436. }
  437. else
  438. {
  439. for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++)
  440. {
  441. for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++)
  442. {
  443. Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
  444. }
  445. }
  446. }
  447. }
  448. /******************************************************************************
  449. function: Draw a line of arbitrary slope
  450. parameter:
  451. Xstart :Starting Xpoint point coordinates
  452. Ystart :Starting Xpoint point coordinates
  453. Xend :End point Xpoint coordinate
  454. Yend :End point Ypoint coordinate
  455. Color :The color of the line segment
  456. Line_width : Line width
  457. Line_Style: Solid and dotted lines
  458. ******************************************************************************/
  459. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  460. UWORD Color_Background, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  461. {
  462. if (Xstart > Paint_info.Width || Ystart > Paint_info.Height ||
  463. Xend > Paint_info.Width || Yend > Paint_info.Height)
  464. {
  465. Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
  466. return;
  467. }
  468. UWORD Xpoint = Xstart;
  469. UWORD Ypoint = Ystart;
  470. int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
  471. int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
  472. // Increment direction, 1 is positive, -1 is counter;
  473. int XAddway = Xstart < Xend ? 1 : -1;
  474. int YAddway = Ystart < Yend ? 1 : -1;
  475. // Cumulative error
  476. int Esp = dx + dy;
  477. char Dotted_Len = 0;
  478. for (;;)
  479. {
  480. Dotted_Len++;
  481. // Painted dotted line, 2 point is really virtual
  482. if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0)
  483. {
  484. // Debug("LINE_DOTTED\r\n");
  485. Paint_DrawPoint(Xpoint, Ypoint, 0xff, Line_width, DOT_STYLE_DFT);
  486. Dotted_Len = 0;
  487. }
  488. else if (Line_Style == LINE_STYLE_DOTTED_2 && Dotted_Len % 4 == 0)
  489. {
  490. Paint_DrawPoint(Xpoint, Ypoint, 0xff, Line_width, DOT_STYLE_DFT);
  491. }
  492. else if (Line_Style == LINE_STYLE_DOTTED_2 && Dotted_Len % 5 == 0)
  493. {
  494. Paint_DrawPoint(Xpoint, Ypoint, 0xff, Line_width, DOT_STYLE_DFT);
  495. }
  496. else if (Line_Style == LINE_STYLE_DOTTED_2 && Dotted_Len % 6 == 0)
  497. {
  498. Paint_DrawPoint(Xpoint, Ypoint, 0xff, Line_width, DOT_STYLE_DFT);
  499. Dotted_Len = 0;
  500. }
  501. else
  502. {
  503. Paint_DrawPoint(Xpoint, Ypoint, Color_Background, Line_width, DOT_STYLE_DFT);
  504. }
  505. if (2 * Esp >= dy)
  506. {
  507. if (Xpoint == Xend)
  508. break;
  509. Esp += dy;
  510. Xpoint += XAddway;
  511. }
  512. if (2 * Esp <= dx)
  513. {
  514. if (Ypoint == Yend)
  515. break;
  516. Esp += dx;
  517. Ypoint += YAddway;
  518. }
  519. }
  520. }
  521. /******************************************************************************
  522. function: Draw a rectangle
  523. parameter:
  524. Xstart :Rectangular Starting Xpoint point coordinates
  525. Ystart :Rectangular Starting Xpoint point coordinates
  526. Xend :Rectangular End point Xpoint coordinate
  527. Yend :Rectangular End point Ypoint coordinate
  528. Color :The color of the Rectangular segment
  529. Line_width: Line width
  530. Draw_Fill : Whether to fill the inside of the rectangle
  531. ******************************************************************************/
  532. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  533. UWORD Color_Background, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  534. {
  535. if (Xstart > Paint_info.Width || Ystart > Paint_info.Height ||
  536. Xend > Paint_info.Width || Yend > Paint_info.Height)
  537. {
  538. Debug("Input exceeds the normal display range\r\n");
  539. return;
  540. }
  541. if (Draw_Fill)
  542. {
  543. UWORD Ypoint;
  544. for (Ypoint = Ystart; Ypoint < Yend; Ypoint++)
  545. {
  546. Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color_Background, Line_width, LINE_STYLE_SOLID);
  547. }
  548. }
  549. else
  550. {
  551. Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color_Background, Line_width, LINE_STYLE_SOLID);
  552. Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color_Background, Line_width, LINE_STYLE_SOLID);
  553. Paint_DrawLine(Xend, Yend, Xend, Ystart, Color_Background, Line_width, LINE_STYLE_SOLID);
  554. Paint_DrawLine(Xend, Yend, Xstart, Yend, Color_Background, Line_width, LINE_STYLE_SOLID);
  555. }
  556. }
  557. /******************************************************************************
  558. function: Use the 8-point method to draw a circle of the
  559. specified size at the specified position->
  560. parameter:
  561. X_Center :Center X coordinate
  562. Y_Center :Center Y coordinate
  563. Radius :circle Radius
  564. Color :The color of the :circle segment
  565. Line_width: Line width
  566. Draw_Fill : Whether to fill the inside of the Circle
  567. ******************************************************************************/
  568. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
  569. UWORD Color_Background, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  570. {
  571. if (X_Center > Paint_info.Width || Y_Center >= Paint_info.Height)
  572. {
  573. Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
  574. return;
  575. }
  576. // Draw a circle from(0, R) as a starting point
  577. int16_t XCurrent, YCurrent;
  578. XCurrent = 0;
  579. YCurrent = Radius;
  580. // Cumulative error,judge the next point of the logo
  581. int16_t Esp = 3 - (Radius << 1);
  582. int16_t sCountY;
  583. if (Draw_Fill == DRAW_FILL_FULL)
  584. {
  585. while (XCurrent <= YCurrent)
  586. { // Realistic circles
  587. for (sCountY = XCurrent; sCountY <= YCurrent; sCountY++)
  588. {
  589. Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 1
  590. Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 2
  591. Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 3
  592. Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 4
  593. Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 5
  594. Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 6
  595. Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); // 7
  596. Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  597. }
  598. if (Esp < 0)
  599. Esp += 4 * XCurrent + 6;
  600. else
  601. {
  602. Esp += 10 + 4 * (XCurrent - YCurrent);
  603. YCurrent--;
  604. }
  605. XCurrent++;
  606. }
  607. }
  608. else
  609. { // Draw a hollow circle
  610. while (XCurrent <= YCurrent)
  611. {
  612. Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 1
  613. Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 2
  614. Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 3
  615. Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 4
  616. Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 5
  617. Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 6
  618. Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 7
  619. Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color_Background, Line_width, DOT_STYLE_DFT); // 0
  620. if (Esp < 0)
  621. Esp += 4 * XCurrent + 6;
  622. else
  623. {
  624. Esp += 10 + 4 * (XCurrent - YCurrent);
  625. YCurrent--;
  626. }
  627. XCurrent++;
  628. }
  629. }
  630. }
  631. // whc set start
  632. void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char, FONT_TYPE_T *Ascii_type,
  633. UWORD Color_Foreground, UWORD Color_Background)
  634. {
  635. // ESP_LOGE(LOG_TAG,"DRAW");
  636. UWORD Page = 0, Column = 0;
  637. int font_width = 0, font_height = 0; // xpos_offset,ypos_offset,
  638. font_width = Ascii_type->Font_Width;
  639. font_height = Ascii_type->Font_Height;
  640. // switch (Ascii_type)
  641. // {
  642. // case 1: font_width = 5; font_height = 7; break;
  643. // case 2: font_width = 7; font_height = 8;break;
  644. // case 3: font_width = 6; font_height = 12;break;
  645. // case 4: font_width = 8; font_height = 16;break;
  646. // case 5: font_width = 12; font_height =24;break;
  647. // case 6: font_width = 12; font_height =24;break;
  648. // case 7: font_width = 16; font_height =32;break;
  649. // // case 8: font_width = 0; font_height =12;break;
  650. // // case 9: font_width = 0; font_height =16;break;
  651. // // case 10:font_width = 0; font_height =24;break;
  652. // // case 11:font_width = 0; font_height =32;break;
  653. // default:
  654. // break;
  655. // }
  656. unsigned char get_data_buf[50] = {};
  657. if (Xpoint > Paint_info.Width || Ypoint > Paint_info.Height)
  658. {
  659. ESP_LOGE(LOG_TAG, "Paint_DrawChar Input exceeds the normal display range");
  660. return;
  661. }
  662. ASCII_GetData(Acsii_Char, Ascii_type->Font_lib_type, get_data_buf);
  663. const unsigned char *ptr = get_data_buf;
  664. // for(int i = 0;i<50;i++)
  665. // {ESP_LOGE(LOG_TAG,"%x",ptr[i]);}
  666. // ESP_LOGE(LOG_TAG,"P");
  667. for (Page = 0; Page < font_height; Page++)
  668. {
  669. for (Column = 0; Column < font_width; Column++)
  670. {
  671. // To determine whether the font background color and screen background color is consistent
  672. if (FONT_BACKGROUND == Color_Foreground)
  673. { // this process is to speed up the scan
  674. if (*ptr & (0x80 >> (Column % 8)))
  675. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
  676. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  677. }
  678. else
  679. {
  680. if (*ptr & (0x80 >> (Column % 8)))
  681. {
  682. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
  683. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  684. }
  685. else
  686. {
  687. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
  688. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  689. }
  690. }
  691. // One pixel is 8 bits
  692. if (Column % 8 == 7)
  693. ptr++;
  694. } // Write a line
  695. if (font_width % 8 != 0)
  696. ptr++;
  697. } // Write all
  698. }
  699. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char *pString,
  700. FONT_TYPE_T *Ascii_type, UWORD Color_Foreground, UWORD Color_Background)
  701. {
  702. UWORD Xpoint = Xstart;
  703. UWORD Ypoint = Ystart;
  704. int font_width = 0, font_height = 0;
  705. font_width = Ascii_type->Font_Width;
  706. font_height = Ascii_type->Font_Height;
  707. if (Xstart > Paint_info.Width || Ystart > Paint_info.Height)
  708. {
  709. Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
  710. return;
  711. }
  712. while (*pString != '\0')
  713. {
  714. // if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  715. if ((Xpoint + font_width) > Paint_info.Width)
  716. {
  717. Xpoint = Xstart;
  718. Ypoint += font_height;
  719. }
  720. // If the Y direction is full, reposition to(Xstart, Ystart)
  721. if ((Ypoint + font_height) > Paint_info.Height)
  722. {
  723. Xpoint = Xstart;
  724. Ypoint = Ystart;
  725. }
  726. Paint_DrawChar(Xpoint, Ypoint, *pString, Ascii_type, Color_Foreground, Color_Background);
  727. // The next character of the address
  728. pString++;
  729. // The next word of the abscissa increases the font of the broadband
  730. Xpoint += font_width;
  731. }
  732. }
  733. void Paint_DrawChar_CN48(UWORD Xstart, UWORD Ystart, const char *pString)
  734. {
  735. #define FONT_SIZE_24 24
  736. // 放大后的64x64点阵字库
  737. #define ENLARGED_FONT_SIZE_48 48
  738. const char *p_text = pString;
  739. unsigned char enlarged_font[48 * 48 / 8] = {};
  740. unsigned char font[24 * 24 / 8] = {};
  741. // ESP_LOG_BUFFER_HEX(LOG_TAG,pString,2);
  742. if (*pString > 0x80)
  743. {
  744. GBK_24_GetData(*p_text, *(p_text + 1), font);
  745. }
  746. else
  747. {
  748. ASCII_GetData(*(p_text), ASCII_24_N, font);
  749. }
  750. double scale = (double)ENLARGED_FONT_SIZE_48 / FONT_SIZE_24;
  751. for (int y = 0; y < ENLARGED_FONT_SIZE_48; y++)
  752. {
  753. for (int x = 0; x < ENLARGED_FONT_SIZE_48; x++)
  754. {
  755. double x0 = x / scale;
  756. double y0 = y / scale;
  757. int x1 = (int)x0;
  758. int y1 = (int)y0;
  759. int x2 = x1 + 1;
  760. int y2 = y1 + 1;
  761. if (x2 >= FONT_SIZE_24)
  762. x2 = FONT_SIZE_24 - 1;
  763. if (y2 >= FONT_SIZE_24)
  764. y2 = FONT_SIZE_24 - 1;
  765. double dx = x0 - x1;
  766. double dy = y0 - y1;
  767. unsigned char q11 = (font[y1 * (FONT_SIZE_24 / 8) + (x1 / 8)] >> (7 - (x1 % 8))) & 1;
  768. unsigned char q21 = (font[y1 * (FONT_SIZE_24 / 8) + (x2 / 8)] >> (7 - (x2 % 8))) & 1;
  769. unsigned char q12 = (font[y2 * (FONT_SIZE_24 / 8) + (x1 / 8)] >> (7 - (x1 % 8))) & 1;
  770. unsigned char q22 = (font[y2 * (FONT_SIZE_24 / 8) + (x2 / 8)] >> (7 - (x2 % 8))) & 1;
  771. double interpolated_value = (1 - dx) * (1 - dy) * q11 + dx * (1 - dy) * q21 +
  772. (1 - dx) * dy * q12 + dx * dy * q22;
  773. int index = y * ENLARGED_FONT_SIZE_48 + x;
  774. if (interpolated_value >= 0.5)
  775. {
  776. enlarged_font[index / 8] |= (1 << (7 - (index % 8)));
  777. }
  778. else
  779. {
  780. enlarged_font[index / 8] &= ~(1 << (7 - (index % 8)));
  781. }
  782. }
  783. }
  784. int Xpoint = Xstart, Ypoint = Ystart;
  785. const unsigned char *ptr = enlarged_font;
  786. UWORD Page = 0, Column = 0;
  787. for (Page = 0; Page < ENLARGED_FONT_SIZE_48; Page++)
  788. {
  789. for (Column = 0; Column < ENLARGED_FONT_SIZE_48; Column++)
  790. {
  791. // To determine whether the font background color and screen background color is consistent
  792. if (FONT_BACKGROUND == WHITE)
  793. { // this process is to speed up the scan
  794. if (*ptr & (0x80 >> (Column % 8)))
  795. Paint_SetPixel(Xpoint + Column, Ypoint + Page, BLACK);
  796. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  797. }
  798. else
  799. {
  800. if (*ptr & (0x80 >> (Column % 8)))
  801. {
  802. Paint_SetPixel(Xpoint + Column, Ypoint + Page, BLACK);
  803. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  804. }
  805. else
  806. {
  807. Paint_SetPixel(Xpoint + Column, Ypoint + Page, WHITE);
  808. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  809. }
  810. }
  811. // One pixel is 8 bits
  812. if (Column % 8 == 7)
  813. ptr++;
  814. } // Write a line
  815. if (ENLARGED_FONT_SIZE_48 % 8 != 0)
  816. ptr++;
  817. } // Write all
  818. }
  819. void Paint_DrawChar_CN48_black(UWORD Xstart, UWORD Ystart, const char *pString) // 原来扩大是黑底白字Paint_DrawChar_CN48_black为白底黑字
  820. {
  821. #define FONT_SIZE_24 24
  822. // 放大后的64x64点阵字库
  823. #define ENLARGED_FONT_SIZE_48 48
  824. const char *p_text = pString;
  825. unsigned char enlarged_font[48 * 48 / 8] = {};
  826. unsigned char font[24 * 24 / 8] = {};
  827. // ESP_LOG_BUFFER_HEX(LOG_TAG,pString,2);
  828. if (*pString > 0x80)
  829. {
  830. GBK_24_GetData(*p_text, *(p_text + 1), font);
  831. }
  832. else
  833. {
  834. ASCII_GetData(*(p_text), ASCII_24_N, font);
  835. }
  836. double scale = (double)ENLARGED_FONT_SIZE_48 / FONT_SIZE_24;
  837. for (int y = 0; y < ENLARGED_FONT_SIZE_48; y++)
  838. {
  839. for (int x = 0; x < ENLARGED_FONT_SIZE_48; x++)
  840. {
  841. double x0 = x / scale;
  842. double y0 = y / scale;
  843. int x1 = (int)x0;
  844. int y1 = (int)y0;
  845. int x2 = x1 + 1;
  846. int y2 = y1 + 1;
  847. if (x2 >= FONT_SIZE_24)
  848. x2 = FONT_SIZE_24 - 1;
  849. if (y2 >= FONT_SIZE_24)
  850. y2 = FONT_SIZE_24 - 1;
  851. double dx = x0 - x1;
  852. double dy = y0 - y1;
  853. unsigned char q11 = (font[y1 * (FONT_SIZE_24 / 8) + (x1 / 8)] >> (7 - (x1 % 8))) & 1;
  854. unsigned char q21 = (font[y1 * (FONT_SIZE_24 / 8) + (x2 / 8)] >> (7 - (x2 % 8))) & 1;
  855. unsigned char q12 = (font[y2 * (FONT_SIZE_24 / 8) + (x1 / 8)] >> (7 - (x1 % 8))) & 1;
  856. unsigned char q22 = (font[y2 * (FONT_SIZE_24 / 8) + (x2 / 8)] >> (7 - (x2 % 8))) & 1;
  857. double interpolated_value = (1 - dx) * (1 - dy) * q11 + dx * (1 - dy) * q21 +
  858. (1 - dx) * dy * q12 + dx * dy * q22;
  859. int index = y * ENLARGED_FONT_SIZE_48 + x;
  860. if (interpolated_value >= 0.5)
  861. {
  862. enlarged_font[index / 8] |= (1 << (7 - (index % 8)));
  863. }
  864. else
  865. {
  866. enlarged_font[index / 8] &= ~(1 << (7 - (index % 8)));
  867. }
  868. }
  869. }
  870. int Xpoint = Xstart, Ypoint = Ystart;
  871. const unsigned char *ptr = enlarged_font;
  872. UWORD Page = 0, Column = 0;
  873. for (Page = 0; Page < ENLARGED_FONT_SIZE_48; Page++)
  874. {
  875. for (Column = 0; Column < ENLARGED_FONT_SIZE_48; Column++)
  876. {
  877. // To determine whether the font background color and screen background color is consistent
  878. if (FONT_BACKGROUND == BLACK)
  879. { // this process is to speed up the scan
  880. if (*ptr & (0x80 >> (Column % 8)))
  881. Paint_SetPixel(Xpoint + Column, Ypoint + Page, WHITE);
  882. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  883. }
  884. else
  885. {
  886. if (*ptr & (0x80 >> (Column % 8)))
  887. {
  888. Paint_SetPixel(Xpoint + Column, Ypoint + Page, WHITE);
  889. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  890. }
  891. else
  892. {
  893. Paint_SetPixel(Xpoint + Column, Ypoint + Page, BLACK);
  894. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  895. }
  896. }
  897. // One pixel is 8 bits
  898. if (Column % 8 == 7)
  899. ptr++;
  900. } // Write a line
  901. if (ENLARGED_FONT_SIZE_48 % 8 != 0)
  902. ptr++;
  903. } // Write all
  904. }
  905. void Paint_DrawChar_CN64(UWORD Xstart, UWORD Ystart, const char *pString)
  906. {
  907. #define FONT_SIZE 32
  908. // 放大后的64x64点阵字库
  909. #define ENLARGED_FONT_SIZE 64
  910. const char *p_text = pString;
  911. unsigned char enlarged_font[64 * 64 / 8] = {};
  912. unsigned char font[32 * 32 / 8] = {};
  913. // ESP_LOG_BUFFER_HEX(LOG_TAG,pString,2);
  914. if (*pString > 0x80)
  915. {
  916. // ESP_LOGW(LOG_TAG,"汉字");
  917. GBK_32_GetData(*p_text, *(p_text + 1), font);
  918. }
  919. else
  920. {
  921. // ESP_LOGW(LOG_TAG,"ASCII");
  922. ASCII_GetData(*(p_text), ASCII_32_N, font);
  923. }
  924. double scale = (double)ENLARGED_FONT_SIZE / FONT_SIZE;
  925. for (int y = 0; y < ENLARGED_FONT_SIZE; y++)
  926. {
  927. for (int x = 0; x < ENLARGED_FONT_SIZE; x++)
  928. {
  929. double x0 = x / scale;
  930. double y0 = y / scale;
  931. int x1 = (int)x0;
  932. int y1 = (int)y0;
  933. int x2 = x1 + 1;
  934. int y2 = y1 + 1;
  935. if (x2 >= FONT_SIZE)
  936. x2 = FONT_SIZE - 1;
  937. if (y2 >= FONT_SIZE)
  938. y2 = FONT_SIZE - 1;
  939. double dx = x0 - x1;
  940. double dy = y0 - y1;
  941. unsigned char q11 = (font[y1 * (FONT_SIZE / 8) + (x1 / 8)] >> (7 - (x1 % 8))) & 1;
  942. unsigned char q21 = (font[y1 * (FONT_SIZE / 8) + (x2 / 8)] >> (7 - (x2 % 8))) & 1;
  943. unsigned char q12 = (font[y2 * (FONT_SIZE / 8) + (x1 / 8)] >> (7 - (x1 % 8))) & 1;
  944. unsigned char q22 = (font[y2 * (FONT_SIZE / 8) + (x2 / 8)] >> (7 - (x2 % 8))) & 1;
  945. double interpolated_value = (1 - dx) * (1 - dy) * q11 + dx * (1 - dy) * q21 +
  946. (1 - dx) * dy * q12 + dx * dy * q22;
  947. int index = y * ENLARGED_FONT_SIZE + x;
  948. if (interpolated_value >= 0.5)
  949. {
  950. enlarged_font[index / 8] |= (1 << (7 - (index % 8)));
  951. }
  952. else
  953. {
  954. enlarged_font[index / 8] &= ~(1 << (7 - (index % 8)));
  955. }
  956. }
  957. }
  958. int Xpoint = Xstart, Ypoint = Ystart;
  959. const unsigned char *ptr = enlarged_font;
  960. UWORD Page = 0, Column = 0;
  961. for (Page = 0; Page < ENLARGED_FONT_SIZE; Page++)
  962. {
  963. for (Column = 0; Column < ENLARGED_FONT_SIZE; Column++)
  964. {
  965. // To determine whether the font background color and screen background color is consistent
  966. if (FONT_BACKGROUND == WHITE)
  967. { // this process is to speed up the scan
  968. if (*ptr & (0x80 >> (Column % 8)))
  969. Paint_SetPixel(Xpoint + Column, Ypoint + Page, BLACK);
  970. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  971. }
  972. else
  973. {
  974. if (*ptr & (0x80 >> (Column % 8)))
  975. {
  976. Paint_SetPixel(Xpoint + Column, Ypoint + Page, BLACK);
  977. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  978. }
  979. else
  980. {
  981. Paint_SetPixel(Xpoint + Column, Ypoint + Page, WHITE);
  982. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  983. }
  984. }
  985. // One pixel is 8 bits
  986. if (Column % 8 == 7)
  987. ptr++;
  988. } // Write a line
  989. if (ENLARGED_FONT_SIZE % 8 != 0)
  990. ptr++;
  991. } // Write all
  992. }
  993. void Paint_DrawChar_CN(UWORD Xstart, UWORD Ystart, const char *pString, FONT_TYPE_T *chinese_type,
  994. UWORD Color_Foreground, UWORD Color_Background)
  995. {
  996. const char *p_text = pString;
  997. int Xpoint = Xstart, Ypoint = Ystart;
  998. int font_width = 0, font_height = 0;
  999. unsigned char get_chinese_data_buf[32 * 4] = {};
  1000. font_width = chinese_type->Font_Width;
  1001. font_height = chinese_type->Font_Height;
  1002. switch (chinese_type->Font_Width)
  1003. {
  1004. // case CHINESE_TYPE_12: font_width = 12; font_height = 12; break;
  1005. case 16:
  1006. {
  1007. GB2312_16_GetData(*p_text, *(p_text + 1), get_chinese_data_buf);
  1008. }
  1009. break;
  1010. case 24:
  1011. {
  1012. GBK_24_GetData(*p_text, *(p_text + 1), get_chinese_data_buf);
  1013. }
  1014. break;
  1015. case 32:
  1016. {
  1017. GBK_32_GetData(*p_text, *(p_text + 1), get_chinese_data_buf);
  1018. }
  1019. break;
  1020. default:
  1021. break;
  1022. }
  1023. // for(int i=0;i<32*4;i++)
  1024. // {
  1025. // printf("%02x ",get_chinese_data_buf[i]);
  1026. // }
  1027. // printf("\n-------------------------\n");
  1028. const unsigned char *ptr = get_chinese_data_buf;
  1029. UWORD Page = 0, Column = 0;
  1030. for (Page = 0; Page < font_height; Page++)
  1031. {
  1032. for (Column = 0; Column < font_width; Column++)
  1033. {
  1034. // To determine whether the font background color and screen background color is consistent
  1035. if (FONT_BACKGROUND == Color_Foreground)
  1036. { // this process is to speed up the scan
  1037. if (*ptr & (0x80 >> (Column % 8)))
  1038. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
  1039. }
  1040. else
  1041. {
  1042. if (*ptr & (0x80 >> (Column % 8)))
  1043. {
  1044. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
  1045. }
  1046. else
  1047. {
  1048. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
  1049. }
  1050. }
  1051. // One pixel is 8 bits
  1052. if (Column % 8 == 7)
  1053. ptr++;
  1054. } // Write a line
  1055. if (font_width % 8 != 0)
  1056. ptr++;
  1057. } // Write all
  1058. }
  1059. void Paint_DrawString_CN48(UWORD Xstart, UWORD Ystart, const char *pString, int is_black)
  1060. {
  1061. UWORD Xpoint = Xstart;
  1062. UWORD Ypoint = Ystart;
  1063. if (Xstart > Paint_info.Width || Ystart > Paint_info.Height)
  1064. {
  1065. Debug("Paint_DrawString_CN Input exceeds the normal display range\r\n");
  1066. return;
  1067. }
  1068. // ESP_LOGW(LOG_TAG,"------CN64--len =%d --:%s--",strlen(pString),pString);
  1069. // while (((* pString != '\0')&&(* (pString + 1) != '\0'))||((* pString == '\0')&&(* (pString + 1) != '\0'))){
  1070. while (*pString != '\0')
  1071. {
  1072. // if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  1073. if ((Xpoint + 48) > Paint_info.Width)
  1074. {
  1075. Xpoint = Xstart;
  1076. Ypoint += 48;
  1077. }
  1078. // ESP_LOGW(LOG_TAG,"------6464------");
  1079. // If the Y direction is full, reposition to(Xstart, Ystart)
  1080. if ((Ypoint + 48) > Paint_info.Height)
  1081. {
  1082. Xpoint = Xstart;
  1083. Ypoint = Ystart;
  1084. }
  1085. if (*pString > 0x80)
  1086. {
  1087. if (!is_black)
  1088. Paint_DrawChar_CN48(Xpoint, Ypoint, pString);
  1089. else
  1090. Paint_DrawChar_CN48_black(Xpoint, Ypoint, pString);
  1091. // The next character of the address
  1092. pString++;
  1093. pString++;
  1094. // The next word of the abscissa increases the font of the broadband
  1095. Xpoint += 48;
  1096. }
  1097. else // ascii
  1098. {
  1099. if (!is_black)
  1100. Paint_DrawChar_CN48(Xpoint, Ypoint, pString);
  1101. else
  1102. Paint_DrawChar_CN48_black(Xpoint, Ypoint, pString);
  1103. // The next character of the address
  1104. pString++;
  1105. // The next word of the abscissa increases the font of the broadband
  1106. Xpoint += 48;
  1107. }
  1108. }
  1109. }
  1110. void Paint_DrawString_CN64(UWORD Xstart, UWORD Ystart, const char *pString)
  1111. {
  1112. UWORD Xpoint = Xstart;
  1113. UWORD Ypoint = Ystart;
  1114. if (Xstart > Paint_info.Width || Ystart > Paint_info.Height)
  1115. {
  1116. Debug("Paint_DrawString_CN Input exceeds the normal display range\r\n");
  1117. return;
  1118. }
  1119. // ESP_LOGW(LOG_TAG,"------CN64--len =%d --:%s--",strlen(pString),pString);
  1120. // while (((* pString != '\0')&&(* (pString + 1) != '\0'))||((* pString == '\0')&&(* (pString + 1) != '\0'))){
  1121. while (*pString != '\0')
  1122. {
  1123. // if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  1124. if ((Xpoint + 64) > Paint_info.Width)
  1125. {
  1126. Xpoint = Xstart;
  1127. Ypoint += 64;
  1128. }
  1129. // ESP_LOGW(LOG_TAG,"------6464------");
  1130. // If the Y direction is full, reposition to(Xstart, Ystart)
  1131. if ((Ypoint + 64) > Paint_info.Height)
  1132. {
  1133. Xpoint = Xstart;
  1134. Ypoint = Ystart;
  1135. }
  1136. if (*pString > 0x80)
  1137. {
  1138. Paint_DrawChar_CN64(Xpoint, Ypoint, pString);
  1139. // The next character of the address
  1140. pString++;
  1141. pString++;
  1142. // The next word of the abscissa increases the font of the broadband
  1143. Xpoint += 64;
  1144. }
  1145. else // ascii
  1146. {
  1147. Paint_DrawChar_CN64(Xpoint, Ypoint, pString);
  1148. // The next character of the address
  1149. pString++;
  1150. // The next word of the abscissa increases the font of the broadband
  1151. Xpoint += 64;
  1152. }
  1153. }
  1154. }
  1155. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char *pString, FONT_TYPE_T *chinese_type,
  1156. UWORD Color_Foreground, UWORD Color_Background)
  1157. {
  1158. UWORD Xpoint = Xstart;
  1159. UWORD Ypoint = Ystart;
  1160. int font_width = 0, font_height = 0;
  1161. font_width = chinese_type->Font_Width;
  1162. font_height = chinese_type->Font_Height;
  1163. if (Xstart > Paint_info.Width || Ystart > Paint_info.Height)
  1164. {
  1165. Debug("Paint_DrawString_CN Input exceeds the normal display range\r\n");
  1166. return;
  1167. }
  1168. while ((*pString != '\0') || (*(pString + 1) != '\0'))
  1169. {
  1170. // if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  1171. if ((Xpoint + font_width) > Paint_info.Width)
  1172. {
  1173. Xpoint = Xstart;
  1174. Ypoint += font_height;
  1175. }
  1176. // If the Y direction is full, reposition to(Xstart, Ystart)
  1177. if ((Ypoint + font_height) > Paint_info.Height)
  1178. {
  1179. Xpoint = Xstart;
  1180. Ypoint = Ystart;
  1181. }
  1182. #if 0
  1183. if(((*(pString +1))== '\0') && ((* pString)<0x80))
  1184. #else
  1185. if (((*pString) < 0x80))
  1186. #endif
  1187. {
  1188. font_width = chinese_type->Font_Width;
  1189. font_height = chinese_type->Font_Height;
  1190. #if 0
  1191. FONT_TYPE_T ascii_type_5x7 = {"ascii_type_5x7",ASCII_5X7,5,7,};
  1192. FONT_TYPE_T ascii_type_7x8 ={"ascii_type_7x8",ASCII_7X8,7,8,};
  1193. FONT_TYPE_T ascii_type_6x12 ={"ascii_type_6x12",ASCII_6X12,6,12,};
  1194. FONT_TYPE_T ascii_type_8x16 ={"ascii_type_8x16",ASCII_8X16,8,16,};
  1195. FONT_TYPE_T ascii_type_12x24 ={"ascii_type_12x24",ASCII_12X24,12,24,};
  1196. FONT_TYPE_T ascii_type_12x24_b ={"ascii_type_12x24_b",ASCII_12X24_B,12,24,};
  1197. FONT_TYPE_T ascii_type_16x32 ={"ascii_type_16x32",ASCII_16X32,16,32,};
  1198. #endif
  1199. switch (font_height)
  1200. {
  1201. case 8:
  1202. Paint_DrawString_EN(Xpoint, Ypoint, (pString), &ascii_type_7x8, Color_Foreground, Color_Background);
  1203. break;
  1204. case 16:
  1205. Paint_DrawString_EN(Xpoint, Ypoint, (pString), &ascii_type_8x16, Color_Foreground, Color_Background);
  1206. break;
  1207. case 24:
  1208. // printf("");
  1209. Paint_DrawString_EN(Xpoint, Ypoint, (pString), &ascii_type_12x24, Color_Foreground, Color_Background);
  1210. break;
  1211. case 32:
  1212. Paint_DrawString_EN(Xpoint, Ypoint, (pString), &ascii_type_16x32, Color_Foreground, Color_Background);
  1213. break;
  1214. }
  1215. Xpoint += font_width / 2;
  1216. pString++;
  1217. }
  1218. else
  1219. {
  1220. Paint_DrawChar_CN(Xpoint, Ypoint, pString, chinese_type, Color_Foreground, Color_Background);
  1221. Xpoint += font_width;
  1222. // The next character of the address
  1223. pString++;
  1224. pString++;
  1225. }
  1226. // The next word of the abscissa increases the font of the broadband
  1227. }
  1228. }
  1229. // void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, FONT_TYPE_T chinese_type,
  1230. // UWORD Color_Foreground, UWORD Color_Background)
  1231. // {
  1232. // }
  1233. // whc set end
  1234. /******************************************************************************
  1235. function: Display time
  1236. parameter:
  1237. Xstart :X coordinate
  1238. Ystart : Y coordinate
  1239. pTime : Time-related structures
  1240. Font :A structure pointer that displays a character size
  1241. Color_Foreground : Select the foreground color
  1242. Color_Background : Select the background color
  1243. ******************************************************************************/
  1244. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, FONT_TYPE_T *Font_type,
  1245. UWORD Color_Foreground, UWORD Color_Background)
  1246. {
  1247. uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  1248. UWORD Dx = Font_type->Font_Width;
  1249. // Write data into the cache
  1250. // Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font_type, Color_Foreground, Color_Background );
  1251. // Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font_type, Color_Foreground, Color_Background );
  1252. // Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font_type, Color_Foreground, Color_Background );
  1253. // Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font_type, Color_Foreground, Color_Background );
  1254. // Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font_type, Color_Foreground, Color_Background );
  1255. // Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font_type, Color_Foreground, Color_Background );
  1256. // Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font_type, Color_Foreground, Color_Background );
  1257. // Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font_type, Color_Foreground, Color_Background );
  1258. Paint_DrawChar(Xstart, Ystart, value[pTime->Hour / 10], Font_type, Color_Foreground, Color_Background);
  1259. Paint_DrawChar(Xstart + Dx, Ystart, value[pTime->Hour % 10], Font_type, Color_Foreground, Color_Background);
  1260. Paint_DrawChar(Xstart + Dx * 2, Ystart, ':', Font_type, Color_Foreground, Color_Background);
  1261. Paint_DrawChar(Xstart + Dx * 3, Ystart, value[pTime->Min / 10], Font_type, Color_Foreground, Color_Background);
  1262. Paint_DrawChar(Xstart + Dx * 4, Ystart, value[pTime->Min % 10], Font_type, Color_Foreground, Color_Background);
  1263. Paint_DrawChar(Xstart + Dx * 5, Ystart, ':', Font_type, Color_Foreground, Color_Background);
  1264. Paint_DrawChar(Xstart + Dx * 6, Ystart, value[pTime->Sec / 10], Font_type, Color_Foreground, Color_Background);
  1265. Paint_DrawChar(Xstart + Dx * 7, Ystart, value[pTime->Sec % 10], Font_type, Color_Foreground, Color_Background);
  1266. }
  1267. /******************************************************************************
  1268. function: Display monochrome bitmap
  1269. parameter:
  1270. image_buffer :A picture data converted to a bitmap
  1271. info:
  1272. Use a computer to convert the image into a corresponding array,
  1273. and then embed the array directly into Imagedata.cpp as a .c file.
  1274. ******************************************************************************/
  1275. void Paint_DrawBitMap(const unsigned char *image_buffer)
  1276. {
  1277. UWORD x, y;
  1278. UDOUBLE Addr = 0;
  1279. for (y = 0; y < Paint_info.HeightByte; y++)
  1280. {
  1281. for (x = 0; x < Paint_info.WidthByte; x++)
  1282. { // 8 pixel = 1 byte
  1283. Addr = x + y * Paint_info.WidthByte;
  1284. Paint_info.Image[Addr] = (unsigned char)image_buffer[Addr];
  1285. }
  1286. }
  1287. }
  1288. /******************************************************************************
  1289. function: Paint_DrawBitMap_Vertical 垂直对称显示背景图片
  1290. parameter:
  1291. image_buffer :A picture data converted to a bitmap
  1292. info:
  1293. Use a computer to convert the image into a corresponding array,
  1294. and then embed the array directly into Imagedata.cpp as a .c file.
  1295. ******************************************************************************/
  1296. void Paint_DrawBitMap_Vertical(const unsigned char *image_buffer)
  1297. {
  1298. uint8_t temp_buffer[648 / 8] = {0};
  1299. UWORD x, y;
  1300. for (y = 0; y < Paint_info.HeightByte; y++)
  1301. {
  1302. memcpy(temp_buffer, (unsigned char *)&image_buffer[(Paint_info.HeightByte - y) * Paint_info.WidthByte], 648 / 8);
  1303. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  1304. memcpy(&Paint_info.Image[y * Paint_info.WidthByte], temp_buffer, 648 / 8);
  1305. }
  1306. }
  1307. /******************************************************************************
  1308. function: paste monochrome bitmap to a frame buff
  1309. parameter:
  1310. image_buffer :A picture data converted to a bitmap
  1311. xStart: The starting x coordinate
  1312. yStart: The starting y coordinate
  1313. imageWidth: Original image width
  1314. imageHeight: Original image height
  1315. flipColor: Whether the color is reversed
  1316. info:
  1317. Use this function to paste image data into a buffer
  1318. ******************************************************************************/
  1319. void Paint_DrawBitMap_Paste(const unsigned char *image_buffer, UWORD xStart, UWORD yStart, UWORD imageWidth,
  1320. UWORD imageHeight, UBYTE flipColor)
  1321. {
  1322. UBYTE color, srcImage;
  1323. UWORD x, y;
  1324. UWORD width = (imageWidth % 8 == 0 ? imageWidth / 8 : imageWidth / 8 + 1);
  1325. for (y = 0; y < imageHeight; y++)
  1326. {
  1327. for (x = 0; x < imageWidth; x++)
  1328. {
  1329. srcImage = image_buffer[y * width + x / 8];
  1330. if (flipColor)
  1331. color = (((srcImage << (x % 8) & 0x80) == 0) ? 0xff : 0x00);
  1332. else
  1333. color = (((srcImage << (x % 8) & 0x80) == 0) ? 0 : 0xff);
  1334. Paint_SetPixel(x + xStart, y + yStart, color);
  1335. }
  1336. }
  1337. }
  1338. void Paint_DrawBitMap_Paste_t(const unsigned char *image_buffer, UWORD xStart, UWORD yStart, UWORD imageWidth,
  1339. UWORD imageHeight, UBYTE flipColor)
  1340. {
  1341. int i = 0;
  1342. UBYTE color, srcImage;
  1343. UWORD x, y;
  1344. UWORD width = (imageWidth % 8 == 0 ? imageWidth / 8 : imageWidth / 8 + 1);
  1345. for (y = 0; y < imageHeight; y++)
  1346. {
  1347. for (x = 0; x < imageWidth; x++)
  1348. {
  1349. srcImage = image_buffer[y * width + x / 8];
  1350. if (flipColor)
  1351. color = (((srcImage << (x % 8) & 0x80) == 0) ? 0xff : 0x00);
  1352. else
  1353. color = (((srcImage << (x % 8) & 0x80) == 0) ? 0 : 0xff);
  1354. printf("%02x ", color);
  1355. i++;
  1356. Paint_SetPixel(x + xStart, y + yStart, color);
  1357. }
  1358. }
  1359. printf("[%d]\n", i);
  1360. }
  1361. ///******************************************************************************
  1362. // function: SDisplay half of monochrome bitmap
  1363. // parameter:
  1364. // Region : 1 Upper half
  1365. // 2 Lower half
  1366. // info:
  1367. //******************************************************************************/
  1368. // void Paint_DrawBitMap_Half(const unsigned char* image_buffer, UBYTE Region)
  1369. //{
  1370. // UWORD x, y;
  1371. // UDOUBLE Addr = 0;
  1372. //
  1373. // if(Region == 1){
  1374. // for (y = 0; y < Paint.HeightByte; y++) {
  1375. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  1376. // Addr = x + y * Paint.WidthByte;
  1377. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  1378. // }
  1379. // }
  1380. // }else{
  1381. // for (y = 0; y < Paint.HeightByte; y++) {
  1382. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  1383. // Addr = x + y * Paint.WidthByte ;
  1384. // Paint.Image[Addr] =
  1385. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  1386. // }
  1387. // }
  1388. // }
  1389. // }
  1390. ///******************************************************************************
  1391. // function: SDisplay half of monochrome bitmap
  1392. // parameter:
  1393. // Region : 1 Upper half
  1394. // 2 Lower half
  1395. // info:
  1396. //******************************************************************************/
  1397. // void Paint_DrawBitMap_OneQuarter(const unsigned char* image_buffer, UBYTE Region)
  1398. //{
  1399. // UWORD x, y;
  1400. // UDOUBLE Addr = 0;
  1401. //
  1402. // if(Region == 1){
  1403. // for (y = 0; y < Paint.HeightByte; y++) {
  1404. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  1405. // Addr = x + y * Paint.WidthByte;
  1406. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  1407. // }
  1408. // }
  1409. // }else if(Region == 2){
  1410. // for (y = 0; y < Paint.HeightByte; y++) {
  1411. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  1412. // Addr = x + y * Paint.WidthByte ;
  1413. // Paint.Image[Addr] =
  1414. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  1415. // }
  1416. // }
  1417. // }else if(Region == 3){
  1418. // for (y = 0; y < Paint.HeightByte; y++) {
  1419. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  1420. // Addr = x + y * Paint.WidthByte ;
  1421. // Paint.Image[Addr] =
  1422. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*2];
  1423. // }
  1424. // }
  1425. // }else if(Region == 4){
  1426. // for (y = 0; y < Paint.HeightByte; y++) {
  1427. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  1428. // Addr = x + y * Paint.WidthByte ;
  1429. // Paint.Image[Addr] =
  1430. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*3];
  1431. // }
  1432. // }
  1433. // }
  1434. // }
  1435. void Paint_DrawBitMap_Block(const unsigned char *image_buffer, UBYTE Region)
  1436. {
  1437. UWORD x, y;
  1438. UDOUBLE Addr = 0;
  1439. for (y = 0; y < Paint_info.HeightByte; y++)
  1440. {
  1441. for (x = 0; x < Paint_info.WidthByte; x++)
  1442. { // 8 pixel = 1 byte
  1443. Addr = x + y * Paint_info.WidthByte;
  1444. Paint_info.Image[Addr] =
  1445. (unsigned char)image_buffer[Addr + (Paint_info.HeightByte) * Paint_info.WidthByte * (Region - 1)];
  1446. }
  1447. }
  1448. }
  1449. void drawQuadraticBezierCurve(uint8_t *framebuffer, int width, int height,
  1450. int x0, int y0, int x1, int y1, int x2, int y2,
  1451. uint8_t color, int thickness)
  1452. {
  1453. // 使用二次贝塞尔曲线算法计算曲线上的点并绘制
  1454. for (double t = 0; t <= 1.0; t += 0.01)
  1455. {
  1456. double u = 1.0 - t;
  1457. double tt = t * t;
  1458. double uu = u * u;
  1459. double ut = u * t;
  1460. int x = (int)(uu * x0 + 2 * ut * x1 + tt * x2);
  1461. int y = (int)(uu * y0 + 2 * ut * y1 + tt * y2);
  1462. // 绘制线条
  1463. for (int i = -thickness / 2; i <= thickness / 2; i++)
  1464. {
  1465. for (int j = -thickness / 2; j <= thickness / 2; j++)
  1466. {
  1467. int currentX = x + i;
  1468. int currentY = y + j;
  1469. // 检查点是否在屏幕范围内
  1470. if (currentX >= 0 && currentX < width && currentY >= 0 && currentY < height)
  1471. {
  1472. // 计算帧缓冲中的字节和位偏移
  1473. int byteOffset = (currentY * width + currentX) / 8;
  1474. int bitOffset = (currentY * width + currentX) % 8;
  1475. // 根据颜色设置像素值
  1476. if (color)
  1477. {
  1478. framebuffer[byteOffset] |= (0x80 >> bitOffset);
  1479. }
  1480. else
  1481. {
  1482. framebuffer[byteOffset] &= ~(0x80 >> bitOffset);
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. #include "math.h"
  1490. void drawQuadraticBezierCurve_do(uint8_t *framebuffer, int width, int height,
  1491. int x0, int y0, int x1, int y1, int x2, int y2,
  1492. uint8_t color, int thickness)
  1493. {
  1494. // 使用二次贝塞尔曲线算法计算曲线上的点并绘制
  1495. for (double t = 0; t <= 1.0; t += 0.01)
  1496. {
  1497. double u = 1.0 - t;
  1498. double tt = t * t;
  1499. double uu = u * u;
  1500. double ut = u * t;
  1501. int x = (int)(uu * x0 + 2 * ut * x1 + tt * x2);
  1502. int y = (int)(uu * y0 + 2 * ut * y1 + tt * y2);
  1503. // 绘制线条
  1504. for (int i = -thickness / 2; i <= thickness / 2; i++)
  1505. {
  1506. for (int j = -thickness / 2; j <= thickness / 2; j++)
  1507. {
  1508. int currentX = x + i;
  1509. int currentY = y + j;
  1510. // 检查点是否在屏幕范围内
  1511. if (currentX >= 0 && currentX < width && currentY >= 0 && currentY < height)
  1512. {
  1513. // 计算帧缓冲中的字节和位偏移
  1514. int byteOffset = (currentY * width + currentX) / 8;
  1515. int bitOffset = (currentY * width + currentX) % 8;
  1516. // 根据颜色设置像素值
  1517. if (color)
  1518. {
  1519. framebuffer[byteOffset] |= (0x80 >> bitOffset);
  1520. }
  1521. else
  1522. {
  1523. framebuffer[byteOffset] &= ~(0x80 >> bitOffset);
  1524. }
  1525. if (abs(x - (uu * x0 + 2 * ut * x1 + tt * x2)) > 1 || abs(y - (uu * y0 + 2 * ut * y1 + tt * y2)) > 1)
  1526. {
  1527. ESP_LOGW(LOG_TAG, "---abs");
  1528. int byteOffset = (y * width + x) / 8;
  1529. int bitOffset = (y * width + x) % 8;
  1530. if (color)
  1531. {
  1532. framebuffer[byteOffset] &= ~(0x80 >> bitOffset);
  1533. }
  1534. else
  1535. {
  1536. framebuffer[byteOffset] |= (0x80 >> bitOffset);
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. }
  1543. }