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
22 #include "libavutil/attributes.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
)
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
);
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
)
53 for (i
= 0; i
< w
; i
++) {
54 l
= mid_pred(l
, src1
[i
], (l
+ src1
[i
] - lt
) & 0xFF) + diff
[i
];
63 static int add_hfyu_left_pred_c(uint8_t *dst
, const uint8_t *src
, int w
,
68 for (i
= 0; i
< w
- 1; i
++) {
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
++) {
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
;
131 ff_huffyuvdsp_init_ppc(c
);
133 ff_huffyuvdsp_init_x86(c
);