FFmpeg  4.0
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 #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 static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
29 {
30  long i;
31 
32  for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
33  long a = *(long *) (src + i);
34  long b = *(long *) (dst + i);
35  *(long *) (dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80);
36  }
37  for (; i < w; i++)
38  dst[i + 0] += src[i + 0];
39 }
40 
41 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  l = *left;
49  lt = *left_top;
50 
51  for (i = 0; i < w; i++) {
52  l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
53  lt = src1[i];
54  dst[i] = l;
55  }
56 
57  *left = l;
58  *left_top = lt;
59 }
60 
61 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  for (i = 0; i < w - 1; i++) {
67  acc += src[i];
68  dst[i] = acc;
69  i++;
70  acc += src[i];
71  dst[i] = acc;
72  }
73 
74  for (; i < w; i++) {
75  acc += src[i];
76  dst[i] = acc;
77  }
78 
79  return acc;
80 }
81 
82 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  for(i=0; i<w-1; i++){
86  acc+= src[i];
87  dst[i]= acc &= mask;
88  i++;
89  acc+= src[i];
90  dst[i]= acc &= mask;
91  }
92 
93  for(; i<w; i++){
94  acc+= src[i];
95  dst[i]= acc &= mask;
96  }
97 
98  return acc;
99 }
100 
101 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  for (i = 0; i < width; i++) {
105  A = src[i - stride];
106  B = src[i - (stride + 1)];
107  C = src[i - 1];
108  src[i] = (A - B + C + src[i]) & 0xFF;
109  }
110 }
111 
113 {
114  c->add_bytes = add_bytes_c;
117 
120 
121  if (ARCH_PPC)
123  if (ARCH_X86)
125 }
int(* add_left_pred)(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int left)
#define C
#define ARCH_PPC
Definition: config.h:29
void ff_llviddsp_init_x86(LLVidDSPContext *llviddsp)
#define pb_80
int acc
Definition: yuv2rgb.c:554
const char * b
Definition: vf_curves.c:113
static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
#define pb_7f
#define src
Definition: vp8dsp.c:254
int stride
Definition: mace.c:144
uint8_t
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)
#define A(x)
Definition: vp56_arith.h:28
void(* add_gradient_pred)(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width)
static const uint16_t mask[17]
Definition: lzw.c:38
#define ARCH_X86
Definition: config.h:38
#define B
Definition: huffyuvdsp.h:32
uint16_t width
Definition: gdv.c:47
uint8_t w
Definition: llviddspenc.c:38
void ff_llviddsp_init_ppc(LLVidDSPContext *llviddsp)
int(* add_left_pred_int16)(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned left)
#define src1
Definition: h264pred.c:139
Libavcodec external API header.
static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc)
void ff_llviddsp_init(LLVidDSPContext *c)
#define mid_pred
Definition: mathops.h:97
static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
int
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 double c[64]
static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w, int acc)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
void(* add_bytes)(uint8_t *dst, uint8_t *src, ptrdiff_t w)