FFmpeg  4.4.9
lossless_videoencdsp.c
Go to the documentation of this file.
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 "lossless_videoencdsp.h"
23 #include "mathops.h"
24 
25 #if HAVE_FAST_64BIT
26 typedef uint64_t uint_native;
27 #define READ AV_RN64
28 #define READA AV_RN64A
29 #define WRITEA AV_WN64A
30 #else
31 typedef uint32_t uint_native;
32 #define READ AV_RN32
33 #define READA AV_RN32A
34 #define WRITEA AV_WN32A
35 #endif
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 static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
41 {
42  long i;
43 
44 #if !HAVE_FAST_UNALIGNED
45  if (((uintptr_t)src1 | (uintptr_t)src2) & (sizeof(uint_native) - 1)) {
46  for (i = 0; i + 7 < w; i += 8) {
47  dst[i + 0] = src1[i + 0] - src2[i + 0];
48  dst[i + 1] = src1[i + 1] - src2[i + 1];
49  dst[i + 2] = src1[i + 2] - src2[i + 2];
50  dst[i + 3] = src1[i + 3] - src2[i + 3];
51  dst[i + 4] = src1[i + 4] - src2[i + 4];
52  dst[i + 5] = src1[i + 5] - src2[i + 5];
53  dst[i + 6] = src1[i + 6] - src2[i + 6];
54  dst[i + 7] = src1[i + 7] - src2[i + 7];
55  }
56  } else
57 #endif
58  for (i = 0; i <= w - (int) sizeof(uint_native); i += sizeof(uint_native)) {
59  uint_native a = READA(src1 + i);
60  uint_native b = READ(src2 + i);
61  WRITEA(dst + i, ((a | pb_80) - (b & pb_7f)) ^ ((a ^ b ^ pb_80) & pb_80));
62  }
63  for (; i < w; i++)
64  dst[i + 0] = src1[i + 0] - src2[i + 0];
65 }
66 
67 static void sub_median_pred_c(uint8_t *dst, const uint8_t *src1,
68  const uint8_t *src2, intptr_t w,
69  int *left, int *left_top)
70 {
71  int i;
72  uint8_t l, lt;
73 
74  l = *left;
75  lt = *left_top;
76 
77  for (i = 0; i < w; i++) {
78  const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF);
79  lt = src1[i];
80  l = src2[i];
81  dst[i] = l - pred;
82  }
83 
84  *left = l;
85  *left_top = lt;
86 }
87 
89  ptrdiff_t stride, ptrdiff_t width, int height)
90 {
91  int i, j;
92  uint8_t prev = 0x80; /* Set the initial value */
93  for (j = 0; j < height; j++) {
94  for (i = 0; i < width; i++) {
95  *dst++ = src[i] - prev;
96  prev = src[i];
97  }
98  src += stride;
99  }
100 }
101 
103 {
104  c->diff_bytes = diff_bytes_c;
105  c->sub_median_pred = sub_median_pred_c;
106  c->sub_left_predict = sub_left_predict_c;
107 
108  if (ARCH_X86)
110 }
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
uint8_t
#define ARCH_X86
Definition: config.h:39
int
uint32_t uint_native
Definition: huffyuvencdsp.c:30
int i
Definition: input.c:407
uint8_t w
Definition: llviddspenc.c:39
#define WRITEA
uint32_t uint_native
#define pb_7f
static void sub_median_pred_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w, int *left, int *left_top)
av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
#define READA
#define pb_80
#define READ
static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, intptr_t w)
static void sub_left_predict_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride, ptrdiff_t width, int height)
void ff_llvidencdsp_init_x86(LLVidEncDSPContext *c)
int stride
Definition: mace.c:144
#define mid_pred
Definition: mathops.h:97
static const float pred[4]
Definition: siprdata.h:259
#define src1
Definition: h264pred.c:140
#define src
Definition: vp8dsp.c:255
#define height
#define width
const char * b
Definition: vf_curves.c:119
static double c[64]