]> git.sesse.net Git - ffmpeg/blob - libavcodec/huffyuvdsp.c
Merge commit '4efab89332ea39a77145e8b15562b981d9dbde68'
[ffmpeg] / libavcodec / huffyuvdsp.c
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 <stdint.h>
20
21 #include "config.h"
22 #include "libavutil/attributes.h"
23 #include "mathops.h"
24 #include "huffyuvdsp.h"
25
26 static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
27     long i;
28     unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL;
29     unsigned long pw_msb = pw_lsb +  0x0001000100010001ULL;
30     for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
31         long a = *(long*)(src+i);
32         long b = *(long*)(dst+i);
33         *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb);
34     }
35     for(; i<w; i++)
36         dst[i] = (dst[i] + src[i]) & mask;
37 }
38
39 static void add_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top){
40     int i;
41     uint16_t l, lt;
42
43     l  = *left;
44     lt = *left_top;
45
46     for(i=0; i<w; i++){
47         l  = (mid_pred(l, src[i], (l + src[i] - lt) & mask) + diff[i]) & mask;
48         lt = src[i];
49         dst[i] = l;
50     }
51
52     *left     = l;
53     *left_top = lt;
54 }
55
56 static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
57                                        intptr_t w, uint8_t *left)
58 {
59     int i;
60     uint8_t r = left[R], g = left[G], b = left[B], a = left[A];
61
62     for (i = 0; i < w; i++) {
63         b += src[4 * i + B];
64         g += src[4 * i + G];
65         r += src[4 * i + R];
66         a += src[4 * i + A];
67
68         dst[4 * i + B] = b;
69         dst[4 * i + G] = g;
70         dst[4 * i + R] = r;
71         dst[4 * i + A] = a;
72     }
73
74     left[B] = b;
75     left[G] = g;
76     left[R] = r;
77     left[A] = a;
78 }
79
80 av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c, AVCodecContext *avctx)
81 {
82     c->add_int16 = add_int16_c;
83     c->add_hfyu_median_pred_int16 = add_hfyu_median_pred_int16_c;
84     c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
85
86     if (ARCH_X86)
87         ff_huffyuvdsp_init_x86(c, avctx);
88 }