Coverage Report

Created: 2025-12-31 07:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/huffyuvencdsp.c
Line
Count
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
0
#define RN  AV_JOIN(AV_RN, BITS)
33
0
#define RNA AV_JOIN(AV_JOIN(AV_RN, BITS), A)
34
0
#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
0
#define pw_1 ((uint_native)-1 / UINT16_MAX)
42
43
25.6k
static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w){
44
25.6k
    long i;
45
25.6k
#if !HAVE_FAST_UNALIGNED
46
25.6k
    if ((uintptr_t)src2 & (sizeof(uint_native) - 1)) {
47
3.24M
        for(i=0; i+3<w; i+=4){
48
3.21M
            dst[i+0] = (src1[i+0]-src2[i+0]) & mask;
49
3.21M
            dst[i+1] = (src1[i+1]-src2[i+1]) & mask;
50
3.21M
            dst[i+2] = (src1[i+2]-src2[i+2]) & mask;
51
3.21M
            dst[i+3] = (src1[i+3]-src2[i+3]) & mask;
52
3.21M
        }
53
25.6k
    }else
54
0
#endif
55
0
    {
56
0
        uint_native pw_lsb = (mask >> 1) * pw_1;
57
0
        uint_native pw_msb = pw_lsb +  pw_1;
58
59
0
        for (i = 0; i <= w - (int)sizeof(uint_native)/2; i += sizeof(uint_native)/2) {
60
0
            uint_native a = RNA(src1 + i);
61
0
            uint_native b = RN (src2 + i);
62
0
            WNA(dst + i, ((a | pw_msb) - (b & pw_lsb)) ^ ((a^b^pw_msb) & pw_msb));
63
0
        }
64
0
    }
65
63.4k
    for (; i<w; i++)
66
37.7k
        dst[i] = (src1[i] - src2[i]) & mask;
67
25.6k
}
68
69
0
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
0
    int i;
71
0
    uint16_t l, lt;
72
73
0
    l  = *left;
74
0
    lt = *left_top;
75
76
0
    for(i=0; i<w; i++){
77
0
        const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & mask);
78
0
        lt = src1[i];
79
0
        l  = src2[i];
80
0
        dst[i] = (l - pred) & mask;
81
0
    }
82
83
0
    *left     = l;
84
0
    *left_top = lt;
85
0
}
86
87
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c, enum AVPixelFormat pix_fmt)
88
994
{
89
994
    c->diff_int16           = diff_int16_c;
90
994
    c->sub_hfyu_median_pred_int16 = sub_hfyu_median_pred_int16_c;
91
92
#if ARCH_X86 && HAVE_X86ASM
93
    ff_huffyuvencdsp_init_x86(c, pix_fmt);
94
#endif
95
994
}