Coverage Report

Created: 2024-09-06 07:53

/src/ffmpeg/libavcodec/huffyuvdsp.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 <stdint.h>
20
21
#include "config.h"
22
#include "libavutil/attributes.h"
23
#include "mathops.h"
24
#include "huffyuv.h"
25
#include "huffyuvdsp.h"
26
27
// 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
28
3.27M
#define pw_1 (ULONG_MAX / UINT16_MAX)
29
30
1.63M
static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
31
1.63M
    long i;
32
1.63M
    unsigned long pw_lsb = (mask >> 1) * pw_1;
33
1.63M
    unsigned long pw_msb = pw_lsb +  pw_1;
34
1.93M
    for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
35
293k
        long a = *(long*)(src+i);
36
293k
        long b = *(long*)(dst+i);
37
293k
        *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb);
38
293k
    }
39
2.95M
    for(; i<w; i++)
40
1.31M
        dst[i] = (dst[i] + src[i]) & mask;
41
1.63M
}
42
43
1.91M
static void add_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top){
44
1.91M
    int i;
45
1.91M
    uint16_t l, lt;
46
47
1.91M
    l  = *left;
48
1.91M
    lt = *left_top;
49
50
6.56M
    for(i=0; i<w; i++){
51
4.64M
        l  = (mid_pred(l, src[i], (l + src[i] - lt) & mask) + diff[i]) & mask;
52
4.64M
        lt = src[i];
53
4.64M
        dst[i] = l;
54
4.64M
    }
55
56
1.91M
    *left     = l;
57
1.91M
    *left_top = lt;
58
1.91M
}
59
60
static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
61
                                       intptr_t w, uint8_t *left)
62
1.55M
{
63
1.55M
    int i;
64
1.55M
    uint8_t r = left[R], g = left[G], b = left[B], a = left[A];
65
66
55.0M
    for (i = 0; i < w; i++) {
67
53.4M
        b += src[4 * i + B];
68
53.4M
        g += src[4 * i + G];
69
53.4M
        r += src[4 * i + R];
70
53.4M
        a += src[4 * i + A];
71
72
53.4M
        dst[4 * i + B] = b;
73
53.4M
        dst[4 * i + G] = g;
74
53.4M
        dst[4 * i + R] = r;
75
53.4M
        dst[4 * i + A] = a;
76
53.4M
    }
77
78
1.55M
    left[B] = b;
79
1.55M
    left[G] = g;
80
1.55M
    left[R] = r;
81
1.55M
    left[A] = a;
82
1.55M
}
83
84
av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt)
85
1.68k
{
86
1.68k
    c->add_int16 = add_int16_c;
87
1.68k
    c->add_hfyu_median_pred_int16 = add_hfyu_median_pred_int16_c;
88
1.68k
    c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
89
90
#if ARCH_RISCV
91
    ff_huffyuvdsp_init_riscv(c, pix_fmt);
92
#elif ARCH_X86
93
    ff_huffyuvdsp_init_x86(c, pix_fmt);
94
1.68k
#endif
95
1.68k
}