MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / decode_entropy_coded_image

Function decode_entropy_coded_image

libavcodec/webp.c:552–756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550}
551
552static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role,
553 int w, int h)
554{
555 ImageContext *img;
556 HuffReader *hg;
557 int i, j, ret, x, y, width;
558
559 img = &s->image[role];
560 img->role = role;
561
562 if (!img->frame) {
563 img->frame = av_frame_alloc();
564 if (!img->frame)
565 return AVERROR(ENOMEM);
566 }
567
568 img->frame->format = AV_PIX_FMT_ARGB;
569 img->frame->width = w;
570 img->frame->height = h;
571
572 if (role == IMAGE_ROLE_ARGB && !img->is_alpha_primary) {
573 ret = ff_thread_get_buffer(s->avctx, img->frame, 0);
574 } else
575 ret = av_frame_get_buffer(img->frame, 1);
576 if (ret < 0)
577 return ret;
578
579 if (get_bits1(&s->gb)) {
580 img->color_cache_bits = get_bits(&s->gb, 4);
581 if (img->color_cache_bits < 1 || img->color_cache_bits > 11) {
582 av_log(s->avctx, AV_LOG_ERROR, "invalid color cache bits: %d\n",
583 img->color_cache_bits);
584 return AVERROR_INVALIDDATA;
585 }
586 img->color_cache = av_calloc(1 << img->color_cache_bits,
587 sizeof(*img->color_cache));
588 if (!img->color_cache)
589 return AVERROR(ENOMEM);
590 } else {
591 img->color_cache_bits = 0;
592 }
593
594 img->nb_huffman_groups = 1;
595 if (role == IMAGE_ROLE_ARGB && get_bits1(&s->gb)) {
596 ret = decode_entropy_image(s);
597 if (ret < 0)
598 return ret;
599 img->nb_huffman_groups = s->nb_huffman_groups;
600 }
601 img->huffman_groups = av_calloc(img->nb_huffman_groups,
602 HUFFMAN_CODES_PER_META_CODE *
603 sizeof(*img->huffman_groups));
604 if (!img->huffman_groups)
605 return AVERROR(ENOMEM);
606
607 for (i = 0; i < img->nb_huffman_groups; i++) {
608 hg = &img->huffman_groups[i * HUFFMAN_CODES_PER_META_CODE];
609 for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; j++) {

Callers 5

decode_entropy_imageFunction · 0.85
parse_transform_colorFunction · 0.85

Calls 14

av_frame_allocFunction · 0.85
av_frame_get_bufferFunction · 0.85
get_bits1Function · 0.85
av_logFunction · 0.85
av_callocFunction · 0.85
decode_entropy_imageFunction · 0.85
read_huffman_code_simpleFunction · 0.85
read_huffman_code_normalFunction · 0.85
get_bits_leftFunction · 0.85
get_huffman_groupFunction · 0.85
huff_reader_get_symbolFunction · 0.85
color_cache_putFunction · 0.85

Tested by

no test coverage detected