2 * This file is part of FFmpeg.
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.
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.
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
20 #include "libavutil/attributes.h"
21 #include "huffyuvencdsp.h"
24 static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w){
26 #if !HAVE_FAST_UNALIGNED
27 if((long)src2 & (sizeof(long)-1)){
28 for(i=0; i+3<w; i+=4){
29 dst[i+0] = (src1[i+0]-src2[i+0]) & mask;
30 dst[i+1] = (src1[i+1]-src2[i+1]) & mask;
31 dst[i+2] = (src1[i+2]-src2[i+2]) & mask;
32 dst[i+3] = (src1[i+3]-src2[i+3]) & mask;
37 unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL;
38 unsigned long pw_msb = pw_lsb + 0x0001000100010001ULL;
40 for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
41 long a = *(long*)(src1+i);
42 long b = *(long*)(src2+i);
43 *(long*)(dst+i) = ((a|pw_msb) - (b&pw_lsb)) ^ ((a^b^pw_msb)&pw_msb);
47 dst[i] = (src1[i] - src2[i]) & mask;
50 static void sub_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w, int *left, int *left_top){
58 const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & mask);
61 dst[i] = (l - pred) & mask;
68 av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c, AVCodecContext *avctx)
70 c->diff_int16 = diff_int16_c;
71 c->sub_hfyu_median_pred_int16 = sub_hfyu_median_pred_int16_c;
74 ff_huffyuvencdsp_init_x86(c, avctx);