狗奴是什么意思| 头顶疼是什么原因| 9月17号是什么星座的| mansory是什么车| 吃青提有什么好处| 感性什么意思| 彼岸花开是什么意思| 赵本山是什么学历| 闰月什么意思| 蛋白石是什么| 三点水翟读什么| 春风十里不如你什么意思| 什么动物没有眼睛| 鼻子毛白了是什么原因| ab和o型血生的孩子是什么血型| 牙根出血是什么原因| 宝宝拉肚子挂什么科| 紫色加红色是什么颜色| 什么是封闭针| 怀孕建档是什么意思| 伽马刀是什么| 梦见自己光脚走路是什么意思| 哭得什么| 肺部结节是什么意思| 耳朵软骨疼是什么原因| 枸杞和山楂泡水喝有什么功效| 木槿花的花语是什么| 9月10日是什么日子| 鼻子挤出来的白色东西是什么| 什么是百慕大三角| 什么时候征兵| 黄瓜有什么好处| 不劳而获是什么意思| 张予曦为什么像混血| 抗核小体抗体阳性说明什么| 36周岁属什么| 尿频是什么原因导致的| 身体水肿是什么原因引起的| 天牛喜欢吃什么| 猫咪来家里是什么寓意| 祛是什么意思| 孩子睡觉磨牙是什么原因| 头晕拉肚子是什么情况| 晚上睡觉咬牙齿是什么原因| 孕妇为什么那么怕热| 额头长痘是什么原因| 陈真属什么生肖| 小恙是什么意思| 白细胞介素是什么| 众什么意思| 丰盈是什么意思| 相火是什么意思| 双鱼座的幸运色是什么| 八字缺什么怎么算| 胰腺的作用和功能是什么| dpd是什么意思| 突然消瘦是什么原因| 88年的属什么生肖| 淘宝交易关闭是什么意思| dior什么意思| hds是什么意思| 绿豆和什么一起煮好| 男士生育检查挂什么科| 什么的什么的词语| 三重一大是什么内容| 猎德村为什么那么有钱| 晚上7点是什么时辰| 什么是融合菜| 88年属什么| 大表哥是什么游戏| 复机是什么意思| 2002年是什么生肖| 肿瘤cr是什么意思| 湿疹是什么样的| 英气是什么意思| 什么的琴声| 巨蟹座和什么最配| penis什么意思| 丰都为什么叫鬼城| 梦见脱发是什么征兆| rt表示什么意思| 流理台是什么| 间歇脉多见于什么病| 蛇蝎心肠是什么生肖| 付之一炬什么意思| 肺部做什么检查最准确| 孕妇梦见龙是什么征兆| 淋巴结什么原因引起的| 梦见抬棺材是什么意思| 牙根出血是什么原因| 后背痒是什么原因| drg什么意思| 热气是什么意思| 变态反应科是看什么病的| 诸神黄昏什么意思| 三月十八是什么星座| 小孩肠胃炎吃什么药| 挚友是什么意思| 什么的马| 相形见拙什么意思| 孙俪什么学历| 吃海鲜忌什么| 先敬罗衣后敬人是什么意思| 四点底与什么有关| 主治医生是什么级别| 小麦秸秆是什么材质| 盐为什么要加碘| 生粉是什么粉| 可小刀是什么意思| 什么是体脂率| 81什么节| 天乙是什么意思| rh血型是什么血型| 回执单是什么意思| 1973年是什么年| 什么属相不能住西户| 鲫鱼是什么鱼| 牙周康又叫什么名字| 白细胞酯酶弱阳性是什么意思| 吃什么死的比较舒服| 得宫颈癌的前兆是什么| 急的什么| 做梦孩子死了什么预兆| 坐班是什么意思| 冥冥之中是什么意思| c反应蛋白是查什么的| 调兵遣将是什么生肖| 摸不到心跳是什么情况| 囟门是什么| 海带补什么| 最近我和你都有一样的心情什么歌| 蜂蜜变质是什么样子| 神经病和精神病有什么区别| 窦性心动过缓伴不齐是什么意思| 知趣是什么意思| 腰肌劳损需要注意什么| 欧洲为什么没有统一| 生蚝吃多了有什么危害| 迪桑特属于什么档次| 阴虱是什么样子图片| 宝宝打嗝是什么原因引起的| 谏什么意思| 肠胃蠕动慢吃什么药| 气胸是什么症状| 什么东西补气血效果最好| 伤口发炎吃什么消炎药| 高血压适合喝什么茶| 油价什么时候上涨| 鸭吃什么食物| 杏子不能和什么一起吃| 以色列是什么人种| 阴毛有什么用| 菜场附近开什么店好| 防风通圣颗粒治什么病| 吃什么东西补肾| 水印是什么意思| 愚蠢是什么意思| 一什么手| 冬瓜吃了有什么好处| 手抖是什么原因| 癃闭是什么意思| qcy是什么牌子| 四妙丸有什么功效与作用| 手指盖空了是什么原因| 口杯是什么意思| 黑卡是什么| 脱发挂什么科| 果肉属于什么组织| 学籍有什么用| 什么蔬菜是温性的| 乙醇是什么| 艾滋病是什么| 什么人不能吃黄芪| 今年72岁属什么生肖| 俄罗斯信奉的是什么教| 白带是绿色的是什么原因| 什么屎不臭| 不来月经是什么原因| 恩怨是什么意思| 民警是干什么的| 婠是什么意思| 废话是什么意思| 前列腺炎挂什么科| uhd是什么意思| 牙周炎吃什么消炎药| 左心增大是什么意思| 舌头白腻厚苔是什么原因| 白发越来越多是什么原因造成的| 骶1隐裂是什么意思| r标是什么意思| bdp是什么意思| 579是什么意思| 配子是什么| 247什么意思| 肾主骨是什么意思| 感冒吃什么药好得快| ca724是什么意思| 雨云是什么字| 无语是什么意思| 铁子是什么意思| 病毒感染发烧吃什么药| 空调外机风扇不转是什么原因| 男士私处用什么清洗| 人体第一道防线是什么| 2018 年是什么年| 木鱼花是什么| 孝道是什么意思| 沦丧是什么意思| 囊性结节是什么| 为什么明星都不戴黄金| 犹太人为什么不受欢迎| 走马观花的走什么意思| 血糖高是什么症状| 来忘掉错对来怀念过去是什么歌| 借什么不用还| 煮虾放什么| 操姓氏读什么| 回应是什么意思| 五行水多代表什么| 为什么不来大姨妈也没有怀孕| 心电图p波代表什么| 质数是什么| 什么样的人容易得脑瘤| 风湿热是什么病| 嘴里苦是什么原因| 心电图p是什么意思| 什么牌子的辅酶q10好| 贡菜是什么菜| 红细胞数目偏高是什么意思| 睡觉多梦吃什么药| n2是什么意思| 确立是什么意思| 为什么叫白俄罗斯| lz什么意思| 六月初十是什么日子| 一个六一个允念什么| 久坐脚肿是什么原因| 木志读什么| 安陵容为什么恨甄嬛| 什么瓜不能吃| 心肌梗塞是什么原因造成的| 副脾对身体有什么影响| 小便尿不出来是什么原因| 梦见抓甲鱼是什么意思| 耳朵轮廓痒是什么原因| 幼儿园什么时候开学| 低压高吃什么药效果好| 瓜怂是什么意思| 延长收货是什么意思| 什么花的花语是自由| ph值小于7是什么意思| 老铁是什么意思| 为什么会有乳腺结节| 鱿鱼不能和什么一起吃| 长江后浪推前浪是什么生肖| 脑梗的症状是什么| angelababy是什么意思| 感冒低烧吃什么药| 122是什么号码| 裤裙搭配什么上衣好看| t1w1高信号代表什么| 两胸之间是什么部位| 穿刺是什么检查| 吃知柏地黄丸有什么副作用| 百度

