FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/huffyuv.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 23 26 88.5%
Functions: 3 3 100.0%
Branches: 13 16 81.2%

Line Branch Exec Source
1 /*
2 * huffyuv codec for libavcodec
3 *
4 * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * see https://multimedia.cx/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/attributes.h"
34 #include "libavutil/error.h"
35 #include "libavutil/log.h"
36 #include "libavutil/mem.h"
37
38 #include "huffyuv.h"
39
40 351 int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
41 {
42 351 int lens[33] = { 0 };
43 uint32_t codes[33];
44
45
2/2
✓ Branch 0 taken 836352 times.
✓ Branch 1 taken 351 times.
836703 for (int i = 0; i < n; i++)
46 836352 lens[len_table[i]]++;
47
48 351 codes[32] = 0;
49
2/2
✓ Branch 0 taken 11232 times.
✓ Branch 1 taken 351 times.
11583 for (int i = FF_ARRAY_ELEMS(lens) - 1; i > 0; i--) {
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11232 times.
11232 if ((lens[i] + codes[i]) & 1) {
51 av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
52 return -1;
53 }
54 11232 codes[i - 1] = (lens[i] + codes[i]) >> 1;
55 }
56
2/2
✓ Branch 0 taken 836352 times.
✓ Branch 1 taken 351 times.
836703 for (int i = 0; i < n; i++) {
57
1/2
✓ Branch 0 taken 836352 times.
✗ Branch 1 not taken.
836352 if (len_table[i])
58 836352 dst[i] = codes[len_table[i]]++;
59 }
60 351 return 0;
61 }
62
63 117 av_cold int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width)
64 {
65 int i;
66
67
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 117 times.
468 for (i=0; i<3; i++) {
68 351 temp[i] = av_malloc(4 * width + 16);
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 351 times.
351 if (!temp[i])
70 return AVERROR(ENOMEM);
71 351 temp16[i] = (uint16_t*)temp[i];
72 }
73 117 return 0;
74 }
75
76 117 av_cold void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3])
77 {
78 int i;
79
80
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 117 times.
468 for(i = 0; i < 3; i++) {
81 351 av_freep(&temp[i]);
82 351 temp16[i] = NULL;
83 }
84 117 }
85