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

Function bfi_decode_frame

libavcodec/bfi.c:50–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50static int bfi_decode_frame(AVCodecContext *avctx, AVFrame *frame,
51 int *got_frame, AVPacket *avpkt)
52{
53 GetByteContext g;
54 int buf_size = avpkt->size;
55 BFIContext *bfi = avctx->priv_data;
56 uint8_t *dst = bfi->dst;
57 uint8_t *src, *dst_offset, colour1, colour2;
58 uint8_t *frame_end = bfi->dst + avctx->width * avctx->height;
59 uint32_t *pal;
60 int i, j, ret, height = avctx->height;
61
62 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
63 return ret;
64
65 bytestream2_init(&g, avpkt->data, buf_size);
66
67 /* Set frame parameters and palette, if necessary */
68 if (!avctx->frame_num) {
69 frame->pict_type = AV_PICTURE_TYPE_I;
70 frame->flags |= AV_FRAME_FLAG_KEY;
71 /* Setting the palette */
72 if (avctx->extradata_size > 768) {
73 av_log(avctx, AV_LOG_ERROR, "Palette is too large.\n");
74 return AVERROR_INVALIDDATA;
75 }
76 pal = (uint32_t *)frame->data[1];
77 for (i = 0; i < avctx->extradata_size / 3; i++) {
78 int shift = 16;
79 *pal = 0xFFU << 24;
80 for (j = 0; j < 3; j++, shift -= 8)
81 *pal += ((avctx->extradata[i * 3 + j] << 2) |
82 (avctx->extradata[i * 3 + j] >> 4)) << shift;
83 pal++;
84 }
85 memcpy(bfi->pal, frame->data[1], sizeof(bfi->pal));
86 } else {
87 frame->pict_type = AV_PICTURE_TYPE_P;
88 frame->flags &= ~AV_FRAME_FLAG_KEY;
89 memcpy(frame->data[1], bfi->pal, sizeof(bfi->pal));
90 }
91
92 bytestream2_skip(&g, 4); // Unpacked size, not required.
93
94 while (dst != frame_end) {
95 static const uint8_t lentab[4] = { 0, 2, 0, 1 };
96 unsigned int byte = bytestream2_get_byte(&g), av_uninit(offset);
97 unsigned int code = byte >> 6;
98 unsigned int length = byte & ~0xC0;
99
100 if (!bytestream2_get_bytes_left(&g)) {
101 av_log(avctx, AV_LOG_ERROR,
102 "Input resolution larger than actual frame.\n");
103 return AVERROR_INVALIDDATA;
104 }
105
106 /* Get length and offset (if required) */
107 if (length == 0) {

Callers

nothing calls this directly

Calls 6

ff_get_bufferFunction · 0.85
bytestream2_initFunction · 0.85
av_logFunction · 0.85
bytestream2_skipFunction · 0.85
bytestream2_get_bufferFunction · 0.85

Tested by

no test coverage detected