FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/huffyuvencdsp.c
Date: 2024-12-12 01:08:13
Exec Total Coverage
Lines: 15 26 57.7%
Functions: 2 3 66.7%
Branches: 4 6 66.7%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "config.h"
20 #include "libavutil/attributes.h"
21 #include "libavutil/intreadwrite.h"
22 #include "huffyuvencdsp.h"
23 #include "mathops.h"
24
25 #if HAVE_FAST_64BIT
26 #define BITS 64
27 typedef uint64_t uint_native;
28 #else
29 #define BITS 32
30 typedef uint32_t uint_native;
31 #endif
32 #define RN AV_JOIN(AV_RN, BITS)
33 #define RNA AV_JOIN(AV_JOIN(AV_RN, BITS), A)
34 #define WNA AV_JOIN(AV_JOIN(AV_WN, BITS), A)
35
36 // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
37 #define pb_7f (~(uint_native)0 / 255 * 0x7f)
38 #define pb_80 (~(uint_native)0 / 255 * 0x80)
39
40 // 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
41 #define pw_1 ((uint_native)-1 / UINT16_MAX)
42
43 488200 static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w){
44 long i;
45 #if !HAVE_FAST_UNALIGNED
46 if ((uintptr_t)src2 & (sizeof(uint_native) - 1)) {
47 for(i=0; i+3<w; i+=4){
48 dst[i+0] = (src1[i+0]-src2[i+0]) & mask;
49 dst[i+1] = (src1[i+1]-src2[i+1]) & mask;
50 dst[i+2] = (src1[i+2]-src2[i+2]) & mask;
51 dst[i+3] = (src1[i+3]-src2[i+3]) & mask;
52 }
53 }else
54 #endif
55 {
56 488200 uint_native pw_lsb = (mask >> 1) * pw_1;
57 488200 uint_native pw_msb = pw_lsb + pw_1;
58
59
2/2
✓ Branch 0 taken 33350400 times.
✓ Branch 1 taken 488200 times.
33838600 for (i = 0; i <= w - (int)sizeof(uint_native)/2; i += sizeof(uint_native)/2) {
60 33350400 uint_native a = RNA(src1 + i);
61 33350400 uint_native b = RN (src2 + i);
62 33350400 WNA(dst + i, ((a | pw_msb) - (b & pw_lsb)) ^ ((a^b^pw_msb) & pw_msb));
63 }
64 }
65
2/2
✓ Branch 0 taken 26900 times.
✓ Branch 1 taken 488200 times.
515100 for (; i<w; i++)
66 26900 dst[i] = (src1[i] - src2[i]) & mask;
67 488200 }
68
69 static void sub_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w, int *left, int *left_top){
70 int i;
71 uint16_t l, lt;
72
73 l = *left;
74 lt = *left_top;
75
76 for(i=0; i<w; i++){
77 const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & mask);
78 lt = src1[i];
79 l = src2[i];
80 dst[i] = (l - pred) & mask;
81 }
82
83 *left = l;
84 *left_top = lt;
85 }
86
87 32 av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c, enum AVPixelFormat pix_fmt)
88 {
89 32 c->diff_int16 = diff_int16_c;
90 32 c->sub_hfyu_median_pred_int16 = sub_hfyu_median_pred_int16_c;
91
92 #if ARCH_X86
93 32 ff_huffyuvencdsp_init_x86(c, pix_fmt);
94 #endif
95 32 }
96