搜索
bottom↓
回复: 10

分享使用tkm32解码gif例子,但是速度慢,有没有更好的库推荐

[复制链接]

出0入0汤圆

发表于 2021-2-21 16:44:35 | 显示全部楼层 |阅读模式
本帖最后由 QbJacky 于 2021-2-21 17:00 编辑

我用 tkm32f499 解码 gif
将gif 文件 载入内存了,
解码
每秒才解码一帧出来,有没有更好的解码的gif 库
11.gif
微信图片_20210221165045.jpg

每一帧 要 1000ms
time:1029
time:1028
time:1012
time:1006
time:1010
time:1024
time:1021
time:1019
time:1022
time:1046
time:996
time:967
time:969
time:944
time:935
time:920
time:915
reset file

解码库 源码如下
调用代码如下
  1. void DemoTask(void *pdata)
  2. {
  3.         INT32U time,i;
  4.         INT8U err;
  5.         gd_GIF *pGif;
  6.         OS_CPU_SysTickInit();
  7.         RgbLcdInit();
  8.         SDIO_Init();
  9.         InitRamFileSystem((const char**)ramfiletab,GetItemSum(ramfiletab));
  10.         pGif=gd_open_gif(ramfiletab[10]);
  11.         if(pGif!=NULL)
  12.                 printf("w:%d h:%d\r\n",pGif->width,pGif->height);
  13.         else
  14.                 printf("can not open\r\n");
  15.         OSTimeDly(OS_TICK_PER_SEC/10);
  16.         for(i=0;i<LcdBufSize;i++)
  17.         {
  18.                 LcdBuffer[i]=0xFFFF;
  19.                 LcdBuffer[i+LcdBufSize]=0xFF00;
  20.         }
  21.         do{
  22.                 time=OSTimeGet();
  23.                 if(gd_get_frame(pGif)!=0)
  24.                 {
  25.                         int x,y;
  26.                         INT8U *scrbuf,*disppt=pGif->canvas;
  27.                         gd_render_frame(pGif,dispram);
  28.                         for(y=0;y<pGif->height;y++)
  29.                         {
  30.                                 scrbuf=(INT8U*)&LcdBuffer[y*XSIZE_PHYS];
  31.                                 for(x=0;x<pGif->width;x++)
  32.                                 {
  33.                                         memcpy(scrbuf,disppt,3);
  34.                                         scrbuf+=4;disppt+=3;
  35.                                 }
  36.                         }
  37.                         printf("time:%d\r\n",OSTimeGet()-time);
  38.                 }
  39.                 else
  40.                 {
  41.                         gd_rewind(pGif);
  42.                         printf("reset file\r\n");
  43.                 }
  44.                 OSTimeDly(OS_TICK_PER_SEC/10);
  45.         }while(1);
  46. }
