2 * Lossless video DSP utils
4 * This file is part of FFmpeg.
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.
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.
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
21 #include "lossless_videodsp.h"
22 #include "libavcodec/mathops.h"
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)
28 static void add_bytes_c(uint8_t *dst, uint8_t *src, ptrdiff_t w)
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);
38 dst[i + 0] += src[i + 0];
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)
51 for (i = 0; i < w; i++) {
52 l = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF) + diff[i];
61 static int add_left_pred_c(uint8_t *dst, const uint8_t *src, ptrdiff_t w,
66 for (i = 0; i < w - 1; i++) {
82 static int add_left_pred_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc){
101 static void add_gradient_pred_c(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width){
104 for (i = 0; i < width; i++) {
106 B = src[i - (stride + 1)];
108 src[i] = (A - B + C + src[i]) & 0xFF;
112 void ff_llviddsp_init(LLVidDSPContext *c)
114 c->add_bytes = add_bytes_c;
115 c->add_median_pred = add_median_pred_c;
116 c->add_left_pred = add_left_pred_c;
118 c->add_left_pred_int16 = add_left_pred_int16_c;
119 c->add_gradient_pred = add_gradient_pred_c;
122 ff_llviddsp_init_ppc(c);
124 ff_llviddsp_init_x86(c);