GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/lossless_videodsp.c Lines: 54 55 98.2 %
Date: 2019-11-22 03:34:36 Branches: 15 16 93.8 %

Line Branch Exec Source
1
/*
2
 * Lossless video DSP utils
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
#include "avcodec.h"
21
#include "lossless_videodsp.h"
22
#include "libavcodec/mathops.h"
23
24
// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
25
#define pb_7f (~0UL / 255 * 0x7f)
26
#define pb_80 (~0UL / 255 * 0x80)
27
28
30819
static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
29
{
30
    long i;
31
32
2536995
    for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
33
2506176
        long a = *(long *) (src + i);
34
2506176
        long b = *(long *) (dst + i);
35
2506176
        *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
36
    }
37
30819
    for (; i < w; i++)
38
        dst[i + 0] += src[i + 0];
39
30819
}
40
41
47711
static void add_median_pred_c(uint8_t *dst, const uint8_t *src1,
42
                              const uint8_t *diff, ptrdiff_t w,
43
                              int *left, int *left_top)
44
{
45
    int i;
46
    uint8_t l, lt;
47
48
47711
    l  = *left;
49
47711
    lt = *left_top;
50
51
28819455
    for (i = 0; i < w; i++) {
52
28771744
        l      = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
53
28771744
        lt     = src1[i];
54
28771744
        dst[i] = l;
55
    }
56
57
47711
    *left     = l;
58
47711
    *left_top = lt;
59
47711
}
60
61
363460
static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w,
62
                           int acc)
63
{
64
    int i;
65
66
50467828
    for (i = 0; i < w - 1; i++) {
67
50104368
        acc   += src[i];
68
50104368
        dst[i] = acc;
69
50104368
        i++;
70
50104368
        acc   += src[i];
71
50104368
        dst[i] = acc;
72
    }
73
74
368976
    for (; i < w; i++) {
75
5516
        acc   += src[i];
76
5516
        dst[i] = acc;
77
    }
78
79
363460
    return acc;
80
}
81
82
359203
static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){
83
    int i;
84
85
49965687
    for(i=0; i<w-1; i++){
86
49606484
        acc+= src[i];
87
49606484
        dst[i]= acc &= mask;
88
49606484
        i++;
89
49606484
        acc+= src[i];
90
49606484
        dst[i]= acc &= mask;
91
    }
92
93
364303
    for(; i<w; i++){
94
5100
        acc+= src[i];
95
5100
        dst[i]= acc &= mask;
96
    }
97
98
359203
    return acc;
99
}
100
101
2697
static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){
102
    int A, B, C, i;
103
104
401985
    for (i = 0; i < width; i++) {
105
399288
        A = src[i - stride];
106
399288
        B = src[i - (stride + 1)];
107
399288
        C = src[i - 1];
108
399288
        src[i] = (A - B + C + src[i]) & 0xFF;
109
    }
110
2697
}
111
112
164
void ff_llviddsp_init(LLVidDSPContext *c)
113
{
114
164
    c->add_bytes                  = add_bytes_c;
115
164
    c->add_median_pred            = add_median_pred_c;
116
164
    c->add_left_pred              = add_left_pred_c;
117
118
164
    c->add_left_pred_int16        = add_left_pred_int16_c;
119
164
    c->add_gradient_pred          = add_gradient_pred_c;
120
121
    if (ARCH_PPC)
122
        ff_llviddsp_init_ppc(c);
123
    if (ARCH_X86)
124
164
        ff_llviddsp_init_x86(c);
125
164
}