复制代码

  1. #include "includes.h"
  2. #include "gifdec.h"

  3. #define MIN(A, B) ((A) < (B) ? (A) : (B))
  4. #define MAX(A, B) ((A) > (B) ? (A) : (B))

  5. typedef struct Entry {
  6.     uint16_t length;
  7.     uint16_t prefix;
  8.     uint8_t  suffix;
  9. } Entry;

  10. typedef struct Table {
  11.     int bulk;
  12.     int nentries;
  13.     Entry *entries;
  14. } Table;

  15. static uint16_t read_num(int fd)
  16. {
  17.     uint8_t bytes[2];
  18.     read(fd, bytes, 2);
  19.     return bytes[0] + (((uint16_t) bytes[1]) << 8);
  20. }

  21. gd_GIF my_gif;

  22. gd_GIF *gd_open_gif(const char *fname)
  23. {
  24.     int fd;
  25.     uint8_t sigver[3];
  26.     uint16_t width, height, depth;
  27.     uint8_t fdsz, bgidx, aspect;
  28.     int i;
  29.     uint8_t *bgcolor;
  30.     int gct_sz;
  31.     gd_GIF *gif;

  32.     fd = open(fname, O_RDONLY);
  33.     if (fd == -1) return NULL;
  34. #ifdef _WIN32
  35.     setmode(fd, O_BINARY);
  36. #endif
  37.     /* Header */
  38.     read(fd, sigver, 3);
  39.     if (memcmp(sigver, "GIF", 3) != 0) {
  40. //        fprintf(stderr, "invalid signature\n");
  41.         goto fail;
  42.     }
  43.     /* Version */
  44.     read(fd, sigver, 3);
  45.     if (memcmp(sigver, "89a", 3) != 0) {
  46. //        fprintf(stderr, "invalid version\n");
  47.         goto fail;
  48.     }
  49.     /* Width x Height */
  50.     width  = read_num(fd);
  51.     height = read_num(fd);
  52.     /* FDSZ */
  53.     read(fd, &fdsz, 1);
  54.     /* Presence of GCT */
  55.     if (!(fdsz & 0x80)) {
  56. //        fprintf(stderr, "no global color table\n");
  57.         goto fail;
  58.     }
  59.     /* Color Space's Depth */
  60.     depth = ((fdsz >> 4) & 7) + 1;
  61.     /* Ignore Sort Flag. */
  62.     /* GCT Size */
  63.     gct_sz = 1 << ((fdsz & 0x07) + 1);
  64.     /* Background Color Index */
  65.     read(fd, &bgidx, 1);
  66.     /* Aspect Ratio */
  67.     read(fd, &aspect, 1);
  68.     /* Create gd_GIF Structure. */
  69.     //gif = calloc(1, sizeof(*gif) + 4 * width * height);
  70.     //if (!gif) goto fail;
  71.     gif=&my_gif;
  72.     gif->fd = fd;
  73.     gif->width  = width;
  74.     gif->height = height;
  75.     gif->depth  = depth;
  76.     /* Read GCT */
  77.     gif->gct.size = gct_sz;
  78.     read(fd, gif->gct.colors, 3 * gif->gct.size);
  79.     gif->palette = &gif->gct;
  80.     gif->bgindex = bgidx;
  81.     //gif->canvas = (uint8_t *) &gif[1];
  82.     //gif->frame = &gif->canvas[3 * width * height];
  83.     if (gif->bgindex)
  84.         memset(gif->frame, gif->bgindex, gif->width * gif->height);
  85.     bgcolor = &gif->palette->colors[gif->bgindex*3];
  86.     if (bgcolor[0] || bgcolor[1] || bgcolor [2])
  87.         for (i = 0; i < gif->width * gif->height; i++)
  88.             memcpy(&gif->canvas[i*3], bgcolor, 3);
  89.     gif->anim_start = lseek(fd, 0, SEEK_CUR);
  90.     goto ok;
  91. fail:
  92.     close(fd);
  93. ok:
  94.     return gif;
  95. }

  96. static void discard_sub_block(gd_GIF *gif)
  97. {
  98.     uint8_t size;
  99.     do {
  100.         read(gif->fd, &size, 1);
  101.                 if(size)        lseek(gif->fd, size, SEEK_CUR);
  102.     } while (size);
  103. }

  104. static void
  105. read_plain_text_ext(gd_GIF *gif)
  106. {
  107. //    if (gif->plain_text) {
  108. //        uint16_t tx, ty, tw, th;
  109. //        uint8_t cw, ch, fg, bg;
  110. //        off_t sub_block;
  111. //        lseek(gif->fd, 1, SEEK_CUR); /* block size = 12 */
  112. //        tx = read_num(gif->fd);
  113. //        ty = read_num(gif->fd);
  114. //        tw = read_num(gif->fd);
  115. //        th = read_num(gif->fd);
  116. //        read(gif->fd, &cw, 1);
  117. //        read(gif->fd, &ch, 1);
  118. //        read(gif->fd, &fg, 1);
  119. //        read(gif->fd, &bg, 1);
  120. //        sub_block = lseek(gif->fd, 0, SEEK_CUR);
  121. //        gif->plain_text(gif, tx, ty, tw, th, cw, ch, fg, bg);
  122. //        lseek(gif->fd, sub_block, SEEK_SET);
  123. //    } else
  124.         {
  125.         /* Discard plain text metadata. */
  126.         lseek(gif->fd, 13, SEEK_CUR);
  127.     }
  128.     /* Discard plain text sub-block. */
  129.     discard_sub_block(gif);
  130. }

  131. static void
  132. read_graphic_control_ext(gd_GIF *gif)
  133. {
  134.     uint8_t rdit;
  135.     /* Discard block size (always 0x04). */
  136.     lseek(gif->fd, 1, SEEK_CUR);
  137.     read(gif->fd, &rdit, 1);
  138.     gif->gce.disposal = (rdit >> 2) & 3;
  139.     gif->gce.input = rdit & 2;
  140.     gif->gce.transparency = rdit & 1;
  141.     gif->gce.delay = read_num(gif->fd);
  142.     read(gif->fd, &gif->gce.tindex, 1);
  143.     /* Skip block terminator. */
  144.     lseek(gif->fd, 1, SEEK_CUR);
  145. }

  146. static void
  147. read_comment_ext(gd_GIF *gif)
  148. {
  149. //    if (gif->comment) {
  150. //        off_t sub_block = lseek(gif->fd, 0, SEEK_CUR);
  151. //        gif->comment(gif);
  152. //        lseek(gif->fd, sub_block, SEEK_SET);
  153. //    }
  154.     /* Discard comment sub-block. */
  155.     discard_sub_block(gif);
  156. }

  157. static void
  158. read_application_ext(gd_GIF *gif)
  159. {
  160.     char app_id[8];
  161.     char app_auth_code[3];
  162.     /* Discard block size (always 0x0B). */
  163.     lseek(gif->fd, 1, SEEK_CUR);
  164.     /* Application Identifier. */
  165.     read(gif->fd, app_id, 8);
  166.     /* Application Authentication Code. */
  167.     read(gif->fd, app_auth_code, 3);
  168.     if (!strncmp(app_id, "NETSCAPE", sizeof(app_id))) {
  169.         /* Discard block size (0x03) and constant byte (0x01). */
  170.         lseek(gif->fd, 2, SEEK_CUR);
  171.         gif->loop_count = read_num(gif->fd);
  172.         /* Skip block terminator. */
  173.         lseek(gif->fd, 1, SEEK_CUR);
  174.     } else if (gif->application) {
  175.         off_t sub_block = lseek(gif->fd, 0, SEEK_CUR);
  176.         gif->application(gif, app_id, app_auth_code);
  177.         lseek(gif->fd, sub_block, SEEK_SET);
  178.         discard_sub_block(gif);
  179.     } else {
  180.         discard_sub_block(gif);
  181.     }
  182. }

  183. static void read_ext(gd_GIF *gif)
  184. {
  185.     uint8_t label;

  186.     read(gif->fd, &label, 1);
  187.     switch (label) {
  188.     case 0x01:
  189.         read_plain_text_ext(gif);
  190.         break;
  191.     case 0xF9:
  192.         read_graphic_control_ext(gif);
  193.         break;
  194.     case 0xFE:
  195.         read_comment_ext(gif);
  196.         break;
  197.     case 0xFF:
  198.         read_application_ext(gif);
  199.         break;
  200.     default:
  201.         //fprintf(stderr, "unknown extension: %02X\n", label);
  202.                 break;
  203.     }
  204. }

  205. static Table *new_table(int key_size,u8 *tab)
  206. {
  207.     int key;
  208.     int init_bulk = MAX(1 << (key_size + 1), 0x100);
  209. //    Table *table = malloc(sizeof(*table) + sizeof(Entry) * init_bulk);
  210. //    if (table) {
  211. //        table->bulk = init_bulk;
  212. //        table->nentries = (1 << key_size) + 2;
  213. //        table->entries = (Entry *) &table[1];
  214. //        for (key = 0; key < (1 << key_size); key++)
  215. //            table->entries[key] = (Entry) {1, 0xFFF, key};
  216. //    }
  217. //    return table;
  218.                 //保证字节对齐
  219.     Table *table;                                                                 //malloc(sizeof(*table) + sizeof(Entry) * init_bulk);
  220.         tab+=(4-(((INT32U)tab)&3))%4;
  221.         table =(Table *)tab;
  222.     if (table) {
  223.         table->bulk = init_bulk;
  224.         table->nentries = (1 << key_size) + 2;
  225.         table->entries = (Entry *) &table[1];
  226.         for (key = 0; key < (1 << key_size); key++)
  227.         {
  228.                         table->entries[key].length =1;       
  229.                         table->entries[key].prefix=0xfff;
  230.                         table->entries[key].suffix=key;
  231.         }
  232.     }
  233.     return table;       
  234. }

  235. /* Add table entry. Return value:
  236. *  0 on success
  237. *  +1 if key size must be incremented after this addition
  238. *  -1 if could not realloc table */
  239. static int
  240. add_entry(Table **tablep, uint16_t length, uint16_t prefix, uint8_t suffix)
  241. {
  242.     Table *table = *tablep;
  243.     if (table->nentries == table->bulk) {
  244.         table->bulk *= 2;
  245. //        table = realloc(table, sizeof(*table) + sizeof(Entry) * table->bulk);
  246. //        if (!table) return -1;
  247. //        table->entries = (Entry *) &table[1];
  248. //        *tablep = table;
  249.     }
  250. //    table->entries[table->nentries] = (Entry) {length, prefix, suffix};
  251.         table->entries[table->nentries].length=length;
  252.         table->entries[table->nentries].prefix=prefix;
  253.         table->entries[table->nentries].suffix=suffix;
  254.     table->nentries++;
  255.     if ((table->nentries & (table->nentries - 1)) == 0)
  256.         return 1;
  257.     return 0;
  258. }

  259. static uint16_t
  260. get_key(gd_GIF *gif, int key_size, uint8_t *sub_len, uint8_t *shift, uint8_t *byte)
  261. {
  262.     int bits_read;
  263.     int rpad;
  264.     int frag_size;
  265.     uint16_t key;

  266.     key = 0;
  267.     for (bits_read = 0; bits_read < key_size; bits_read += frag_size) {
  268.         rpad = (*shift + bits_read) % 8;
  269.         if (rpad == 0) {
  270.             /* Update byte. */
  271.             if (*sub_len == 0)
  272.                 read(gif->fd, sub_len, 1); /* Must be nonzero! */
  273.             read(gif->fd, byte, 1);
  274.             (*sub_len)--;
  275.         }
  276.         frag_size = MIN(key_size - bits_read, 8 - rpad);
  277.         key |= ((uint16_t) ((*byte) >> rpad)) << bits_read;
  278.     }
  279.     /* Clear extra bits to the left. */
  280.     key &= (1 << key_size) - 1;
  281.     *shift = (*shift + key_size) % 8;
  282.     return key;
  283. }

  284. /* Compute output index of y-th input line, in frame of height h. */
  285. static int
  286. interlaced_line_index(int h, int y)
  287. {
  288.     int p; /* number of lines in current pass */

  289.     p = (h - 1) / 8 + 1;
  290.     if (y < p) /* pass 1 */
  291.         return y * 8;
  292.     y -= p;
  293.     p = (h - 5) / 8 + 1;
  294.     if (y < p) /* pass 2 */
  295.         return y * 8 + 4;
  296.     y -= p;
  297.     p = (h - 3) / 4 + 1;
  298.     if (y < p) /* pass 3 */
  299.         return y * 4 + 2;
  300.     y -= p;
  301.     /* pass 4 */
  302.     return y * 2 + 1;
  303. }

  304. /* Decompress image pixels.
  305. * Return 0 on success or -1 on out-of-memory (w.r.t. LZW code table). */
  306. static int
  307. read_image_data(gd_GIF *gif, int interlace)
  308. {
  309.     uint8_t sub_len, shift, byte;
  310.     int init_key_size, key_size, table_is_full;
  311.     int frm_off, str_len, p, x, y;
  312.     uint16_t key, clear, stop;
  313.     int ret;
  314.     Table *table;
  315.     Entry entry;
  316.     off_t start, end;

  317.     read(gif->fd, &byte, 1);
  318.     key_size = (int) byte;
  319.     start = lseek(gif->fd, 0, SEEK_CUR);
  320.     discard_sub_block(gif);
  321.     end = lseek(gif->fd, 0, SEEK_CUR);
  322.     lseek(gif->fd, start, SEEK_SET);
  323.     clear = 1 << key_size;
  324.     stop = clear + 1;
  325.     table = new_table(key_size,gif->table);
  326.     key_size++;
  327.     init_key_size = key_size;
  328.     sub_len = shift = 0;
  329.     key = get_key(gif, key_size, &sub_len, &shift, &byte); /* clear code */
  330.     frm_off = 0;
  331.     ret = 0;
  332.     while (1) {
  333.         if (key == clear) {
  334.             key_size = init_key_size;
  335.             table->nentries = (1 << (key_size - 1)) + 2;
  336.             table_is_full = 0;
  337.         } else if (!table_is_full) {
  338.             ret = add_entry(&table, str_len + 1, key, entry.suffix);
  339.             if (ret == -1) {
  340.                 //free(table);
  341.                 return -1;
  342.             }
  343.             if (table->nentries == 0x1000) {
  344.                 ret = 0;
  345.                 table_is_full = 1;
  346.             }
  347.         }
  348.         key = get_key(gif, key_size, &sub_len, &shift, &byte);
  349.         if (key == clear) continue;
  350.         if (key == stop) break;
  351.         if (ret == 1) key_size++;
  352.         entry = table->entries[key];
  353.         str_len = entry.length;
  354.         while (1) {
  355.             p = frm_off + entry.length - 1;
  356.             x = p % gif->fw;
  357.             y = p / gif->fw;
  358.             if (interlace)
  359.                 y = interlaced_line_index((int) gif->fh, y);
  360.             gif->frame[(gif->fy + y) * gif->width + gif->fx + x] = entry.suffix;
  361.             if (entry.prefix == 0xFFF)
  362.                 break;
  363.             else
  364.                 entry = table->entries[entry.prefix];
  365.         }
  366.         frm_off += str_len;
  367.         if (key < table->nentries - 1 && !table_is_full)
  368.             table->entries[table->nentries - 1].suffix = entry.suffix;
  369.     }
  370.     //free(table);
  371.     read(gif->fd, &sub_len, 1); /* Must be zero! */
  372.     lseek(gif->fd, end, SEEK_SET);
  373.     return 0;
  374. }

  375. /* Read image.
  376. * Return 0 on success or -1 on out-of-memory (w.r.t. LZW code table). */
  377. static int
  378. read_image(gd_GIF *gif)
  379. {
  380.     uint8_t fisrz;
  381.     int interlace;

  382.     /* Image Descriptor. */
  383.     gif->fx = read_num(gif->fd);
  384.     gif->fy = read_num(gif->fd);
  385.     gif->fw = read_num(gif->fd);
  386.     gif->fh = read_num(gif->fd);
  387.     read(gif->fd, &fisrz, 1);
  388.     interlace = fisrz & 0x40;
  389.     /* Ignore Sort Flag. */
  390.     /* Local Color Table? */
  391.     if (fisrz & 0x80) {
  392.         /* Read LCT */
  393.         gif->lct.size = 1 << ((fisrz & 0x07) + 1);
  394.         read(gif->fd, gif->lct.colors, 3 * gif->lct.size);
  395.         gif->palette = &gif->lct;
  396.     } else
  397.         gif->palette = &gif->gct;
  398.     /* Image Data. */
  399.     return read_image_data(gif, interlace);
  400. }

  401. static void render_frame_rect(gd_GIF *gif, uint8_t *buffer)
  402. {
  403.     int i, j, k;
  404.     uint8_t index, *color;
  405.     i = gif->fy * gif->width + gif->fx;
  406.     for (j = 0; j < gif->fh; j++) {
  407.         for (k = 0; k < gif->fw; k++) {
  408.             index = gif->frame[(gif->fy + j) * gif->width + gif->fx + k];
  409.             color = &gif->palette->colors[index*3];
  410.             if (!gif->gce.transparency || index != gif->gce.tindex)
  411.                 memcpy(&buffer[(i+k)*3], color, 3);
  412.         }
  413.         i += gif->width;
  414.     }
  415. }

  416. static void dispose(gd_GIF *gif)
  417. {
  418.     int i, j, k;
  419.     uint8_t *bgcolor;
  420.         //printf("gif->gce.disposal=%d\r\n",gif->gce.disposal);
  421.     switch (gif->gce.disposal) {
  422.     case 2: /* Restore to background color. */
  423.         bgcolor = &gif->palette->colors[gif->bgindex*3];
  424.         i = gif->fy * gif->width + gif->fx;
  425.         for (j = 0; j < gif->fh; j++) {
  426.             for (k = 0; k < gif->fw; k++)
  427.                 memcpy(&gif->canvas[(i+k)*3], bgcolor, 3);
  428.             i += gif->width;
  429.         }
  430.         break;
  431.     case 3: /* Restore to previous, i.e., don't update canvas.*/
  432.         break;
  433.     default:
  434.         /* Add frame non-transparent pixels to canvas. */
  435.         render_frame_rect(gif, gif->canvas);
  436.     }
  437. }

  438. /* Return 1 if got a frame; 0 if got GIF trailer; -1 if error. */
  439. int gd_get_frame(gd_GIF *gif)
  440. {
  441.     char sep;
  442.     dispose(gif);
  443.     read(gif->fd, &sep, 1);
  444.     while (sep != ',') {
  445.         if (sep == ';')
  446.             return 0;
  447.         if (sep == '!')
  448.             read_ext(gif);
  449.         else return -1;
  450.         read(gif->fd, &sep, 1);
  451.     }
  452.     if (read_image(gif) == -1)
  453.         return -1;
  454.     return 1;
  455. }

  456. void gd_render_frame(gd_GIF *gif, uint8_t *buffer)
  457. {
  458.     render_frame_rect(gif,gif->canvas);
  459.     //memcpy(buffer, gif->canvas, gif->width * gif->height * 3);
  460.     //render_frame_rect(gif, buffer);
  461. }

  462. int
  463. gd_is_bgcolor(gd_GIF *gif, uint8_t color[3])
  464. {
  465.     return !memcmp(&gif->palette->colors[gif->bgindex*3], color, 3);
  466. }

  467. void gd_rewind(gd_GIF *gif)
  468. {
  469.         int i;
  470.     uint8_t *bgcolor;
  471.     lseek(gif->fd, gif->anim_start, SEEK_SET);
  472.     if (gif->bgindex)
  473.         memset(gif->frame, gif->bgindex, gif->width * gif->height);
  474.     bgcolor = &gif->palette->colors[gif->bgindex*3];
  475.     if (bgcolor[0] || bgcolor[1] || bgcolor [2])
  476.         for (i = 0; i < gif->width * gif->height; i++)
  477.             memcpy(&gif->canvas[i*3], bgcolor, 3);       
  478. }

  479. void
  480. gd_close_gif(gd_GIF *gif)
  481. {
  482.     close(gif->fd);
  483.     //free(gif);
  484. }
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出16170入6148汤圆

