FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/fic.c
Date: 2022-07-05 19:52:29
Exec Total Coverage
Lines: 194 229 84.7%
Branches: 85 118 72.0%

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