{"id":1330,"date":"2023-04-03T14:18:12","date_gmt":"2023-04-03T06:18:12","guid":{"rendered":"https:\/\/www.huangrongzhen.ink\/?p=1330"},"modified":"2023-04-03T18:28:17","modified_gmt":"2023-04-03T10:28:17","slug":"20-%e5%8d%95%e7%89%87%e6%9c%ba-gui-%e8%ae%be%e8%ae%a1%ef%bc%88%e4%ba%8c%e5%8d%81%ef%bc%89-gif-%e6%98%be%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/www.huangrongzhen.ink\/?p=1330","title":{"rendered":"\u5355\u7247\u673a GUI \u8bbe\u8ba1\uff08\u4e8c\u5341\uff09- GIF \u663e\u793a"},"content":{"rendered":"<div class=\"wp-block-post-excerpt\"><p class=\"wp-block-post-excerpt__excerpt\">\u57fa\u4e8e GD32F303ZET6 \u82f9\u679c\u6d3e\u5f00\u53d1\u677f <\/p><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%AE%80%E4%BB%8B\"><\/span>\u7b80\u4ecb<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u524d\u9762\u7684\u5b9e\u9a8c\u4e2d\u4ecb\u7ecd\u4e86 BMP\u3001JPEG \u548c PNG \u7684\u89e3\u7801\u663e\u793a\uff0c\u672c\u7ae0\u4e2d\u5c06\u4ecb\u7ecd\u5982\u4f55\u89e3\u7801 GIF \u56fe\u7247\u3002<\/p>\n\n\n\n<p>GIF \u56fe\u7247\uff0c\u5373\u4e3a\u5e38\u8bf4\u7684\u52a8\u56fe\uff0c\u53ef\u4ee5\u663e\u793a\u7b80\u5355\u7684\u52a8\u753b\u6548\u679c\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u8131\u4e86\u90a3\u4e48\u4e45\uff0c\u4e3b\u8981\u662f\u6ca1\u6709\u627e\u5230\u4e00\u4e2a\u597d\u7684 GIF \u89e3\u7801\u5e93\u3002\u6211\u5728\u7f51\u4e0a\u641c\u7d22\u4e86\u5f88\u4e45\uff0c\u90a3\u4e9b GIF \u89e3\u7801\u5e93\u90fd\u662f\u57fa\u4e8e PC \u5e73\u53f0\u7684\uff0c\u57fa\u672c\u4e0d\u80fd\u5728 Keil \u4e0a\u7f16\u8bd1\u901a\u8fc7\u3002\u5728\u8fd9\u671f\u95f4\u6211\u8fd8\u5c1d\u8bd5\u8fc7\u539f\u5b50\u54e5\u7684 GIF \u9a71\u52a8\uff0c\u4e0d\u8fc7\u4ed6\u5bb6\u7684\u9a71\u52a8\uff0c\u53ea\u80fd\u663e\u793a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684 GIF\uff0c\u540e\u6765\u6211\u5c06\u6240\u6709\u6587\u4ef6\u64cd\u4f5c\u76f8\u5173\u7684\u51fd\u6570\u90fd\u4fee\u6539\u6210\u5185\u5b58\u64cd\u7eb5\uff0c\u4f46\u662f\u540e\u8fb9\u53c8\u53d1\u73b0\u4e86\u65b0\u95ee\u9898\u3002\u539f\u5b50\u54e5\u63d0\u4f9b\u7684 GIF \u9a71\u52a8\uff0c\u4e0d\u80fd\u6b63\u5e38\u663e\u793a\u5e26\u900f\u660e\u5ea6\u7684 GIF \u56fe\u7247\uff0c\u7136\u800c\u6211\u5bf9 GIF \u7684\u89e3\u7801\u4e0d\u662f\u5f88\u719f\uff0c\u4e0d\u60f3\u4fee\u6539\u5e95\u5c42\u4ee3\u7801\u3002\u4e8e\u662f\u6211\u4fbf\u5230 Github \u4e0a\u641c\u5bfb\uff0c\u7ec8\u4e8e\u627e\u5230\u4e00\u4e2a\u6bd4\u8f83\u5408\u9002\u7684 GIF \u89e3\u7801\u5e93\uff0c\u5373 gifdec\u3002\u8be5\u89e3\u7801\u5e93\u539f\u672c\u662f\u7528\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\uff0c\u663e\u793a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684 GIF \u7684\uff0c\u88ab\u6211\u9b54\u6539\u6210\u53ef\u4ee5\u89e3\u7801\u5185\u5b58\u4e2d\u7684 GIF\u3002\u8fd9\u4e2a\u89e3\u7801\u5e93\u76f8\u5bf9\u4e8e\u539f\u5b50\u54e5\u7684\uff0c\u901f\u5ea6\u6162\u4e86\u4e9b\uff0c\u6d88\u8017\u7684\u5185\u5b58\u6bd4\u8f83\u591a\uff0c\u800c\u4e14<strong>\u5e94\u7528\u5728 FatFS \u4e0a\u65f6\uff0c\u5bb9\u6613\u5361\u6b7b\uff08\u539f\u56e0\u672a\u77e5\uff09<\/strong>\uff0c\u4f46\u662f\u5b83\u53ef\u4ee5\u663e\u793a\u5e26\u900f\u660e\u5ea6\u7684 GIF\u3002<\/p>\n\n\n\n<p>\u867d\u7136\u65e0\u6cd5\u5728 FatFS \u4e0a\u4f7f\u7528\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u5c06 GIF \u76f4\u63a5\u56fa\u5316\u5230 Flash\uff0c\u76f8\u5f53\u4e8e\u5728\u5185\u5b58\u4e2d\u8bbf\u95ee\uff0c\u89e3\u7801\u663e\u793a\u5c0f\u7684 GIF \u56fe\u7247\u8fd8\u662f\u53ef\u4ee5\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%BA%90%E7%A0%81%E5%A4%B4%E6%96%87%E4%BB%B6\"><\/span>\u6e90\u7801\u5934\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>gifdec \u7684\u5934\u6587\u4ef6\u5982\u4e0b\u6240\u793a\u3002\u8fd9\u5f53\u4e2d\u7684 GIF_MAX_WIDTH \u548c GIF_MAX_HEIGHT \u4e3a GIF \u6700\u5927\u5c3a\u5bf8\uff0c\u8d8a\u5927\uff0c\u89e3\u7801\u65f6\u6240\u6d88\u8017\u7684\u5185\u5b58\u8d8a\u5927\uff0c\u6240\u4ee5\u5728\u5355\u7247\u673a\u4e2d\u53ef\u4ee5\u9002\u5f53\u6539\u5c0f\u4e00\u4e9b\u3002\u6253\u5f00\uff08\u9884\u89e3\u7801\uff09GIF \u65f6\uff0c\u9700\u8981\u63d0\u4f9b\u4e24\u4e2a\u51fd\u6570\uff0c\u4e00\u4e2a\u662f\u8bfb\u53d6\u6570\u636e\u51fd\u6570\uff0c\u53e6\u4e00\u4e2a\u662f\u79fb\u52a8\u8bfb\u5199\u6307\u9488\u51fd\u6570\uff0c\u7a0d\u540e\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#ifndef GIFDEC_H\n#define GIFDEC_H\n\n#include &lt;stdint.h&gt;\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define GIF_MAX_WIDTH  800\n#define GIF_MAX_HEIGHT 480\n\ntypedef void (*gd_READ)(void* param, void* buf, unsigned int num);\ntypedef int (*gd_LSEEK)(void* param, int offset, int whence);\n\ntypedef struct gd_Palette {\n    int size;\n    uint8_t colors[0x100 * 3];\n} gd_Palette;\n\ntypedef struct gd_GCE {\n    uint16_t delay;\n    uint8_t tindex;\n    uint8_t disposal;\n    int input;\n    int transparency;\n} gd_GCE;\n\ntypedef struct gd_GIF {\n    long anim_start;\n    uint16_t width, height;\n    uint16_t depth;\n    uint16_t loop_count;\n    gd_GCE gce;\n    gd_Palette *palette;\n    gd_Palette lct, gct;\n    void (*plain_text)(\n        struct gd_GIF *gif, uint16_t tx, uint16_t ty,\n        uint16_t tw, uint16_t th, uint8_t cw, uint8_t ch,\n        uint8_t fg, uint8_t bg\n    );\n    void (*comment)(struct gd_GIF *gif);\n    void (*application)(struct gd_GIF *gif, char id[8], char auth[3]);\n    uint16_t fx, fy, fw, fh;\n    uint8_t bgindex;\n    uint8_t *canvas;\n    uint8_t frame[4 * GIF_MAX_WIDTH * GIF_MAX_HEIGHT];\n    gd_READ read;\n    gd_LSEEK lseek;\n    void* param;\n} gd_GIF;\n\nint gd_open_gif(gd_GIF* gif, void* param, gd_READ read, gd_LSEEK lseek);\nint gd_get_frame(gd_GIF *gif);\nvoid gd_render_frame(gd_GIF *gif, uint8_t *buffer);\nint gd_is_bgcolor(gd_GIF *gif, uint8_t color[3]);\nvoid gd_rewind(gd_GIF *gif);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif \/* GIFDEC_H *\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%BA%90%E6%96%87%E4%BB%B6\"><\/span>\u6e90\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>gifdec \u7684\u6e90\u6587\u4ef6\u5982\u4e0b\u6240\u793a\u3002\u6e90\u6587\u4ef6\u4e2d\u6709\u6d89\u53ca\u5230\u52a8\u6001\u5185\u5b58\u5206\u914d\u64cd\u4f5c\uff0c\u5982\u679c\u662f\u5e94\u7528\u5230\u5355\u7247\u673a\u4e2d\uff0c\u53ef\u4ee5\u66ff\u6362\u6210\u81ea\u5df1\u7684\u52a8\u6001\u5185\u5b58\u5206\u914d\u51fd\u6570\u3002GIF \u89e3\u7801\u65f6\uff0c\u6240\u9700\u7684\u5185\u5b58\u5f88\u5927\uff0c\u6240\u4ee5\u63a8\u8350\u4f7f\u7528\u5916\u62d3 SRAM\u3002\u5bf9\u4e8e\u82f9\u679c\u6d3e\u5f00\u53d1\u677f\uff0c1MB \u7684\u5916\u62d3 SRAM \u89e3\u7801 GIF \u662f\u6709\u70b9\u5403\u529b\u7684\uff0c\u4f46\u84dd\u8393\u6d3e\u5219\u4e0d\u540c\uff0c\u84dd\u8393\u6d3e\u5f00\u53d1\u677f\u4e0a\u6709 32MB \u7684 SDRAM\uff0c\u5b8c\u5168\u4e0d\u7528\u62c5\u5fc3\u5185\u5b58\u4e0d\u591f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include \"gifdec.h\"\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\n#define MIN(A, B) ((A) &lt; (B) ? (A) : (B))\n#define MAX(A, B) ((A) &gt; (B) ? (A) : (B))\n#define GIF_SEEK_CUR (1)\n#define GIF_SEEK_SET (0)\n\ntypedef struct Entry {\n  uint16_t length;\n  uint16_t prefix;\n  uint8_t  suffix;\n} Entry;\n\ntypedef struct Table {\n  int bulk;\n  int nentries;\n  Entry* entries;\n} Table;\n\nstatic void\ngif_mem_copy(void* des, void* src, unsigned int size)\n{\n  unsigned char* source;\n  unsigned char* target;\n  unsigned int i;\n  source = src;\n  target = des;\n  for (i = 0; i &lt; size; i++)\n  {\n    target[i] = source[i];\n  }\n}\n\nstatic int\ngif_mem_cmp(void* buf1, void* buf2, unsigned int size)\n{\n  unsigned char* source;\n  unsigned char* target;\n  unsigned int i;\n  source = buf1;\n  target = buf2;\n  for (i = 0; i &lt; size; i++)\n  {\n    if (target[i] != source[i])\n    {\n      return 1;\n    }\n  }\n  return 0;\n}\n\nstatic void\ngif_mem_set(void* buf, int value, unsigned int len)\n{\n  unsigned char* buffer;\n  unsigned int i;\n  buffer = buf;\n  for (i = 0; i &lt; len; i++)\n  {\n    buffer[i] = value;\n  }\n}\n\nstatic void* \ngif_malloc(unsigned int size)\n{\n  return malloc(size);\n}\n\nstatic void \ngif_free(void* p)\n{\n  free(p);\n}\n\nstatic uint16_t\nread_num(gd_GIF* gif)\n{\n  uint8_t bytes[2];\n\n  gif-&gt;read(gif-&gt;param, bytes, 2);\n  return bytes[0] + (((uint16_t)bytes[1]) &lt;&lt; 8);\n}\n\nint\ngd_open_gif(gd_GIF* gif, void* param, gd_READ read, gd_LSEEK lseek)\n{\n  uint8_t sigver[3];\n  uint16_t width, height, depth;\n  uint8_t fdsz, bgidx, aspect;\n  int i;\n  uint8_t* bgcolor;\n  int gct_sz;\n\n  gif-&gt;read = read;\n  gif-&gt;lseek = lseek;\n  gif-&gt;param = param;\n\n  \/* Header *\/\n  gif-&gt;read(gif-&gt;param, sigver, 3);\n  if (gif_mem_cmp(sigver, \"GIF\", 3) != 0) {\n    printf(\"invalid signature\\n\");\n    return -1;\n  }\n  \/* Version *\/\n  gif-&gt;read(gif-&gt;param, sigver, 3);\n  if (gif_mem_cmp(sigver, \"89a\", 3) != 0) {\n    printf(\"invalid version\\n\");\n    return -1;\n  }\n  \/* Width x Height *\/\n  width = read_num(gif);\n  height = read_num(gif);\n  if ((width &gt; GIF_MAX_WIDTH) || (height &gt; GIF_MAX_HEIGHT))\n  {\n    printf(\"invalid size\\n\");\n    return -1;\n  }\n  \/* FDSZ *\/\n  gif-&gt;read(gif-&gt;param, &amp;fdsz, 1);\n  \/* Presence of GCT *\/\n  if (!(fdsz &amp; 0x80)) {\n    printf(\"no global color table\\n\");\n    return -1;\n  }\n  \/* Color Space's Depth *\/\n  depth = ((fdsz &gt;&gt; 4) &amp; 7) + 1;\n  \/* Ignore Sort Flag. *\/\n  \/* GCT Size *\/\n  gct_sz = 1 &lt;&lt; ((fdsz &amp; 0x07) + 1);\n  \/* Background Color Index *\/\n  gif-&gt;read(gif-&gt;param, &amp;bgidx, 1);\n  \/* Aspect Ratio *\/\n  gif-&gt;read(gif-&gt;param, &amp;aspect, 1);\n  \/* Init gd_GIF Structure. *\/\n  gif-&gt;width = width;\n  gif-&gt;height = height;\n  gif-&gt;depth = depth;\n  \/* Read GCT *\/\n  gif-&gt;gct.size = gct_sz;\n  gif-&gt;read(gif-&gt;param, gif-&gt;gct.colors, 3 * gif-&gt;gct.size);\n  gif-&gt;palette = &amp;gif-&gt;gct;\n  gif-&gt;bgindex = bgidx;\n  gif-&gt;canvas = &amp;gif-&gt;frame[width * height];\n  if (gif-&gt;bgindex)\n    gif_mem_set(gif-&gt;frame, gif-&gt;bgindex, gif-&gt;width * gif-&gt;height);\n  bgcolor = &amp;gif-&gt;palette-&gt;colors[gif-&gt;bgindex * 3];\n  if (bgcolor[0] || bgcolor[1] || bgcolor[2])\n    for (i = 0; i &lt; gif-&gt;width * gif-&gt;height; i++)\n      gif_mem_copy(&amp;gif-&gt;canvas[i * 3], bgcolor, 3);\n  gif-&gt;anim_start = gif-&gt;lseek(gif-&gt;param, 0, GIF_SEEK_CUR);\n  return 0;\n}\n\nstatic void\ndiscard_sub_blocks(gd_GIF* gif)\n{\n  uint8_t size;\n\n  do {\n    gif-&gt;read(gif-&gt;param, &amp;size, 1);\n    gif-&gt;lseek(gif-&gt;param, size, GIF_SEEK_CUR);\n  } while (size);\n}\n\nstatic void\nread_plain_text_ext(gd_GIF* gif)\n{\n  if (gif-&gt;plain_text) {\n    uint16_t tx, ty, tw, th;\n    uint8_t cw, ch, fg, bg;\n    long sub_block;\n    gif-&gt;lseek(gif-&gt;param, 1, GIF_SEEK_CUR); \/* block size = 12 *\/\n    tx = read_num(gif);\n    ty = read_num(gif);\n    tw = read_num(gif);\n    th = read_num(gif);\n    gif-&gt;read(gif-&gt;param, &amp;cw, 1);\n    gif-&gt;read(gif-&gt;param, &amp;ch, 1);\n    gif-&gt;read(gif-&gt;param, &amp;fg, 1);\n    gif-&gt;read(gif-&gt;param, &amp;bg, 1);\n    sub_block = gif-&gt;lseek(gif-&gt;param, 0, GIF_SEEK_CUR);\n    gif-&gt;plain_text(gif, tx, ty, tw, th, cw, ch, fg, bg);\n    gif-&gt;lseek(gif-&gt;param, sub_block, GIF_SEEK_SET);\n  }\n  else {\n    \/* Discard plain text metadata. *\/\n    gif-&gt;lseek(gif-&gt;param, 13, GIF_SEEK_CUR);\n  }\n  \/* Discard plain text sub-blocks. *\/\n  discard_sub_blocks(gif);\n}\n\nstatic void\nread_graphic_control_ext(gd_GIF* gif)\n{\n  uint8_t rdit;\n\n  \/* Discard block size (always 0x04). *\/\n  gif-&gt;lseek(gif-&gt;param, 1, GIF_SEEK_CUR);\n  gif-&gt;read(gif-&gt;param, &amp;rdit, 1);\n  gif-&gt;gce.disposal = (rdit &gt;&gt; 2) &amp; 3;\n  gif-&gt;gce.input = rdit &amp; 2;\n  gif-&gt;gce.transparency = rdit &amp; 1;\n  gif-&gt;gce.delay = read_num(gif);\n  gif-&gt;read(gif-&gt;param, &amp;gif-&gt;gce.tindex, 1);\n  \/* Skip block terminator. *\/\n  gif-&gt;lseek(gif-&gt;param, 1, GIF_SEEK_CUR);\n}\n\nstatic void\nread_comment_ext(gd_GIF* gif)\n{\n  if (gif-&gt;comment) {\n    long sub_block = gif-&gt;lseek(gif-&gt;param, 0, GIF_SEEK_CUR);\n    gif-&gt;comment(gif);\n    gif-&gt;lseek(gif-&gt;param, sub_block, GIF_SEEK_SET);\n  }\n  \/* Discard comment sub-blocks. *\/\n  discard_sub_blocks(gif);\n}\n\nstatic void\nread_application_ext(gd_GIF* gif)\n{\n  char app_id[8];\n  char app_auth_code[3];\n\n  \/* Discard block size (always 0x0B). *\/\n  gif-&gt;lseek(gif-&gt;param, 1, GIF_SEEK_CUR);\n  \/* Application Identifier. *\/\n  gif-&gt;read(gif-&gt;param, app_id, 8);\n  \/* Application Authentication Code. *\/\n  gif-&gt;read(gif-&gt;param, app_auth_code, 3);\n  if (!gif_mem_cmp(app_id, \"NETSCAPE\", sizeof(app_id))) {\n    \/* Discard block size (0x03) and constant byte (0x01). *\/\n    gif-&gt;lseek(gif-&gt;param, 2, GIF_SEEK_CUR);\n    gif-&gt;loop_count = read_num(gif);\n    \/* Skip block terminator. *\/\n    gif-&gt;lseek(gif-&gt;param, 1, GIF_SEEK_CUR);\n  }\n  else if (gif-&gt;application) {\n    long sub_block = gif-&gt;lseek(gif-&gt;param, 0, GIF_SEEK_CUR);\n    gif-&gt;application(gif, app_id, app_auth_code);\n    gif-&gt;lseek(gif-&gt;param, sub_block, GIF_SEEK_SET);\n    discard_sub_blocks(gif);\n  }\n  else {\n    discard_sub_blocks(gif);\n  }\n}\n\nstatic void\nread_ext(gd_GIF* gif)\n{\n  uint8_t label;\n\n  gif-&gt;read(gif-&gt;param, &amp;label, 1);\n  switch (label) {\n  case 0x01:\n    read_plain_text_ext(gif);\n    break;\n  case 0xF9:\n    read_graphic_control_ext(gif);\n    break;\n  case 0xFE:\n    read_comment_ext(gif);\n    break;\n  case 0xFF:\n    read_application_ext(gif);\n    break;\n  default:\n    printf(\"unknown extension: %02X\\n\", label);\n  }\n}\n\nstatic Table*\nnew_table(int key_size)\n{\n  int key;\n  int init_bulk = MAX(1 &lt;&lt; (key_size + 1), 0x100);\n  Table* table = gif_malloc(sizeof(*table) + sizeof(Entry) * init_bulk);\n  if (table) {\n    table-&gt;bulk = init_bulk;\n    table-&gt;nentries = (1 &lt;&lt; key_size) + 2;\n    table-&gt;entries = (Entry*)&amp;table[1];\n    for (key = 0; key &lt; (1 &lt;&lt; key_size); key++) {\n      table-&gt;entries[key].length = 1;\n      table-&gt;entries[key].prefix = 0xFFF;\n      table-&gt;entries[key].suffix = key;\n    }\n  }\n  return table;\n}\n\n\/* Add table entry. Return value:\n *  0 on success\n *  +1 if key size must be incremented after this addition\n *  -1 if could not realloc table *\/\nstatic int\nadd_entry(Table** tablep, uint16_t length, uint16_t prefix, uint8_t suffix)\n{\n  Table* table = *tablep;\n  if (table-&gt;nentries == table-&gt;bulk) {\n    table-&gt;bulk *= 2;\n    table = realloc(table, sizeof(*table) + sizeof(Entry) * table-&gt;bulk);\n    if (!table) return -1;\n    table-&gt;entries = (Entry*)&amp;table[1];\n    *tablep = table;\n  }\n  table-&gt;entries[table-&gt;nentries].length = length;\n  table-&gt;entries[table-&gt;nentries].prefix = prefix;\n  table-&gt;entries[table-&gt;nentries].suffix = suffix;\n  table-&gt;nentries++;\n  if ((table-&gt;nentries &amp; (table-&gt;nentries - 1)) == 0)\n    return 1;\n  return 0;\n}\n\nstatic uint16_t\nget_key(gd_GIF* gif, int key_size, uint8_t* sub_len, uint8_t* shift, uint8_t* byte)\n{\n  int bits_read;\n  int rpad;\n  int frag_size;\n  uint16_t key;\n\n  key = 0;\n  for (bits_read = 0; bits_read &lt; key_size; bits_read += frag_size) {\n    rpad = (*shift + bits_read) % 8;\n    if (rpad == 0) {\n      \/* Update byte. *\/\n      if (*sub_len == 0) {\n        gif-&gt;read(gif-&gt;param, sub_len, 1); \/* Must be nonzero! *\/\n        if (*sub_len == 0)\n          return 0x1000;\n      }\n      gif-&gt;read(gif-&gt;param, byte, 1);\n      (*sub_len)--;\n    }\n    frag_size = MIN(key_size - bits_read, 8 - rpad);\n    key |= ((uint16_t)((*byte) &gt;&gt; rpad)) &lt;&lt; bits_read;\n  }\n  \/* Clear extra bits to the left. *\/\n  key &amp;= (1 &lt;&lt; key_size) - 1;\n  *shift = (*shift + key_size) % 8;\n  return key;\n}\n\n\/* Compute output index of y-th input line, in frame of height h. *\/\nstatic int\ninterlaced_line_index(int h, int y)\n{\n  int p; \/* number of lines in current pass *\/\n\n  p = (h - 1) \/ 8 + 1;\n  if (y &lt; p) \/* pass 1 *\/\n    return y * 8;\n  y -= p;\n  p = (h - 5) \/ 8 + 1;\n  if (y &lt; p) \/* pass 2 *\/\n    return y * 8 + 4;\n  y -= p;\n  p = (h - 3) \/ 4 + 1;\n  if (y &lt; p) \/* pass 3 *\/\n    return y * 4 + 2;\n  y -= p;\n  \/* pass 4 *\/\n  return y * 2 + 1;\n}\n\n\/* Decompress image pixels.\n * Return 0 on success or -1 on out-of-memory (w.r.t. LZW code table). *\/\nstatic int\nread_image_data(gd_GIF* gif, int interlace)\n{\n  uint8_t sub_len, shift, byte;\n  int init_key_size, key_size, table_is_full;\n  int frm_off, frm_size, str_len, i, p, x, y;\n  uint16_t key, clear, stop;\n  int ret;\n  Table* table;\n  Entry entry;\n  long start, end;\n\n  gif-&gt;read(gif-&gt;param, &amp;byte, 1);\n  key_size = (int)byte;\n  if (key_size &lt; 2 || key_size &gt; 8)\n    return -1;\n\n  start = gif-&gt;lseek(gif-&gt;param, 0, GIF_SEEK_CUR);\n  discard_sub_blocks(gif);\n  end = gif-&gt;lseek(gif-&gt;param, 0, GIF_SEEK_CUR);\n  gif-&gt;lseek(gif-&gt;param, start, GIF_SEEK_SET);\n  clear = 1 &lt;&lt; key_size;\n  stop = clear + 1;\n  table = new_table(key_size);\n  key_size++;\n  init_key_size = key_size;\n  sub_len = shift = 0;\n  key = get_key(gif, key_size, &amp;sub_len, &amp;shift, &amp;byte); \/* clear code *\/\n  frm_off = 0;\n  ret = 0;\n  frm_size = gif-&gt;fw * gif-&gt;fh;\n  while (frm_off &lt; frm_size) {\n    if (key == clear) {\n      key_size = init_key_size;\n      table-&gt;nentries = (1 &lt;&lt; (key_size - 1)) + 2;\n      table_is_full = 0;\n    }\n    else if (!table_is_full) {\n      ret = add_entry(&amp;table, str_len + 1, key, entry.suffix);\n      if (ret == -1) {\n        gif_free(table);\n        return -1;\n      }\n      if (table-&gt;nentries == 0x1000) {\n        ret = 0;\n        table_is_full = 1;\n      }\n    }\n    key = get_key(gif, key_size, &amp;sub_len, &amp;shift, &amp;byte);\n    if (key == clear) continue;\n    if (key == stop || key == 0x1000) break;\n    if (ret == 1) key_size++;\n    entry = table-&gt;entries[key];\n    str_len = entry.length;\n    for (i = 0; i &lt; str_len; i++) {\n      p = frm_off + entry.length - 1;\n      x = p % gif-&gt;fw;\n      y = p \/ gif-&gt;fw;\n      if (interlace)\n        y = interlaced_line_index((int)gif-&gt;fh, y);\n      gif-&gt;frame[(gif-&gt;fy + y) * gif-&gt;width + gif-&gt;fx + x] = entry.suffix;\n      if (entry.prefix == 0xFFF)\n        break;\n      else\n        entry = table-&gt;entries[entry.prefix];\n    }\n    frm_off += str_len;\n    if (key &lt; table-&gt;nentries - 1 &amp;&amp; !table_is_full)\n      table-&gt;entries[table-&gt;nentries - 1].suffix = entry.suffix;\n  }\n  gif_free(table);\n  if (key == stop)\n    gif-&gt;read(gif-&gt;param, &amp;sub_len, 1); \/* Must be zero! *\/\n  gif-&gt;lseek(gif-&gt;param, end, GIF_SEEK_SET);\n  return 0;\n}\n\n\/* Read image.\n * Return 0 on success or -1 on out-of-memory (w.r.t. LZW code table). *\/\nstatic int\nread_image(gd_GIF* gif)\n{\n  uint8_t fisrz;\n  int interlace;\n\n  \/* Image Descriptor. *\/\n  gif-&gt;fx = read_num(gif);\n  gif-&gt;fy = read_num(gif);\n\n  if (gif-&gt;fx &gt;= gif-&gt;width || gif-&gt;fy &gt;= gif-&gt;height)\n    return -1;\n\n  gif-&gt;fw = read_num(gif);\n  gif-&gt;fh = read_num(gif);\n\n  gif-&gt;fw = MIN(gif-&gt;fw, gif-&gt;width - gif-&gt;fx);\n  gif-&gt;fh = MIN(gif-&gt;fh, gif-&gt;height - gif-&gt;fy);\n\n  gif-&gt;read(gif-&gt;param, &amp;fisrz, 1);\n  interlace = fisrz &amp; 0x40;\n  \/* Ignore Sort Flag. *\/\n  \/* Local Color Table? *\/\n  if (fisrz &amp; 0x80) {\n    \/* Read LCT *\/\n    gif-&gt;lct.size = 1 &lt;&lt; ((fisrz &amp; 0x07) + 1);\n    gif-&gt;read(gif-&gt;param, gif-&gt;lct.colors, 3 * gif-&gt;lct.size);\n    gif-&gt;palette = &amp;gif-&gt;lct;\n  }\n  else\n    gif-&gt;palette = &amp;gif-&gt;gct;\n  \/* Image Data. *\/\n  return read_image_data(gif, interlace);\n}\n\nstatic void\nrender_frame_rect(gd_GIF* gif, uint8_t* buffer)\n{\n  int i, j, k;\n  uint8_t index, * color;\n  i = gif-&gt;fy * gif-&gt;width + gif-&gt;fx;\n  for (j = 0; j &lt; gif-&gt;fh; j++) {\n    for (k = 0; k &lt; gif-&gt;fw; k++) {\n      index = gif-&gt;frame[(gif-&gt;fy + j) * gif-&gt;width + gif-&gt;fx + k];\n      color = &amp;gif-&gt;palette-&gt;colors[index * 3];\n      if (!gif-&gt;gce.transparency || index != gif-&gt;gce.tindex)\n        gif_mem_copy(&amp;buffer[(i + k) * 3], color, 3);\n    }\n    i += gif-&gt;width;\n  }\n}\n\nstatic void\ndispose(gd_GIF* gif)\n{\n  int i, j, k;\n  uint8_t* bgcolor;\n  switch (gif-&gt;gce.disposal) {\n  case 2: \/* Restore to background color. *\/\n    bgcolor = &amp;gif-&gt;palette-&gt;colors[gif-&gt;bgindex * 3];\n    i = gif-&gt;fy * gif-&gt;width + gif-&gt;fx;\n    for (j = 0; j &lt; gif-&gt;fh; j++) {\n      for (k = 0; k &lt; gif-&gt;fw; k++)\n        gif_mem_copy(&amp;gif-&gt;canvas[(i + k) * 3], bgcolor, 3);\n      i += gif-&gt;width;\n    }\n    break;\n  case 3: \/* Restore to previous, i.e., don't update canvas.*\/\n    break;\n  default:\n    \/* Add frame non-transparent pixels to canvas. *\/\n    render_frame_rect(gif, gif-&gt;canvas);\n  }\n}\n\n\/* Return 1 if got a frame; 0 if got GIF trailer; -1 if error. *\/\nint\ngd_get_frame(gd_GIF* gif)\n{\n  char sep;\n\n  dispose(gif);\n  gif-&gt;read(gif-&gt;param, &amp;sep, 1);\n  while (sep != ',') {\n    if (sep == ';')\n      return 0;\n    if (sep == '!')\n      read_ext(gif);\n    else return -1;\n    gif-&gt;read(gif-&gt;param, &amp;sep, 1);\n  }\n  if (read_image(gif) == -1)\n    return -1;\n  return 1;\n}\n\nvoid\ngd_render_frame(gd_GIF* gif, uint8_t* buffer)\n{\n  gif_mem_copy(buffer, gif-&gt;canvas, gif-&gt;width * gif-&gt;height * 3);\n  render_frame_rect(gif, buffer);\n}\n\nint\ngd_is_bgcolor(gd_GIF* gif, uint8_t color[3])\n{\n  return !gif_mem_cmp(&amp;gif-&gt;palette-&gt;colors[gif-&gt;bgindex * 3], color, 3);\n}\n\nvoid\ngd_rewind(gd_GIF* gif)\n{\n  gif-&gt;lseek(gif-&gt;param, gif-&gt;anim_start, GIF_SEEK_SET);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%BA%94%E7%94%A8\"><\/span>\u5e94\u7528<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4ecb\u7ecd gifdec \u7684\u5e94\u7528\uff0c\u9996\u5148\u662f\u6dfb\u52a0\u5305\u542b\u5934\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/*********************************************************************************************************\r\n*                                              \u5305\u542b\u5934\u6587\u4ef6\r\n*********************************************************************************************************\/\r\n#include &lt;stdio.h>\r\n#include \".\/LCD\/LCD.h\"\r\n#include &lt;windows.h>\r\n#include \".\/Picture\/gifdec.h\"<\/code><\/pre>\n\n\n\n<p>\u5728\u672c\u6587\u7ae0\uff0c\u663e\u793a GIF \u4e4b\u524d\uff0c\u5df2\u7ecf\u9884\u5148\u5c06 GIF \u8f6c\u6210 C \u8bed\u8a00\u6570\u7ec4\uff0c\u5177\u4f53\u5b9e\u73b0\u53ef\u53c2\u8003 <a href=\"https:\/\/www.huangrongzhen.ink\/?p=66\">AnythingToC-\u4efb\u610f\u6587\u4ef6\u8f6c C \u8bed\u8a00\u6570\u7ec4\u5c0f\u5de5\u5177<\/a>\u3002\u4e3a\u4e86\u8ddf\u8e2a\u8bb0\u5f55 GIF \u6587\u4ef6\u7684\u8bfb\u5199\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/*********************************************************************************************************\r\n*                                              \u679a\u4e3e\u7ed3\u6784\u4f53\u5b9a\u4e49\r\n*********************************************************************************************************\/\r\ntypedef struct\r\n{\r\n  unsigned char* buf;       \/\/\u6570\u636e\u7f13\u51b2\u533a\u9996\u5730\u5740\r\n  unsigned int   readCnt;   \/\/\u8bfb\u53d6\u8ba1\u6570\r\n  unsigned int   totalSize; \/\/GIF \u56fe\u7247\u5927\u5c0f\uff08\u5b57\u8282\uff09\r\n}StructGIFParam;<\/code><\/pre>\n\n\n\n<p>gifdec \u8f93\u51fa\u7684\u662f RGB888 \u683c\u5f0f\uff0c\u800c\u6211\u4eec\u9700\u8981\u7684\u662f RGB565\uff0c\u5355\u7247\u673a\u4e2d\u5927\u591a\u4f7f\u7528\u7684\u662f RGB565 \u683c\u5f0f\uff0c\u6240\u4ee5\u4f1a\u6d89\u53ca\u5230 RGB888 \u4e0e RGB565 \u4e4b\u95f4\u7684\u8f6c\u6362\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/*********************************************************************************************************\r\n* \u51fd\u6570\u540d\u79f0\uff1a GifGetRgb565\r\n* \u51fd\u6570\u529f\u80fd\uff1a \u5c06 RGB888 \u8f6c\u4e3a RGB565\r\n* \u8f93\u5165\u53c2\u6570\uff1a ctb\uff1aRGB888 \u989c\u8272\u6570\u7ec4\u9996\u5730\u5740\r\n* \u8f93\u51fa\u53c2\u6570\uff1a void\r\n* \u8fd4 \u56de \u503c\uff1a RGB565 \u989c\u8272\r\n* \u521b\u5efa\u65e5\u671f\uff1a 2023\u5e7403\u670825\u65e5\r\n* \u6ce8    \u610f\uff1a\r\n*********************************************************************************************************\/\r\nu16 GifGetRgb565(u8* ctb)\r\n{\r\n  u16 r, g, b;\r\n  r = (ctb[0] >> 3) &amp; 0x1F;\r\n  g = (ctb[1] >> 2) &amp; 0x3F;\r\n  b = (ctb[2] >> 3) &amp; 0x1F;\r\n  return b + (g &lt;&lt; 5) + (r &lt;&lt; 11);\r\n}<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0cGIF \u6a21\u5757\u901a\u8fc7\u6b64\u51fd\u6570\u83b7\u53d6 GIF \u6587\u4ef6\u6570\u636e\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\u3002GIFRead \u51fd\u6570\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u7528\u6237\u53c2\u6570\uff0c\u5373\u7528\u6237\u6253\u5f00 GIF \u56fe\u7247\u65f6\u8f93\u5165\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u6307\u5411\u4efb\u610f\u6570\u636e\uff0c\u5728\u8fd9\u91cc\u6211\u4eec\u5047\u5b9a\u4f20\u5165\u7684\u662f\u4e00\u4e2a\u6307\u9488\u53c2\u6570\uff0c\u4e14\u6307\u5411\u4e00\u4e2a StructGIFParam \u7c7b\u578b\u7684\u7ed3\u6784\u4f53\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u663e\u793a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684 GIF \u56fe\u7247\u800c\u8a00\uff0c\u53ea\u9700\u8981\u8c03\u7528 fwrite \u51fd\u6570\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/*********************************************************************************************************\r\n* \u51fd\u6570\u540d\u79f0\uff1a GIFRead\r\n* \u51fd\u6570\u529f\u80fd\uff1a GIF \u89e3\u7801\u6a21\u5757\u8bfb\u53d6\u6570\u636e\r\n* \u8f93\u5165\u53c2\u6570\uff1a param\uff1a\u7528\u6237\u53c2\u6570\uff0cbuf\uff1a\u6570\u636e\u7f13\u51b2\u533a\uff0cnum\uff1a\u8bfb\u53d6\u957f\u5ea6\r\n* \u8f93\u51fa\u53c2\u6570\uff1a void\r\n* \u8fd4 \u56de \u503c\uff1a void\r\n* \u521b\u5efa\u65e5\u671f\uff1a 2023\u5e7403\u670825\u65e5\r\n* \u6ce8    \u610f\uff1a\r\n*********************************************************************************************************\/\r\nvoid GIFRead(void* param, void* buf, unsigned int num)\r\n{\r\n  unsigned int i;\r\n  unsigned char* buffer;\r\n  StructGIFParam* stream;\r\n  buffer = (unsigned char*)buf;\r\n  stream = (StructGIFParam*)param;\r\n  for (i = 0; i &lt; num; i++)\r\n  {\r\n    buffer[i] = stream->buf[stream->readCnt++];\r\n  }\r\n}<\/code><\/pre>\n\n\n\n<p>\u9664\u4e86\u8bfb\u53d6\u6570\u636e\u7684\u51fd\u6570\uff0c\u6211\u4eec\u8fd8\u8981\u4e3a GIF \u89e3\u7801\u6a21\u5757\u63d0\u4f9b\u4fee\u6539\u8bfb\u5199\u4f4d\u7f6e\u7684\u63a5\u53e3\u51fd\u6570\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u663e\u793a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684 GIF \u56fe\u7247\u800c\u8a00\uff0c\u76f4\u63a5\u8c03\u7528 fseek \u51fd\u6570\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/*********************************************************************************************************\r\n* \u51fd\u6570\u540d\u79f0\uff1a GIFLseek\r\n* \u51fd\u6570\u529f\u80fd\uff1a GIF \u8bbe\u7f6e\u8bfb\u5199\u4f4d\u7f6e\r\n* \u8f93\u5165\u53c2\u6570\uff1a param\uff1a\u7528\u6237\u53c2\u6570\r\n*            offset\uff1a\u504f\u79fb\u91cf\uff0c\r\n*            whence\uff1a0-\u4ece\u6587\u4ef6\u5f00\u59cb\u5f80\u540e\u79fb\u52a8 offset \u4e2a\u5b57\u8282\r\n*                    1-\u5f53\u524d\u4f4d\u7f6e\u5f80\u524d\u6216\u5f80\u540e\u79fb\u52a8 offset \u4e2a\u5b57\u8282\r\n* \u8f93\u51fa\u53c2\u6570\uff1a void\r\n* \u8fd4 \u56de \u503c\uff1a \u6210\u529f\uff1a\u8fd4\u56de\u6587\u4ef6\u5f53\u524d\u8bfb\u5199\u4f4d\u7f6e\u76f8\u5bf9\u4e8e\u6587\u4ef6\u5f00\u59cb\u4f4d\u7f6e\u7684\u504f\u79fb\u91cf\uff08\u5b57\u8282\u6570\uff09\r\n*            \u5931\u8d25\uff1a\u8fd4\u56de -1\r\n* \u521b\u5efa\u65e5\u671f\uff1a 2023\u5e7403\u670825\u65e5\r\n* \u6ce8    \u610f\uff1a\r\n*********************************************************************************************************\/\r\nint GIFLseek(void* param, int offset, int whence)\r\n{\r\n  \/\/\u83b7\u53d6\u7528\u6237\u53c2\u6570\r\n  StructGIFParam* stream;\r\n  stream = (StructGIFParam*)param;\r\n\r\n  \/\/\u4ece\u6587\u4ef6\u5f00\u59cb\u5f80\u540e\u79fb\u52a8 offset \u4e2a\u5b57\u8282\r\n  if (0 == whence)\r\n  {\r\n    if (offset &lt;= stream->totalSize)\r\n    {\r\n      stream->readCnt = offset;\r\n      return stream->readCnt;\r\n    }\r\n    else\r\n    {\r\n      return -1;\r\n    }\r\n  }\r\n\r\n  \/\/\u5f53\u524d\u4f4d\u7f6e\u5f80\u524d\u6216\u5f80\u540e\u79fb\u52a8 offset \u4e2a\u5b57\u8282\r\n  else if (1 == whence)\r\n  {\r\n    if ((stream->readCnt + offset) &lt;= stream->totalSize)\r\n    {\r\n      stream->readCnt = stream->readCnt + offset;\r\n      return stream->readCnt;\r\n    }\r\n    else\r\n    {\r\n      return -1;\r\n    }\r\n  }\r\n  return -1;\r\n}<\/code><\/pre>\n\n\n\n<p>\u5b9a\u4e49\u597d\u63a5\u53e3\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u89e3\u7801 GIF \u56fe\u7247\u4e86\u3002\u5f00\u59cb\u89e3\u7801 GIF \u56fe\u7247\u65f6\uff0c\u901a\u8fc7 gd_open_gif \u51fd\u6570\u6253\u5f00 GIF \u56fe\u7247\u3002GIF \u56fe\u7247\u5206\u6709\u5e26\u900f\u660e\u5ea6\u5427\u4e0d\u5e26\u900f\u660e\u5ea6\u4e24\u79cd\u7c7b\u578b\uff0c\u5982\u679c\u662f\u5e26\u900f\u660e\u5ea6\u7684\uff0c\u90a3\u4e48\u9700\u8981\u63d0\u524d\u5c06 GIF \u663e\u793a\u533a\u57df\u7684\u50cf\u7d20\u70b9\u6570\u636e\u4fdd\u5b58\u4e0b\u6765\uff0c\u65b9\u4fbf\u89e3\u7801\u65f6\u56de\u586b\u80cc\u666f\u6570\u636e\u3002\u540c\u65f6\uff0c\u4e00\u6bb5 GIF \u56fe\u50cf\u53ef\u4ee5\u91cd\u590d\u663e\u793a\u591a\u6b21\uff0c\u5982\u679c\u8bfb\u8005\u53ea\u9700\u8981\u663e\u793a\u4e00\u904d\uff0c\u90a3\u4e48\u53ef\u4ee5\u53bb\u6389\u89e3\u7801\u90e8\u5206\u6700\u5916\u8fb9\u7684\u90a3\u4e2a\u5faa\u73af\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">\/*********************************************************************************************************\n* \u51fd\u6570\u540d\u79f0\uff1a main\n* \u51fd\u6570\u529f\u80fd\uff1a \u4e3b\u51fd\u6570\n* \u8f93\u5165\u53c2\u6570\uff1a void\n* \u8f93\u51fa\u53c2\u6570\uff1a void\n* \u8fd4 \u56de \u503c\uff1a void\n* \u521b\u5efa\u65e5\u671f\uff1a 2023\u5e7403\u670810\u65e5\n* \u6ce8    \u610f\uff1a \u57fa\u4e8e EasyX \u56fe\u5f62\u5e93\n*********************************************************************************************************\/\nint main(void)\n{\n  static gd_GIF s_structGIF;\n  int xoff, yoff;\n\n  \/\/\u521d\u59cb\u5316\n  InitLCD();\n\n  \/\/\u8bbe\u5b9a\u7528\u6237\u53c2\u6570\n  extern const unsigned char g_arrGifImage3[17083];\n  static StructGIFParam s_structGIFParam;\n  s_structGIFParam.buf = g_arrGifImage3;\n  s_structGIFParam.readCnt = 0;\n  s_structGIFParam.totalSize = sizeof(g_arrGifImage3);\n\n  \/\/\u89e3\u6790\u6587\u4ef6\n  if (0 != gd_open_gif(&amp;s_structGIF, &amp;s_structGIFParam, GIFRead, GIFLseek))\n  {\n    return -1;\n  }\n\n  \/\/\u8ba1\u7b97\u8d77\u59cb\u5750\u6807\u504f\u79fb\u91cf\uff0c\u4f7f\u5f97 GIF \u663e\u793a\u5230\u5c4f\u5e55\u6b63\u4e2d\u592e\uff08\u5c4f\u5e55\u5c3a\u5bf8\uff1a800x480\uff09\n  xoff = (800 - s_structGIF.width) \/ 2;\n  yoff = (480 - s_structGIF.height) \/ 2;\n\n  \/\/\u4e3a\u4e00\u5e27\u56fe\u50cf\u5206\u914d\u52a8\u6001\u5185\u5b58\n  unsigned char* buffer = malloc(s_structGIF.width * s_structGIF.height * 3);\n  unsigned short* background = malloc(s_structGIF.width * s_structGIF.height * sizeof(unsigned short));\n  if ((NULL == buffer) || (NULL == background))\n  {\n    printf(\"Fail to malloc\\r\\n\");\n    while (1) {}\n  }\n\n  \/\/\u4fdd\u5b58\u80cc\u666f\n  for (int y = 0; y &lt; s_structGIF.height; y++)\n  {\n    for (int x = 0; x &lt; s_structGIF.width; x++)\n    {\n      background[y * s_structGIF.width + x] = LCDReadPoint(x + xoff, y + yoff);\n    }\n  }\n\n  \/\/\u89e3\u7801\u5e76\u663e\u793a\n  for (unsigned looped = 1;; looped++) \n  {\n    \/\/\u83b7\u53d6 1 \u5e27\u56fe\u50cf\n    while (gd_get_frame(&amp;s_structGIF))\n    {\n      \/\/\u89e3\u7801\n      gd_render_frame(&amp;s_structGIF, buffer);\n      \n      \/\/\u5e26\u900f\u660e\u5ea6\u5904\u7406\n      if (s_structGIF.gce.transparency)\n      {\n        char* color = buffer;\n        for (int y = 0; y &lt; s_structGIF.height; y++)\n        {\n          for (int x = 0; x &lt; s_structGIF.width; x++)\n          {\n            if (gd_is_bgcolor(&amp;s_structGIF, color))\n            {\n              LCDFastDrawPoint(x + xoff, y + yoff, background[y * s_structGIF.width + x]);\n            }\n            else\n            {\n              LCDFastDrawPoint(x + xoff, y + yoff, GifGetRgb565(color));\n            }\n            color += 3;\n          }\n        }\n      }\n\n      \/\/\u4e0d\u5e26\u900f\u660e\u5ea6\u5904\u7406\n      else\n      {\n        char* color = buffer;\n        for (int y = 0; y &lt; s_structGIF.height; y++)\n        {\n          for (int x = 0; x &lt; s_structGIF.width; x++)\n          {\n            LCDFastDrawPoint(x + xoff, y + yoff, GifGetRgb565(color));\n            color += 3;\n          }\n        }\n      }\n\n      \/\/\u5ef6\u65f6\n      Sleep(s_structGIF.gce.delay * 10);\n    }\n\n    \/\/\u8fbe\u5230\u4e86\u9884\u5b9a\u7684\u64ad\u653e\u6b21\u6570\n    if ((looped >= s_structGIF.loop_count) &amp;&amp; (0 != s_structGIF.loop_count))\n    {\n      break;\n    }\n\n    \/\/\u4ece\u5934\u5f00\u59cb\u663e\u793a\n    gd_rewind(&amp;s_structGIF);\n  }\n  free(buffer);\n  free(background);\n\n  \/\/\u4e3b\u5faa\u73af\n  while (1)\n  {\n    \/\/\u5ef6\u65f6 25ms\n    Sleep(25);\n  }\n  \n  return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%9E%E9%AA%8C%E7%BB%93%E6%9E%9C\"><\/span>\u5b9e\u9a8c\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5b9e\u9a8c\u7ed3\u679c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"793\" height=\"507\" src=\"http:\/\/www.huangrongzhen.ink\/wp-content\/uploads\/2023\/04\/\u5355\u7247\u673a-GUI-\u8bbe\u8ba1\uff08\u4e8c\u5341\uff09-GIF-\u663e\u793a-\u5b9e\u9a8c\u7ed3\u679c-20230403.gif\" alt=\"\" class=\"wp-image-1343\"\/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%BA%90%E7%A0%81\"><\/span>\u6e90\u7801<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u672c\u7ae0\u8282\u4e2d\u7684\u6e90\u7801\u8bf7\u53c2\u8003\u300a<em><a href=\"http:\/\/www.huangrongzhen.ink\/?p=451\">\u5355\u7247\u673a GUI \u8bbe\u8ba1\uff08\u96f6\uff09- \u5927\u7eb2<\/a><\/em>\u300b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e GD32F303ZET6 \u82f9\u679c\u6d3e\u5f00\u53d1\u677f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/1330"}],"collection":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1330"}],"version-history":[{"count":19,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/1330\/revisions"}],"predecessor-version":[{"id":1356,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=\/wp\/v2\/posts\/1330\/revisions\/1356"}],"wp:attachment":[{"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.huangrongzhen.ink\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}