发表于 2021-2-21 16:47:58 来自手机 | 显示全部楼层
“tkm解码 gif”标题不合格。请自行修改。

帖子标题必须能充分说明帖子的内容。如你要问AVR的ADC如何才能测量得比较准确,“AVR的ADC如何消除干扰测量得比较准确?”是合格的标题。不合格举例:
    1:小女子冰天雪地裸体跪求解决方法
    2:救命啊...
    3:高手请出招,一个无法解决的AVR问题
    4:一个困扰学习单片机初学者,惊动单片机开发者的难题
    5:AVR的ADC测量   (点评:你到底是问问题,或是有技术心得与大家分享?)

出0入442汤圆

发表于 2021-2-21 17:39:50 来自手机 | 显示全部楼层
我晕,你用file去访问不卡才怪了。应该先把gif整个载入内存,然后直接走pointer访问,同时编译器开os优化。

出0入0汤圆

 楼主| 发表于 2021-2-21 17:40:56 | 显示全部楼层
本帖最后由 QbJacky 于 2021-2-21 17:42 编辑
wye11083 发表于 2021-2-21 17:39
我晕,你用file去访问不卡才怪了。应该先把gif整个载入内存,然后直接走pointer访问,同时编译器开os优化。 ...


我已经使用 在内存里面 操作的了 ,所有gif 都载入到 内存中,然后在内存解码,read 我是指向内存的,只是为了 兼容原来库的函数,写了一个内存对应的操作

