]> git.sesse.net Git - ffmpeg/blob - libavfilter/colorspacedsp.c
Merge commit 'e3453fd44480d903338c663238bf280215dd9a07'
[ffmpeg] / libavfilter / colorspacedsp.c
1 /*
2  * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "colorspacedsp.h"
22
23 #define SS_W 0
24 #define SS_H 0
25
26 #define BIT_DEPTH 8
27 #include "colorspacedsp_template.c"
28
29 #undef BIT_DEPTH
30 #define BIT_DEPTH 10
31 #include "colorspacedsp_template.c"
32
33 #undef BIT_DEPTH
34 #define BIT_DEPTH 12
35 #include "colorspacedsp_template.c"
36
37 #undef SS_W
38 #undef SS_H
39
40 #define SS_W 1
41 #define SS_H 0
42
43 #undef BIT_DEPTH
44 #define BIT_DEPTH 8
45 #include "colorspacedsp_template.c"
46
47 #undef BIT_DEPTH
48 #define BIT_DEPTH 10
49 #include "colorspacedsp_template.c"
50
51 #undef BIT_DEPTH
52 #define BIT_DEPTH 12
53 #include "colorspacedsp_template.c"
54
55 #undef SS_W
56 #undef SS_H
57
58 #define SS_W 1
59 #define SS_H 1
60
61 #undef BIT_DEPTH
62 #define BIT_DEPTH 8
63 #include "colorspacedsp_template.c"
64
65 #undef BIT_DEPTH
66 #define BIT_DEPTH 10
67 #include "colorspacedsp_template.c"
68
69 #undef BIT_DEPTH
70 #define BIT_DEPTH 12
71 #include "colorspacedsp_template.c"
72
73 static void multiply3x3_c(int16_t *buf[3], ptrdiff_t stride,
74                           int w, int h, const int16_t m[3][3][8])
75 {
76     int y, x;
77     int16_t *buf0 = buf[0], *buf1 = buf[1], *buf2 = buf[2];
78
79     for (y = 0; y < h; y++) {
80         for (x = 0; x < w; x++) {
81             int v0 = buf0[x], v1 = buf1[x], v2 = buf2[x];
82
83             buf0[x] = av_clip_int16((m[0][0][0] * v0 + m[0][1][0] * v1 +
84                                      m[0][2][0] * v2 + 8192) >> 14);
85             buf1[x] = av_clip_int16((m[1][0][0] * v0 + m[1][1][0] * v1 +
86                                      m[1][2][0] * v2 + 8192) >> 14);
87             buf2[x] = av_clip_int16((m[2][0][0] * v0 + m[2][1][0] * v1 +
88                                      m[2][2][0] * v2 + 8192) >> 14);
89         }
90
91         buf0 += stride;
92         buf1 += stride;
93         buf2 += stride;
94     }
95 }
96
97 void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
98 {
99 #define init_yuv2rgb_fn(idx, bit) \
100     dsp->yuv2rgb[idx][0] = yuv2rgb_444p##bit##_c; \
101     dsp->yuv2rgb[idx][1] = yuv2rgb_422p##bit##_c; \
102     dsp->yuv2rgb[idx][2] = yuv2rgb_420p##bit##_c
103
104     init_yuv2rgb_fn(0,  8);
105     init_yuv2rgb_fn(1, 10);
106     init_yuv2rgb_fn(2, 12);
107
108 #define init_rgb2yuv_fn(idx, bit) \
109     dsp->rgb2yuv[idx][0] = rgb2yuv_444p##bit##_c; \
110     dsp->rgb2yuv[idx][1] = rgb2yuv_422p##bit##_c; \
111     dsp->rgb2yuv[idx][2] = rgb2yuv_420p##bit##_c
112
113     init_rgb2yuv_fn(0,  8);
114     init_rgb2yuv_fn(1, 10);
115     init_rgb2yuv_fn(2, 12);
116
117 #define init_yuv2yuv_fn(idx1, idx2, bit1, bit2) \
118     dsp->yuv2yuv[idx1][idx2][0] = yuv2yuv_444p##bit1##to##bit2##_c; \
119     dsp->yuv2yuv[idx1][idx2][1] = yuv2yuv_422p##bit1##to##bit2##_c; \
120     dsp->yuv2yuv[idx1][idx2][2] = yuv2yuv_420p##bit1##to##bit2##_c
121 #define init_yuv2yuv_fns(idx1, bit1) \
122     init_yuv2yuv_fn(idx1, 0, bit1,  8); \
123     init_yuv2yuv_fn(idx1, 1, bit1, 10); \
124     init_yuv2yuv_fn(idx1, 2, bit1, 12)
125
126     init_yuv2yuv_fns(0,  8);
127     init_yuv2yuv_fns(1, 10);
128     init_yuv2yuv_fns(2, 12);
129
130     dsp->multiply3x3 = multiply3x3_c;
131
132     if (ARCH_X86)
133         ff_colorspacedsp_x86_init(dsp);
134 }