FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/huffyuv.c
Date: 2021-09-23 20:34:37
Exec Total Coverage
Lines: 28 31 90.3%
Branches: 12 14 85.7%

Line Branch Exec Source
1 /*
2 * huffyuv codec for libavcodec
3 *
4 * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
7 * the algorithm used
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 /**
27 * @file
28 * huffyuv codec for libavcodec.
29 */
30
31 #include <stdint.h>
32
33 #include "libavutil/mem.h"
34
35 #include "avcodec.h"
36 #include "bswapdsp.h"
37 #include "huffyuv.h"
38
39 351 int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
40 {
41 int len, index;
42 351 uint32_t bits = 0;
43
44
2/2
✓ Branch 0 taken 11232 times.
✓ Branch 1 taken 351 times.
11583 for (len = 32; len > 0; len--) {
45
2/2
✓ Branch 0 taken 26763264 times.
✓ Branch 1 taken 11232 times.
26774496 for (index = 0; index < n; index++) {
46
2/2
✓ Branch 0 taken 836352 times.
✓ Branch 1 taken 25926912 times.
26763264 if (len_table[index] == len)
47 836352 dst[index] = bits++;
48 }
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11232 times.
11232 if (bits & 1) {
50 av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
51 return -1;
52 }
53 11232 bits >>= 1;
54 }
55 351 return 0;
56 }
57
58 117 av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
59 {
60 int i;
61
62
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 117 times.
468 for (i=0; i<3; i++) {
63 351 s->temp[i]= av_malloc(4*s->width + 16);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 351 times.
351 if (!s->temp[i])
65 return AVERROR(ENOMEM);
66 351 s->temp16[i] = (uint16_t*)s->temp[i];
67 }
68 117 return 0;
69 }
70
71 117 av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
72 {
73 117 HYuvContext *s = avctx->priv_data;
74
75 117 s->avctx = avctx;
76 117 s->flags = avctx->flags;
77
78 117 ff_bswapdsp_init(&s->bdsp);
79
80 117 s->width = avctx->width;
81 117 s->height = avctx->height;
82
83 av_assert1(s->width > 0 && s->height > 0);
84 117 }
85
86 117 av_cold void ff_huffyuv_common_end(HYuvContext *s)
87 {
88 int i;
89
90
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 117 times.
468 for(i = 0; i < 3; i++) {
91 351 av_freep(&s->temp[i]);
92 351 s->temp16[i] = NULL;
93 }
94 117 }
95