出0入0汤圆

发表于 2021-2-21 17:52:33 | 显示全部楼层
LZW解压缩还有 交叉算法,本来就费cpu,能不能每帧提前转成bitmap,需要的时候定时刷屏就行了呢

出0入442汤圆

发表于 2021-2-21 20:54:54 来自手机 | 显示全部楼层
QbJacky 发表于 2021-2-21 17:40
我已经使用 在内存里面 操作的了 ,所有gif 都载入到 内存中,然后在内存解码,read 我是指向内存的,只是为 ...

我指你file操作!需要全部转成数组操作。还有干吗要生成rgb再拷一次?直接生成argb不好吗?可优化的地方多了,你先在pc上把所有性能瓶颈都优化掉再移植吧。否则就写进去bitmap,这是最保险的。

出0入0汤圆

 楼主| 发表于 2021-2-21 22:14:14 | 显示全部楼层
本帖最后由 QbJacky 于 2021-2-21 22:20 编辑
gwnpeter 发表于 2021-2-21 17:52
LZW解压缩还有 交叉算法,本来就费cpu,能不能每帧提前转成bitmap,需要的时候定时刷屏就行了呢 ...


帧数多的话 不压缩 只能存 sd卡,但是 读取sd卡的速度也不快啊 好像只有0.5M 每秒,64K的图片
我的图片是 256*64 的  如果使用 要是提前转argb  就要 64K 一帧  10帧/秒    内存也就能放10秒而已 不够用

