Lines Matching refs:gif

26 static gd_GIF *  gif_open(gd_GIF * gif);
27 static bool f_gif_open(gd_GIF * gif, const void * path, bool is_file);
28 static void f_gif_read(gd_GIF * gif, void * buf, size_t len);
29 static int f_gif_seek(gd_GIF * gif, size_t pos, int k);
30 static void f_gif_close(gd_GIF * gif);
33 read_num(gd_GIF * gif) in read_num() argument
37 f_gif_read(gif, bytes, 2); in read_num()
76 gd_GIF *gif = NULL; in gif_open() local
111 gif = lv_mem_alloc(sizeof(gd_GIF) + 5 * width * height); in gif_open()
113 gif = lv_mem_alloc(sizeof(gd_GIF) + 4 * width * height); in gif_open()
115 gif = lv_mem_alloc(sizeof(gd_GIF) + 3 * width * height); in gif_open()
118 if (!gif) goto fail; in gif_open()
119 memcpy(gif, gif_base, sizeof(gd_GIF)); in gif_open()
120 gif->width = width; in gif_open()
121 gif->height = height; in gif_open()
122 gif->depth = depth; in gif_open()
124 gif->gct.size = gct_sz; in gif_open()
125 f_gif_read(gif, gif->gct.colors, 3 * gif->gct.size); in gif_open()
126 gif->palette = &gif->gct; in gif_open()
127 gif->bgindex = bgidx; in gif_open()
128 gif->canvas = (uint8_t *) &gif[1]; in gif_open()
130 gif->frame = &gif->canvas[4 * width * height]; in gif_open()
132 gif->frame = &gif->canvas[3 * width * height]; in gif_open()
134 gif->frame = &gif->canvas[2 * width * height]; in gif_open()
136 if (gif->bgindex) { in gif_open()
137 memset(gif->frame, gif->bgindex, gif->width * gif->height); in gif_open()
139 bgcolor = &gif->palette->colors[gif->bgindex*3]; in gif_open()
141 for (i = 0; i < gif->width * gif->height; i++) { in gif_open()
143 gif->canvas[i*4 + 0] = *(bgcolor + 2); in gif_open()
144 gif->canvas[i*4 + 1] = *(bgcolor + 1); in gif_open()
145 gif->canvas[i*4 + 2] = *(bgcolor + 0); in gif_open()
146 gif->canvas[i*4 + 3] = 0xff; in gif_open()
149 gif->canvas[i*3 + 0] = c.full & 0xff; in gif_open()
150 gif->canvas[i*3 + 1] = (c.full >> 8) & 0xff; in gif_open()
151 gif->canvas[i*3 + 2] = 0xff; in gif_open()
154 gif->canvas[i*2 + 0] = c.full; in gif_open()
155 gif->canvas[i*2 + 1] = 0xff; in gif_open()
158 gif->canvas[i*2 + 0] = c.ch.red > 128 ? 1 : 0; in gif_open()
159 gif->canvas[i*2 + 1] = 0xff; in gif_open()
162 gif->anim_start = f_gif_seek(gif, 0, LV_FS_SEEK_CUR); in gif_open()
163 gif->loop_count = -1; in gif_open()
168 return gif; in gif_open()
172 discard_sub_blocks(gd_GIF *gif) in discard_sub_blocks() argument
177 f_gif_read(gif, &size, 1); in discard_sub_blocks()
178 f_gif_seek(gif, size, LV_FS_SEEK_CUR); in discard_sub_blocks()
183 read_plain_text_ext(gd_GIF *gif) in read_plain_text_ext() argument
185 if (gif->plain_text) { in read_plain_text_ext()
189 f_gif_seek(gif, 1, LV_FS_SEEK_CUR); /* block size = 12 */ in read_plain_text_ext()
190 tx = read_num(gif); in read_plain_text_ext()
191 ty = read_num(gif); in read_plain_text_ext()
192 tw = read_num(gif); in read_plain_text_ext()
193 th = read_num(gif); in read_plain_text_ext()
194 f_gif_read(gif, &cw, 1); in read_plain_text_ext()
195 f_gif_read(gif, &ch, 1); in read_plain_text_ext()
196 f_gif_read(gif, &fg, 1); in read_plain_text_ext()
197 f_gif_read(gif, &bg, 1); in read_plain_text_ext()
198 sub_block = f_gif_seek(gif, 0, LV_FS_SEEK_CUR); in read_plain_text_ext()
199 gif->plain_text(gif, tx, ty, tw, th, cw, ch, fg, bg); in read_plain_text_ext()
200 f_gif_seek(gif, sub_block, LV_FS_SEEK_SET); in read_plain_text_ext()
203 f_gif_seek(gif, 13, LV_FS_SEEK_CUR); in read_plain_text_ext()
206 discard_sub_blocks(gif); in read_plain_text_ext()
210 read_graphic_control_ext(gd_GIF *gif) in read_graphic_control_ext() argument
215 f_gif_seek(gif, 1, LV_FS_SEEK_CUR); in read_graphic_control_ext()
216 f_gif_read(gif, &rdit, 1); in read_graphic_control_ext()
217 gif->gce.disposal = (rdit >> 2) & 3; in read_graphic_control_ext()
218 gif->gce.input = rdit & 2; in read_graphic_control_ext()
219 gif->gce.transparency = rdit & 1; in read_graphic_control_ext()
220 gif->gce.delay = read_num(gif); in read_graphic_control_ext()
221 f_gif_read(gif, &gif->gce.tindex, 1); in read_graphic_control_ext()
223 f_gif_seek(gif, 1, LV_FS_SEEK_CUR); in read_graphic_control_ext()
227 read_comment_ext(gd_GIF *gif) in read_comment_ext() argument
229 if (gif->comment) { in read_comment_ext()
230 size_t sub_block = f_gif_seek(gif, 0, LV_FS_SEEK_CUR); in read_comment_ext()
231 gif->comment(gif); in read_comment_ext()
232 f_gif_seek(gif, sub_block, LV_FS_SEEK_SET); in read_comment_ext()
235 discard_sub_blocks(gif); in read_comment_ext()
239 read_application_ext(gd_GIF *gif) in read_application_ext() argument
246 f_gif_seek(gif, 1, LV_FS_SEEK_CUR); in read_application_ext()
248 f_gif_read(gif, app_id, 8); in read_application_ext()
250 f_gif_read(gif, app_auth_code, 3); in read_application_ext()
253 f_gif_seek(gif, 2, LV_FS_SEEK_CUR); in read_application_ext()
254 loop_count = read_num(gif); in read_application_ext()
255 if(gif->loop_count < 0) { in read_application_ext()
257 gif->loop_count = 0; in read_application_ext()
260 gif->loop_count = loop_count + 1; in read_application_ext()
264 f_gif_seek(gif, 1, LV_FS_SEEK_CUR); in read_application_ext()
265 } else if (gif->application) { in read_application_ext()
266 size_t sub_block = f_gif_seek(gif, 0, LV_FS_SEEK_CUR); in read_application_ext()
267 gif->application(gif, app_id, app_auth_code); in read_application_ext()
268 f_gif_seek(gif, sub_block, LV_FS_SEEK_SET); in read_application_ext()
269 discard_sub_blocks(gif); in read_application_ext()
271 discard_sub_blocks(gif); in read_application_ext()
276 read_ext(gd_GIF *gif) in read_ext() argument
280 f_gif_read(gif, &label, 1); in read_ext()
283 read_plain_text_ext(gif); in read_ext()
286 read_graphic_control_ext(gif); in read_ext()
289 read_comment_ext(gif); in read_ext()
292 read_application_ext(gif); in read_ext()
338 get_key(gd_GIF *gif, int key_size, uint8_t *sub_len, uint8_t *shift, uint8_t *byte) in get_key() argument
351 f_gif_read(gif, sub_len, 1); /* Must be nonzero! */ in get_key()
354 f_gif_read(gif, byte, 1); in get_key()
391 read_image_data(gd_GIF *gif, int interlace) in read_image_data() argument
402 f_gif_read(gif, &byte, 1); in read_image_data()
404 start = f_gif_seek(gif, 0, LV_FS_SEEK_CUR); in read_image_data()
405 discard_sub_blocks(gif); in read_image_data()
406 end = f_gif_seek(gif, 0, LV_FS_SEEK_CUR); in read_image_data()
407 f_gif_seek(gif, start, LV_FS_SEEK_SET); in read_image_data()
414 key = get_key(gif, key_size, &sub_len, &shift, &byte); /* clear code */ in read_image_data()
417 frm_size = gif->fw*gif->fh; in read_image_data()
434 key = get_key(gif, key_size, &sub_len, &shift, &byte); in read_image_data()
442 x = p % gif->fw; in read_image_data()
443 y = p / gif->fw; in read_image_data()
445 y = interlaced_line_index((int) gif->fh, y); in read_image_data()
446 gif->frame[(gif->fy + y) * gif->width + gif->fx + x] = entry.suffix; in read_image_data()
457 if (key == stop) f_gif_read(gif, &sub_len, 1); /* Must be zero! */ in read_image_data()
458 f_gif_seek(gif, end, LV_FS_SEEK_SET); in read_image_data()
465 read_image(gd_GIF *gif) in read_image() argument
471 gif->fx = read_num(gif); in read_image()
472 gif->fy = read_num(gif); in read_image()
473 gif->fw = read_num(gif); in read_image()
474 gif->fh = read_num(gif); in read_image()
475 f_gif_read(gif, &fisrz, 1); in read_image()
481 gif->lct.size = 1 << ((fisrz & 0x07) + 1); in read_image()
482 f_gif_read(gif, gif->lct.colors, 3 * gif->lct.size); in read_image()
483 gif->palette = &gif->lct; in read_image()
485 gif->palette = &gif->gct; in read_image()
487 return read_image_data(gif, interlace); in read_image()
491 render_frame_rect(gd_GIF *gif, uint8_t *buffer) in render_frame_rect() argument
495 i = gif->fy * gif->width + gif->fx; in render_frame_rect()
496 for (j = 0; j < gif->fh; j++) { in render_frame_rect()
497 for (k = 0; k < gif->fw; k++) { in render_frame_rect()
498 index = gif->frame[(gif->fy + j) * gif->width + gif->fx + k]; in render_frame_rect()
499 color = &gif->palette->colors[index*3]; in render_frame_rect()
500 if (!gif->gce.transparency || index != gif->gce.tindex) { in render_frame_rect()
522 i += gif->width; in render_frame_rect()
527 dispose(gd_GIF *gif) in dispose() argument
531 switch (gif->gce.disposal) { in dispose()
533 bgcolor = &gif->palette->colors[gif->bgindex*3]; in dispose()
536 if(gif->gce.transparency) opa = 0x00; in dispose()
538 i = gif->fy * gif->width + gif->fx; in dispose()
539 for (j = 0; j < gif->fh; j++) { in dispose()
540 for (k = 0; k < gif->fw; k++) { in dispose()
542 gif->canvas[(i+k)*4 + 0] = *(bgcolor + 2); in dispose()
543 gif->canvas[(i+k)*4 + 1] = *(bgcolor + 1); in dispose()
544 gif->canvas[(i+k)*4 + 2] = *(bgcolor + 0); in dispose()
545 gif->canvas[(i+k)*4 + 3] = opa; in dispose()
548 gif->canvas[(i+k)*3 + 0] = c.full & 0xff; in dispose()
549 gif->canvas[(i+k)*3 + 1] = (c.full >> 8) & 0xff; in dispose()
550 gif->canvas[(i+k)*3 + 2] = opa; in dispose()
553 gif->canvas[(i+k)*2 + 0] = c.full; in dispose()
554 gif->canvas[(i+k)*2 + 1] = opa; in dispose()
557 gif->canvas[(i+k)*2 + 0] = b > 128 ? 1 : 0; in dispose()
558 gif->canvas[(i+k)*2 + 1] = opa; in dispose()
561 i += gif->width; in dispose()
568 render_frame_rect(gif, gif->canvas); in dispose()
574 gd_get_frame(gd_GIF *gif) in gd_get_frame() argument
578 dispose(gif); in gd_get_frame()
579 f_gif_read(gif, &sep, 1); in gd_get_frame()
582 f_gif_seek(gif, gif->anim_start, LV_FS_SEEK_SET); in gd_get_frame()
583 if(gif->loop_count == 1 || gif->loop_count < 0) { in gd_get_frame()
586 else if(gif->loop_count > 1) { in gd_get_frame()
587 gif->loop_count--; in gd_get_frame()
591 read_ext(gif); in gd_get_frame()
593 f_gif_read(gif, &sep, 1); in gd_get_frame()
595 if (read_image(gif) == -1) in gd_get_frame()
601 gd_render_frame(gd_GIF *gif, uint8_t *buffer) in gd_render_frame() argument
612 render_frame_rect(gif, buffer); in gd_render_frame()
616 gd_rewind(gd_GIF *gif) in gd_rewind() argument
618 gif->loop_count = -1; in gd_rewind()
619 f_gif_seek(gif, gif->anim_start, LV_FS_SEEK_SET); in gd_rewind()
623 gd_close_gif(gd_GIF *gif) in gd_close_gif() argument
625 f_gif_close(gif); in gd_close_gif()
626 lv_mem_free(gif); in gd_close_gif()
629 static bool f_gif_open(gd_GIF * gif, const void * path, bool is_file) in f_gif_open() argument
631 gif->f_rw_p = 0; in f_gif_open()
632 gif->data = NULL; in f_gif_open()
633 gif->is_file = is_file; in f_gif_open()
636 lv_fs_res_t res = lv_fs_open(&gif->fd, path, LV_FS_MODE_RD); in f_gif_open()
640 gif->data = path; in f_gif_open()
645 static void f_gif_read(gd_GIF * gif, void * buf, size_t len) in f_gif_read() argument
647 if(gif->is_file) { in f_gif_read()
648 lv_fs_read(&gif->fd, buf, len, NULL); in f_gif_read()
651 memcpy(buf, &gif->data[gif->f_rw_p], len); in f_gif_read()
652 gif->f_rw_p += len; in f_gif_read()
656 static int f_gif_seek(gd_GIF * gif, size_t pos, int k) in f_gif_seek() argument
658 if(gif->is_file) { in f_gif_seek()
659 lv_fs_seek(&gif->fd, pos, k); in f_gif_seek()
661 lv_fs_tell(&gif->fd, &x); in f_gif_seek()
664 if(k == LV_FS_SEEK_CUR) gif->f_rw_p += pos; in f_gif_seek()
665 else if(k == LV_FS_SEEK_SET) gif->f_rw_p = pos; in f_gif_seek()
666 return gif->f_rw_p; in f_gif_seek()
670 static void f_gif_close(gd_GIF * gif) in f_gif_close() argument
672 if(gif->is_file) { in f_gif_close()
673 lv_fs_close(&gif->fd); in f_gif_close()