乐学“食安”,肯德基食安宣教趣味体验营成功举


Directory: ../../../ffmpeg/
File: src/libavcodec/fic.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 198 232 85.3%
Functions: 9 9 100.0%
Branches: 92 122 75.4%

Line Branch Exec Source
1 /*
2 * Mirillis FIC decoder
3 *
4 * Copyright (c) 2014 Konstantin Shishkov
5 * Copyright (c) 2014 Derek Buitenhuis
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "libavutil/common.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/mem_internal.h"
27 #include "libavutil/opt.h"
28 #include "avcodec.h"
29 #include "codec_internal.h"
30 #include "decode.h"
31 #include "get_bits.h"
32 #include "golomb.h"
33
34 typedef struct FICThreadContext {
35 DECLARE_ALIGNED(16, int16_t, block)[64];
36 const uint8_t *src;
37 int slice_h;
38 int src_size;
39 int y_off;
40 int p_frame;
41 } FICThreadContext;
42
43 typedef struct FICContext {
44 AVClass *class;
45 AVCodecContext *avctx;
46 AVFrame *frame;
47 AVFrame *final_frame;
48
49 FICThreadContext *slice_data;
50 int slice_data_size;
51
52 const uint8_t *qmat;
53
54 enum AVPictureType cur_frame_type;
55
56 int aligned_width, aligned_height;
57 int num_slices, slice_h;
58
59 int skip_cursor;
60 } FICContext;
61
62 static const uint8_t fic_qmat_hq[64] = {
63 1, 2, 2, 2, 3, 3, 3, 4,
64 2, 2, 2, 3, 3, 3, 4, 4,
65 2, 2, 3, 3, 3, 4, 4, 4,
66 2, 2, 3, 3, 3, 4, 4, 5,
67 2, 3, 3, 3, 4, 4, 5, 6,
68 3, 3, 3, 4, 4, 5, 6, 7,
69 3, 3, 3, 4, 4, 5, 7, 7,
70 3, 3, 4, 4, 5, 7, 7, 7,
71 };
72
73 static const uint8_t fic_qmat_lq[64] = {
74 1, 5, 6, 7, 8, 9, 9, 11,
75 5, 5, 7, 8, 9, 9, 11, 12,
76 6, 7, 8, 9, 9, 11, 11, 12,
77 7, 7, 8, 9, 9, 11, 12, 13,
78 7, 8, 9, 9, 10, 11, 13, 16,
79 8, 9, 9, 10, 11, 13, 16, 19,
80 8, 9, 9, 11, 12, 15, 18, 23,
81 9, 9, 11, 12, 15, 18, 23, 27
82 };
83
84 static const uint8_t fic_header[7] = { 0, 0, 1, 'F', 'I', 'C', 'V' };
85
86 #define FIC_HEADER_SIZE 27
87 #define CURSOR_OFFSET 59
88 #define CURSOR_SIZE 4096
89
90 2061536 static av_always_inline void fic_idct(int16_t *blk, int step, int shift, int rnd)
91 {
92 2061536 const unsigned t0 = 27246 * blk[3 * step] + 18405 * blk[5 * step];
93 2061536 const unsigned t1 = 27246 * blk[5 * step] - 18405 * blk[3 * step];
94 2061536 const unsigned t2 = 6393 * blk[7 * step] + 32139 * blk[1 * step];
95 2061536 const unsigned t3 = 6393 * blk[1 * step] - 32139 * blk[7 * step];
96 2061536 const unsigned t4 = 5793U * ((int)(t2 + t0 + 0x800) >> 12);
97 2061536 const unsigned t5 = 5793U * ((int)(t3 + t1 + 0x800) >> 12);
98 2061536 const unsigned t6 = t2 - t0;
99 2061536 const unsigned t7 = t3 - t1;
100 2061536 const unsigned t8 = 17734 * blk[2 * step] - 42813 * blk[6 * step];
101 2061536 const unsigned t9 = 17734 * blk[6 * step] + 42814 * blk[2 * step];
102 2061536 const unsigned tA = (blk[0 * step] - blk[4 * step]) * 32768 + rnd;
103 2061536 const unsigned tB = (blk[0 * step] + blk[4 * step]) * 32768 + rnd;
104 2061536 blk[0 * step] = (int)( t4 + t9 + tB) >> shift;
105 2061536 blk[1 * step] = (int)( t6 + t7 + t8 + tA) >> shift;
106 2061536 blk[2 * step] = (int)( t6 - t7 - t8 + tA) >> shift;
107 2061536 blk[3 * step] = (int)( t5 - t9 + tB) >> shift;
108 2061536 blk[4 * step] = (int)( -t5 - t9 + tB) >> shift;
109 2061536 blk[5 * step] = (int)(-(t6 - t7) - t8 + tA) >> shift;
110 2061536 blk[6 * step] = (int)(-(t6 + t7) + t8 + tA) >> shift;
111 2061536 blk[7 * step] = (int)( -t4 + t9 + tB) >> shift;
112 2061536 }
113
114 128846 static void fic_idct_put(uint8_t *dst, int stride, int16_t *block)
115 {
116 int i, j;
117 int16_t *ptr;
118
119 128846 ptr = block;
120 128846 fic_idct(ptr++, 8, 13, (1 << 12) + (1 << 17));
121
2/2
✓ Branch 0 taken 901922 times.
✓ Branch 1 taken 128846 times.
1030768 for (i = 1; i < 8; i++) {
122 901922 fic_idct(ptr, 8, 13, 1 << 12);
123 901922 ptr++;
124 }
125
126 128846 ptr = block;
127
2/2
✓ Branch 0 taken 1030768 times.
✓ Branch 1 taken 128846 times.
1159614 for (i = 0; i < 8; i++) {
128 1030768 fic_idct(ptr, 1, 20, 0);
129 1030768 ptr += 8;
130 }
131
132 128846 ptr = block;
133
2/2
✓ Branch 0 taken 1030768 times.
✓ Branch 1 taken 128846 times.
1159614 for (j = 0; j < 8; j++) {
134
2/2
✓ Branch 0 taken 8246144 times.
✓ Branch 1 taken 1030768 times.
9276912 for (i = 0; i < 8; i++)
135 8246144 dst[i] = av_clip_uint8(ptr[i]);
136 1030768 dst += stride;
137 1030768 ptr += 8;
138 }
139 128846 }
140 1077100 static int fic_decode_block(FICContext *ctx, GetBitContext *gb,
141 uint8_t *dst, int stride, int16_t *block, int *is_p)
142 {
143 int i, num_coeff;
144
145
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1077094 times.
1077100 if (get_bits_left(gb) < 8)
146 6 return AVERROR_INVALIDDATA;
147
148 /* Is it a skip block? */
149
2/2
✓ Branch 1 taken 948248 times.
✓ Branch 2 taken 128846 times.
1077094 if (get_bits1(gb)) {
150 948248 *is_p = 1;
151 948248 return 0;
152 }
153
154 128846 memset(block, 0, sizeof(*block) * 64);
155
156 128846 num_coeff = get_bits(gb, 7);
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 128846 times.
128846 if (num_coeff > 64)
158 return AVERROR_INVALIDDATA;
159
160
2/2
✓ Branch 0 taken 2249776 times.
✓ Branch 1 taken 128846 times.
2378622 for (i = 0; i < num_coeff; i++) {
161 2249776 int v = get_se_golomb(gb);
162
2/4
✓ Branch 0 taken 2249776 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2249776 times.
2249776 if (v < -2048 || v > 2048)
163 return AVERROR_INVALIDDATA;
164 2249776 block[ff_zigzag_direct[i]] = v *
165 2249776 ctx->qmat[ff_zigzag_direct[i]];
166 }
167
168 128846 fic_idct_put(dst, stride, block);
169
170 128846 return 0;
171 }
172
173 184 static int fic_decode_slice(AVCodecContext *avctx, void *tdata)
174 {
175 184 FICContext *ctx = avctx->priv_data;
176 184 FICThreadContext *tctx = tdata;
177 GetBitContext gb;
178 184 const uint8_t *src = tctx->src;
179 184 int slice_h = tctx->slice_h;
180 184 int src_size = tctx->src_size;
181 184 int y_off = tctx->y_off;
182 int x, y, p, ret;
183
184 184 ret = init_get_bits8(&gb, src, src_size);
185
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 176 times.
184 if (ret < 0)
186 8 return ret;
187
188
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 170 times.
698 for (p = 0; p < 3; p++) {
189 528 int stride = ctx->frame->linesize[p];
190 528 uint8_t* dst = ctx->frame->data[p] + (y_off >> !!p) * stride;
191
192
2/2
✓ Branch 0 taken 8448 times.
✓ Branch 1 taken 522 times.
8970 for (y = 0; y < (slice_h >> !!p); y += 8) {
193
2/2
✓ Branch 0 taken 1077100 times.
✓ Branch 1 taken 8442 times.
1085542 for (x = 0; x < (ctx->aligned_width >> !!p); x += 8) {
194 int ret;
195
196
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1077094 times.
1077100 if ((ret = fic_decode_block(ctx, &gb, dst + x, stride,
197 1077100 tctx->block, &tctx->p_frame)) != 0)
198 6 return ret;
199 }
200
201 8442 dst += 8 * stride;
202 }
203 }
204
205 170 return 0;
206 }
207
208 1472 static av_always_inline void fic_alpha_blend(uint8_t *dst, uint8_t *src,
209 int size, uint8_t *alpha)
210 {
211 int i;
212
213
2/2
✓ Branch 0 taken 35328 times.
✓ Branch 1 taken 1472 times.
36800 for (i = 0; i < size; i++)
214 35328 dst[i] += ((src[i] - dst[i]) * alpha[i]) >> 8;
215 1472 }
216
217 23 static void fic_draw_cursor(AVCodecContext *avctx, const uint8_t cursor_buf[CURSOR_SIZE],
218 int cur_x, int cur_y)
219 {
220 23 FICContext *ctx = avctx->priv_data;
221 23 const uint8_t *ptr = cursor_buf;
222 uint8_t *dstptr[3];
223 uint8_t planes[4][1024];
224 uint8_t chroma[3][256];
225 int i, j, p;
226
227 /* Convert to YUVA444. */
228
2/2
✓ Branch 0 taken 23552 times.
✓ Branch 1 taken 23 times.
23575 for (i = 0; i < 1024; i++) {
229 23552 planes[0][i] = (( 25 * ptr[0] + 129 * ptr[1] + 66 * ptr[2]) / 255) + 16;
230 23552 planes[1][i] = ((-38 * ptr[0] + 112 * ptr[1] + -74 * ptr[2]) / 255) + 128;
231 23552 planes[2][i] = ((-18 * ptr[0] + 112 * ptr[1] + -94 * ptr[2]) / 255) + 128;
232 23552 planes[3][i] = ptr[3];
233
234 23552 ptr += 4;
235 }
236
237 /* Subsample chroma. */
238
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 23 times.
391 for (i = 0; i < 32; i += 2)
239
2/2
✓ Branch 0 taken 5888 times.
✓ Branch 1 taken 368 times.
6256 for (j = 0; j < 32; j += 2)
240
2/2
✓ Branch 0 taken 17664 times.
✓ Branch 1 taken 5888 times.
23552 for (p = 0; p < 3; p++)
241 17664 chroma[p][16 * (i / 2) + j / 2] = (planes[p + 1][32 * i + j ] +
242 17664 planes[p + 1][32 * i + j + 1] +
243 17664 planes[p + 1][32 * (i + 1) + j ] +
244 17664 planes[p + 1][32 * (i + 1) + j + 1]) / 4;
245
246 /* Seek to x/y pos of cursor. */
247
2/2
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 23 times.
92 for (i = 0; i < 3; i++)
248 69 dstptr[i] = ctx->final_frame->data[i] +
249 69 (ctx->final_frame->linesize[i] * (cur_y >> !!i)) +
250 69 (cur_x >> !!i) + !!i;
251
252 /* Copy. */
253
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 23 times.
391 for (i = 0; i < FFMIN(32, avctx->height - cur_y) - 1; i += 2) {
254 368 int lsize = FFMIN(32, avctx->width - cur_x);
255 368 int csize = lsize / 2;
256
257 368 fic_alpha_blend(dstptr[0],
258 368 planes[0] + i * 32, lsize, planes[3] + i * 32);
259 368 fic_alpha_blend(dstptr[0] + ctx->final_frame->linesize[0],
260 368 planes[0] + (i + 1) * 32, lsize, planes[3] + (i + 1) * 32);
261 368 fic_alpha_blend(dstptr[1],
262 368 chroma[0] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16);
263 368 fic_alpha_blend(dstptr[2],
264 368 chroma[1] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16);
265
266 368 dstptr[0] += ctx->final_frame->linesize[0] * 2;
267 368 dstptr[1] += ctx->final_frame->linesize[1];
268 368 dstptr[2] += ctx->final_frame->linesize[2];
269 }
270 23 }
271
272 242 static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
273 int *got_frame, AVPacket *avpkt)
274 {
275 242 FICContext *ctx = avctx->priv_data;
276 242 const uint8_t *src = avpkt->data;
277 int ret;
278 int slice, nslices;
279 int msize;
280 int tsize;
281 int cur_x, cur_y;
282 242 int skip_cursor = ctx->skip_cursor;
283 const uint8_t *sdata;
284
285 /* Header + at least one slice (4) */
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 242 times.
242 if (avpkt->size < FIC_HEADER_SIZE + 4) {
287 av_log(avctx, AV_LOG_ERROR, "Frame data is too small.\n");
288 return AVERROR_INVALIDDATA;
289 }
290
291 /* Check for header. */
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 242 times.
242 if (memcmp(src, fic_header, 7))
293 av_log(avctx, AV_LOG_WARNING, "Invalid FIC Header.\n");
294
295 /* Is it a skip frame? */
296
2/2
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 46 times.
242 if (src[17]) {
297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 196 times.
196 if (!ctx->final_frame->data[0]) {
298 av_log(avctx, AV_LOG_WARNING, "Initial frame is skipped\n");
299 return AVERROR_INVALIDDATA;
300 }
301 196 ret = ff_reget_buffer(avctx, ctx->final_frame,
302 FF_REGET_BUFFER_FLAG_READONLY);
303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 196 times.
196 if (ret < 0)
304 return ret;
305 196 goto skip;
306 }
307
308 46 nslices = src[13];
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (!nslices) {
310 av_log(avctx, AV_LOG_ERROR, "Zero slices found.\n");
311 return AVERROR_INVALIDDATA;
312 }
313
314 /* High or Low Quality Matrix? */
315
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 ctx->qmat = src[23] ? fic_qmat_hq : fic_qmat_lq;
316
317 /* Skip cursor data. */
318 46 tsize = AV_RB24(src + 24);
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (tsize > avpkt->size - FIC_HEADER_SIZE) {
320 av_log(avctx, AV_LOG_ERROR,
321 "Packet is too small to contain cursor (%d vs %d bytes).\n",
322 tsize, avpkt->size - FIC_HEADER_SIZE);
323 return AVERROR_INVALIDDATA;
324 }
325
326
3/6
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 46 times.
46 if (!tsize || !AV_RL16(src + 37) || !AV_RL16(src + 39))
327 skip_cursor = 1;
328
329
3/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
46 if (!skip_cursor && tsize < 32) {
330 av_log(avctx, AV_LOG_WARNING,
331 "Cursor data too small. Skipping cursor.\n");
332 skip_cursor = 1;
333 }
334
335 /* Cursor position. */
336 46 cur_x = AV_RL16(src + 33);
337 46 cur_y = AV_RL16(src + 35);
338
4/6
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 23 times.
46 if (!skip_cursor && (cur_x > avctx->width || cur_y > avctx->height)) {
339 av_log(avctx, AV_LOG_DEBUG,
340 "Invalid cursor position: (%d,%d). Skipping cursor.\n",
341 cur_x, cur_y);
342 skip_cursor = 1;
343 }
344
345
4/6
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 23 times.
46 if (!skip_cursor && (AV_RL16(src + 37) != 32 || AV_RL16(src + 39) != 32)) {
346 av_log(avctx, AV_LOG_WARNING,
347 "Invalid cursor size. Skipping cursor.\n");
348 skip_cursor = 1;
349 }
350
351
3/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
46 if (!skip_cursor && avpkt->size < CURSOR_OFFSET + CURSOR_SIZE)
352 skip_cursor = 1;
353
354 /* Slice height for all but the last slice. */
355 46 ctx->slice_h = 16 * (ctx->aligned_height >> 4) / nslices;
356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (ctx->slice_h % 16)
357 ctx->slice_h = FFALIGN(ctx->slice_h - 16, 16);
358
359 /* First slice offset and remaining data. */
360 46 sdata = src + tsize + FIC_HEADER_SIZE + 4 * nslices;
361 46 msize = avpkt->size - nslices * 4 - tsize - FIC_HEADER_SIZE;
362
363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (msize <= ctx->aligned_width/8 * (ctx->aligned_height/8) / 8) {
364 av_log(avctx, AV_LOG_ERROR, "Not enough frame data to decode.\n");
365 return AVERROR_INVALIDDATA;
366 }
367
368 /* Allocate slice data. */
369 46 av_fast_malloc(&ctx->slice_data, &ctx->slice_data_size,
370 nslices * sizeof(ctx->slice_data[0]));
371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (!ctx->slice_data_size) {
372 av_log(avctx, AV_LOG_ERROR, "Could not allocate slice data.\n");
373 return AVERROR(ENOMEM);
374 }
375 46 memset(ctx->slice_data, 0, nslices * sizeof(ctx->slice_data[0]));
376
377
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 46 times.
230 for (slice = 0; slice < nslices; slice++) {
378 184 unsigned slice_off = AV_RB32(src + tsize + FIC_HEADER_SIZE + slice * 4);
379 unsigned slice_size;
380 184 int y_off = ctx->slice_h * slice;
381 184 int slice_h = ctx->slice_h;
382
383 /*
384 * Either read the slice size, or consume all data left.
385 * Also, special case the last slight height.
386 */
387
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 138 times.
184 if (slice == nslices - 1) {
388 46 slice_size = msize;
389 46 slice_h = FFALIGN(avctx->height - ctx->slice_h * (nslices - 1), 16);
390 } else {
391 138 slice_size = AV_RB32(src + tsize + FIC_HEADER_SIZE + slice * 4 + 4);
392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if (slice_size < slice_off)
393 return AVERROR_INVALIDDATA;
394 }
395
396
4/4
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 176 times.
184 if (slice_size < slice_off || slice_size > msize)
397 8 continue;
398
399 176 slice_size -= slice_off;
400
401 176 ctx->slice_data[slice].src = sdata + slice_off;
402 176 ctx->slice_data[slice].src_size = slice_size;
403 176 ctx->slice_data[slice].slice_h = slice_h;
404 176 ctx->slice_data[slice].y_off = y_off;
405 }
406
407
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
46 if ((ret = ff_reget_buffer(avctx, ctx->frame, 0)) < 0)
408 return ret;
409
410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
46 if ((ret = avctx->execute(avctx, fic_decode_slice, ctx->slice_data,
411 NULL, nslices, sizeof(ctx->slice_data[0]))) < 0)
412 return ret;
413
414 46 ctx->frame->flags |= AV_FRAME_FLAG_KEY;
415 46 ctx->frame->pict_type = AV_PICTURE_TYPE_I;
416
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 6 times.
70 for (slice = 0; slice < nslices; slice++) {
417
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 24 times.
64 if (ctx->slice_data[slice].p_frame) {
418 40 ctx->frame->flags &= ~AV_FRAME_FLAG_KEY;
419 40 ctx->frame->pict_type = AV_PICTURE_TYPE_P;
420 40 break;
421 }
422 }
423 46 ret = av_frame_replace(ctx->final_frame, ctx->frame);
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (ret < 0)
425 return ret;
426
427 /* Draw cursor if needed. */
428
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 23 times.
46 if (!skip_cursor) {
429 /* Make frame writable. */
430 23 ret = ff_reget_buffer(avctx, ctx->final_frame, 0);
431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (ret < 0)
432 return ret;
433
434 23 fic_draw_cursor(avctx, src + CURSOR_OFFSET, cur_x, cur_y);
435 }
436
437 23 skip:
438
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 242 times.
242 if ((ret = av_frame_ref(rframe, ctx->final_frame)) < 0)
439 return ret;
440 242 *got_frame = 1;
441
442 242 return avpkt->size;
443 }
444
445 4 static av_cold int fic_decode_close(AVCodecContext *avctx)
446 {
447 4 FICContext *ctx = avctx->priv_data;
448
449 4 av_freep(&ctx->slice_data);
450 4 av_frame_free(&ctx->final_frame);
451 4 av_frame_free(&ctx->frame);
452
453 4 return 0;
454 }
455
456 4 static av_cold int fic_decode_init(AVCodecContext *avctx)
457 {
458 4 FICContext *ctx = avctx->priv_data;
459
460 /* Initialize various context values */
461 4 ctx->avctx = avctx;
462 4 ctx->aligned_width = FFALIGN(avctx->width, 16);
463 4 ctx->aligned_height = FFALIGN(avctx->height, 16);
464
465 4 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
466 4 avctx->bits_per_raw_sample = 8;
467
468 4 ctx->frame = av_frame_alloc();
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!ctx->frame)
470 return AVERROR(ENOMEM);
471 4 ctx->final_frame = av_frame_alloc();
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!ctx->final_frame)
473 return AVERROR(ENOMEM);
474
475 4 return 0;
476 }
477
478 static const AVOption options[] = {
479 { "skip_cursor", "skip the cursor", offsetof(FICContext, skip_cursor), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
480 { NULL },
481 };
482
483 static const AVClass fic_decoder_class = {
484 .class_name = "FIC decoder",
485 .item_name = av_default_item_name,
486 .option = options,
487 .version = LIBAVUTIL_VERSION_INT,
488 };
489
490 const FFCodec ff_fic_decoder = {
491 .p.name = "fic",
492 CODEC_LONG_NAME("Mirillis FIC"),
493 .p.type = AVMEDIA_TYPE_VIDEO,
494 .p.id = AV_CODEC_ID_FIC,
495 .priv_data_size = sizeof(FICContext),
496 .init = fic_decode_init,
497 FF_CODEC_DECODE_CB(fic_decode_frame),
498 .close = fic_decode_close,
499 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS,
500 .p.priv_class = &fic_decoder_class,
501 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
502 };
503

五指毛桃有什么作用 皮皮虾吃什么 试管什么降调 面首什么意思 z值是什么意思
洗衣机脱水是什么意思 脱力是什么意思 梦见坟墓是什么预兆 什么是吸附性义齿 心肌缺血用什么药
黑乌龙茶属于什么茶 没主见是什么意思 正月十八是什么日子 豆豉是什么东西 睡前吃什么有助于睡眠
脸上经常长痘痘是什么原因 什么叫正盐 白头发多吃什么 什么人容易得焦虑症 庚午五行属什么
羊水栓塞是什么原因引起的hcv9jop3ns3r.cn 低烧吃什么药好hcv8jop2ns7r.cn 低钾有什么症状和危害hcv8jop7ns8r.cn 朱砂痣什么意思hcv8jop8ns4r.cn 糜烂是什么意思hcv9jop6ns8r.cn
洋葱什么时候收获hcv8jop2ns6r.cn 非营利性医院是什么意思hanqikai.com hp是什么牌子的电脑hcv7jop9ns6r.cn 额头上长斑是什么原因造成的hcv8jop6ns8r.cn 吃什么东西可以减肥hcv8jop7ns9r.cn
幽门螺杆菌是一种什么病hcv8jop0ns0r.cn 外阴苔癣是一种什么病hcv7jop7ns2r.cn 为什么老虎头上有王字hcv8jop5ns8r.cn 立秋当天吃什么hcv9jop7ns9r.cn 狗狗吃胡萝卜有什么好处hcv9jop3ns9r.cn
谢谢谬赞是什么意思hcv7jop4ns8r.cn 什么是k金hcv8jop3ns4r.cn 大祭司是什么意思hcv9jop6ns5r.cn 骨密度z值是什么意思hcv8jop9ns9r.cn 日月同辉是什么意思helloaicloud.com
百度 技术支持:蜘蛛池 www.kelongchi.com