//读取文件的 大小size 和时间 time 千分之一秒
fn:0:gif/0.gif size:4102 time:9
fn:0:gif/1.gif size:19008 time:36
fn:0:gif/2.gif size:9871 time:20
fn:0:gif/3.gif size:3575 time:7
fn:0:gif/4.gif size:5655 time:12
fn:0:gif/5.gif size:11751 time:25
fn:0:gif/6.gif size:24534 time:46
fn:0:gif/7.gif size:7762 time:16
fn:0:gif/8.gif size:11122 time:22
fn:0:gif/9.gif size:16443 time:31
fn:0:gif/10.gif size:1167569 time:2258

出0入0汤圆

 楼主| 发表于 2021-2-21 23:07:49 | 显示全部楼层
wye11083 发表于 2021-2-21 20:54
我指你file操作!需要全部转成数组操作。还有干吗要生成rgb再拷一次?直接生成argb不好吗?可优化的地方 ...

尝试一下 先释放出每一帧 放入 w25Q32 里面 再读取来试试
SD卡的操作速度太慢,不知道是卡的问题 还是 sdio 的速度 导致

出0入442汤圆

发表于 2021-2-22 00:15:10 来自手机 | 显示全部楼层
QbJacky 发表于 2021-2-21 23:07
尝试一下 先释放出每一帧 放入 w25Q32 里面 再读取来试试
SD卡的操作速度太慢,不知道是卡的问题 还是 sd ...

看看是不是模拟sdio,那样肯定不行。spi如果不是qspi也不行。普通spi最快也就4mb速度。

出0入0汤圆

 楼主| 发表于 2021-2-22 08:26:49 | 显示全部楼层
wye11083 发表于 2021-2-22 00:15
看看是不是模拟sdio,那样肯定不行。spi如果不是qspi也不行。普通spi最快也就4mb速度。 ...

调用不了dma,和 多 block 读取也不成功
只能 单 block 读取
然后 感觉速度 好慢

打算使用 w25Qxx 作为存储了 这个在 tkm32f499 的例程里面 速度还是可以的

出0入0汤圆

 楼主| 发表于 2021-2-22 11:06:02 | 显示全部楼层
Gif2Bmp.rar (64.01 KB)
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-3-29 16:43

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表