FFmpeg
Loading...
Searching...
No Matches
lossless_videodsp.c
Go to the documentation of this file.
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
21#include "config.h"
22#include "lossless_videodsp.h"
23#include "libavcodec/mathops.h"
25
26// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
27#define pb_7f (~0UL / 255 * 0x7f)
28#define pb_80 (~0UL / 255 * 0x80)
29
30static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
31{
32 long i;
33
34 for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
35 long a = *(long *) (src + i);
36 long b = *(long *) (dst + i);
37 *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
38 }
39 for (; i < w; i++)
40 dst[i + 0] += src[i + 0];
41}
42
43static void add_median_pred_c(uint8_t *dst, const uint8_t *src1,
44 const uint8_t *diff, ptrdiff_t w,
45 int *left, int *left_top)
46{
47 int i;
48 uint8_t l, lt;
49
50 l = *left;
51 lt = *left_top;
52
53 for (i = 0; i < w; i++) {
54 l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
55 lt = src1[i];
56 dst[i] = l;
57 }
58
59 *left = l;
60 *left_top = lt;
61}
62
63static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w,
64 int acc)
65{
66 int i;
67
68 for (i = 0; i < w - 1; i++) {
69 acc += src[i];
70 dst[i] = acc;
71 i++;
72 acc += src[i];
73 dst[i] = acc;
74 }
75
76 for (; i < w; i++) {
77 acc += src[i];
78 dst[i] = acc;
79 }
80
81 return acc;
82}
83
84static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){
85 int i;
86
87 for(i=0; i<w-1; i++){
88 acc+= src[i];
89 dst[i]= acc &= mask;
90 i++;
91 acc+= src[i];
92 dst[i]= acc &= mask;
93 }
94
95 for(; i<w; i++){
96 acc+= src[i];
97 dst[i]= acc &= mask;
98 }
99
100 return acc;
101}
102
103static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){
104 int A, B, C, i;
105
106 for (i = 0; i < width; i++) {
107 A = src[i - stride];
108 B = src[i - (stride + 1)];
109 C = src[i - 1];
110 src[i] = (A - B + C + src[i]) & 0xFF;
111 }
112}
113
115{
116 c->add_bytes = add_bytes_c;
117 c->add_median_pred = add_median_pred_c;
118 c->add_left_pred = add_left_pred_c;
119
120 c->add_left_pred_int16 = add_left_pred_int16_c;
121 c->add_gradient_pred = add_gradient_pred_c;
122
123#if ARCH_PPC
125#elif ARCH_RISCV
127#elif ARCH_X86 && HAVE_X86ASM
129#endif
130}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define A(x)
Definition vpx_arith.h:28
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
int a
#define B
Definition huffyuv.h:42
#define b
Definition input.c:43
#define C
#define pb_7f
#define pb_80
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
uint8_t w
Definition llvidencdsp.c:39
static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc)
static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int acc)
av_cold void ff_llviddsp_init(LLVidDSPContext *c)
static void add_median_pred_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)
static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
void ff_llviddsp_init_x86(LLVidDSPContext *llviddsp)
void ff_llviddsp_init_ppc(LLVidDSPContext *llviddsp)
void ff_llviddsp_init_riscv(LLVidDSPContext *llviddsp)
static const uint16_t mask[17]
Definition lzw.c:38
#define mid_pred
Definition mathops.h:115
#define stride
#define src1
Definition h264pred.c:141
#define src
Definition vp8dsp.c:248
#define width
Definition dsp.h:89
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static double c[64]