aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / libavcodec / huffyuvdsp.c
blobff69b45d12c37f5297949ed3ec54cfae7dd42abc
1 /*
2 * This file is part of Libav.
4 * Libav 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.
9 * Libav 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <stdint.h>
21 #include "config.h"
22 #include "libavutil/attributes.h"
23 #include "mathops.h"
24 #include "huffyuvdsp.h"
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)
30 static void add_bytes_c(uint8_t *dst, uint8_t *src, int w)
32 long i;
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);
39 for (; i < w; i++)
40 dst[i + 0] += src[i + 0];
43 static void add_hfyu_median_pred_c(uint8_t *dst, const uint8_t *src1,
44 const uint8_t *diff, int w,
45 int *left, int *left_top)
47 int i;
48 uint8_t l, lt;
50 l = *left;
51 lt = *left_top;
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;
59 *left = l;
60 *left_top = lt;
63 static int add_hfyu_left_pred_c(uint8_t *dst, const uint8_t *src, int w,
64 int acc)
66 int i;
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;
76 for (; i < w; i++) {
77 acc += src[i];
78 dst[i] = acc;
81 return acc;
84 #if HAVE_BIGENDIAN
85 #define B 3
86 #define G 2
87 #define R 1
88 #define A 0
89 #else
90 #define B 0
91 #define G 1
92 #define R 2
93 #define A 3
94 #endif
95 static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
96 int w, int *red, int *green,
97 int *blue, int *alpha)
99 int i, r = *red, g = *green, b = *blue, a = *alpha;
101 for (i = 0; i < w; i++) {
102 b += src[4 * i + B];
103 g += src[4 * i + G];
104 r += src[4 * i + R];
105 a += src[4 * i + A];
107 dst[4 * i + B] = b;
108 dst[4 * i + G] = g;
109 dst[4 * i + R] = r;
110 dst[4 * i + A] = a;
113 *red = r;
114 *green = g;
115 *blue = b;
116 *alpha = a;
118 #undef B
119 #undef G
120 #undef R
121 #undef A
123 av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c)
125 c->add_bytes = add_bytes_c;
126 c->add_hfyu_median_pred = add_hfyu_median_pred_c;
127 c->add_hfyu_left_pred = add_hfyu_left_pred_c;
128 c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
130 if (ARCH_PPC)
131 ff_huffyuvdsp_init_ppc(c);
132 if (ARCH_X86)
133 ff_huffyuvdsp_init_x86(c);