1 /*****************************************************************************
2 * chroma_yuv.c : ARM NEONv1 YUV 4:2:0 to YUV :2:2 chroma conversion for VLC
3 *****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_filter.h>
28 #include <vlc_picture.h>
30 #include "arm_neon/chroma_neon.h"
32 static int Open (vlc_object_t
*);
35 set_description (N_("ARM NEON video chroma conversions"))
36 set_capability ("video converter", 250)
37 set_callbacks (Open
, NULL
)
40 #define DEFINE_PACK(pack, pict) \
41 struct yuv_pack pack = { (pict)->Y_PIXELS, (pict)->Y_PITCH }
42 #define DEFINE_PLANES(planes, pict) \
43 struct yuv_planes planes = { \
44 (pict)->Y_PIXELS, (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->Y_PITCH }
45 #define DEFINE_PLANES_SWAP(planes, pict) \
46 struct yuv_planes planes = { \
47 (pict)->Y_PIXELS, (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->Y_PITCH }
49 #define DEFINE_UV_PLANES(planes, pict) \
50 struct uv_planes planes = { \
51 (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->U_PITCH }
52 #define DEFINE_UV_PLANES_SWAP(planes, pict) \
53 struct uv_planes planes = { \
54 (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->U_PITCH }
55 #define DEFINE_UV_PACK(pack, pict) \
56 struct yuv_pack pack = { (pict)->U_PIXELS, (pict)->U_PITCH }
58 /* Planar YUV420 to packed YUV422 */
59 static void I420_YUYV (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
61 DEFINE_PACK(out
, dst
);
62 DEFINE_PLANES(in
, src
);
63 i420_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
64 filter
->fmt_in
.video
.i_height
);
66 VIDEO_FILTER_WRAPPER (I420_YUYV
)
68 static void I420_YVYU (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
70 DEFINE_PACK(out
, dst
);
71 DEFINE_PLANES_SWAP(in
, src
);
72 i420_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
73 filter
->fmt_in
.video
.i_height
);
75 VIDEO_FILTER_WRAPPER (I420_YVYU
)
77 static void I420_UYVY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
79 DEFINE_PACK(out
, dst
);
80 DEFINE_PLANES(in
, src
);
81 i420_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
82 filter
->fmt_in
.video
.i_height
);
84 VIDEO_FILTER_WRAPPER (I420_UYVY
)
86 static void I420_VYUY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
88 DEFINE_PACK(out
, dst
);
89 DEFINE_PLANES_SWAP(in
, src
);
90 i420_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
91 filter
->fmt_in
.video
.i_height
);
93 VIDEO_FILTER_WRAPPER (I420_VYUY
)
96 /* Semiplanar NV12/21/16/24 to planar I420/YV12/I422/I444 */
97 static void copy_y_plane(filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
99 uint8_t *src_y
= src
->Y_PIXELS
;
100 uint8_t *dst_y
= dst
->Y_PIXELS
;
101 if (src
->Y_PITCH
== dst
->Y_PITCH
) {
102 memcpy(dst_y
, src_y
, dst
->Y_PITCH
* filter
->fmt_in
.video
.i_height
);
104 for (unsigned y
= 0; y
< filter
->fmt_in
.video
.i_height
;
105 y
++, dst_y
+= dst
->Y_PITCH
, src_y
+= src
->Y_PITCH
)
106 memcpy(dst_y
, src_y
, filter
->fmt_in
.video
.i_width
);
110 #define SEMIPLANAR_FILTERS(name, h_subsamp, v_subsamp) \
111 static void name (filter_t *filter, picture_t *src, \
114 DEFINE_UV_PLANES(out, dst); \
115 DEFINE_UV_PACK(in, src); \
116 copy_y_plane (filter, src, dst); \
117 deinterleave_chroma_neon (&out, &in, \
118 filter->fmt_in.video.i_width / h_subsamp, \
119 filter->fmt_in.video.i_height / v_subsamp); \
121 VIDEO_FILTER_WRAPPER (name) \
123 #define SEMIPLANAR_FILTERS_SWAP(name, h_subsamp, v_subsamp) \
124 static void name (filter_t *filter, picture_t *src, \
127 DEFINE_UV_PLANES_SWAP(out, dst); \
128 DEFINE_UV_PACK(in, src); \
129 copy_y_plane (filter, src, dst); \
130 deinterleave_chroma_neon (&out, &in, \
131 filter->fmt_in.video.i_width / h_subsamp, \
132 filter->fmt_in.video.i_height / v_subsamp); \
134 VIDEO_FILTER_WRAPPER (name) \
136 SEMIPLANAR_FILTERS (Semiplanar_Planar_420, 2, 2)
137 SEMIPLANAR_FILTERS_SWAP (Semiplanar_Planar_420_Swap
, 2, 2)
138 SEMIPLANAR_FILTERS (Semiplanar_Planar_422
, 2, 1)
139 SEMIPLANAR_FILTERS (Semiplanar_Planar_444
, 1, 1)
142 /* Planar YUV422 to packed YUV422 */
143 static void I422_YUYV (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
145 DEFINE_PACK(out
, dst
);
146 DEFINE_PLANES(in
, src
);
147 i422_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
148 filter
->fmt_in
.video
.i_height
);
150 VIDEO_FILTER_WRAPPER (I422_YUYV
)
152 static void I422_YVYU (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
154 DEFINE_PACK(out
, dst
);
155 DEFINE_PLANES_SWAP(in
, src
);
156 i422_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
157 filter
->fmt_in
.video
.i_height
);
159 VIDEO_FILTER_WRAPPER (I422_YVYU
)
161 static void I422_UYVY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
163 DEFINE_PACK(out
, dst
);
164 DEFINE_PLANES(in
, src
);
165 i422_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
166 filter
->fmt_in
.video
.i_height
);
168 VIDEO_FILTER_WRAPPER (I422_UYVY
)
170 static void I422_VYUY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
172 DEFINE_PACK(out
, dst
);
173 DEFINE_PLANES_SWAP(in
, src
);
174 i422_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
175 filter
->fmt_in
.video
.i_height
);
177 VIDEO_FILTER_WRAPPER (I422_VYUY
)
180 /* Packed YUV422 to planar YUV422 */
181 static void YUYV_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
183 DEFINE_PLANES(out
, dst
);
184 DEFINE_PACK(in
, src
);
185 yuyv_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
186 filter
->fmt_in
.video
.i_height
);
188 VIDEO_FILTER_WRAPPER (YUYV_I422
)
190 static void YVYU_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
192 DEFINE_PLANES_SWAP(out
, dst
);
193 DEFINE_PACK(in
, src
);
194 yuyv_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
195 filter
->fmt_in
.video
.i_height
);
197 VIDEO_FILTER_WRAPPER (YVYU_I422
)
199 static void UYVY_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
201 DEFINE_PLANES(out
, dst
);
202 DEFINE_PACK(in
, src
);
203 uyvy_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
204 filter
->fmt_in
.video
.i_height
);
206 VIDEO_FILTER_WRAPPER (UYVY_I422
)
208 static void VYUY_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
210 DEFINE_PLANES_SWAP(out
, dst
);
211 DEFINE_PACK(in
, src
);
212 uyvy_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
213 filter
->fmt_in
.video
.i_height
);
215 VIDEO_FILTER_WRAPPER (VYUY_I422
)
217 static int Open (vlc_object_t
*obj
)
219 filter_t
*filter
= (filter_t
*)obj
;
221 if (!vlc_CPU_ARM_NEON())
223 if ((filter
->fmt_in
.video
.i_width
!= filter
->fmt_out
.video
.i_width
)
224 || (filter
->fmt_in
.video
.i_height
!= filter
->fmt_out
.video
.i_height
))
227 switch (filter
->fmt_in
.video
.i_chroma
)
229 /* Planar to packed */
231 switch (filter
->fmt_out
.video
.i_chroma
)
234 filter
->pf_video_filter
= I420_YUYV_Filter
;
237 filter
->pf_video_filter
= I420_UYVY_Filter
;
240 filter
->pf_video_filter
= I420_YVYU_Filter
;
243 filter
->pf_video_filter
= I420_VYUY_Filter
;
251 switch (filter
->fmt_out
.video
.i_chroma
)
254 filter
->pf_video_filter
= I420_YVYU_Filter
;
257 filter
->pf_video_filter
= I420_VYUY_Filter
;
260 filter
->pf_video_filter
= I420_YUYV_Filter
;
263 filter
->pf_video_filter
= I420_UYVY_Filter
;
271 switch (filter
->fmt_out
.video
.i_chroma
)
274 filter
->pf_video_filter
= I422_YUYV_Filter
;
277 filter
->pf_video_filter
= I422_UYVY_Filter
;
280 filter
->pf_video_filter
= I422_YVYU_Filter
;
283 filter
->pf_video_filter
= I422_VYUY_Filter
;
290 /* Semiplanar to planar */
292 switch (filter
->fmt_out
.video
.i_chroma
)
295 filter
->pf_video_filter
= Semiplanar_Planar_420_Filter
;
298 filter
->pf_video_filter
= Semiplanar_Planar_420_Swap_Filter
;
306 switch (filter
->fmt_out
.video
.i_chroma
)
309 filter
->pf_video_filter
= Semiplanar_Planar_420_Swap_Filter
;
312 filter
->pf_video_filter
= Semiplanar_Planar_420_Filter
;
320 switch (filter
->fmt_out
.video
.i_chroma
)
323 filter
->pf_video_filter
= Semiplanar_Planar_422_Filter
;
331 switch (filter
->fmt_out
.video
.i_chroma
)
334 filter
->pf_video_filter
= Semiplanar_Planar_444_Filter
;
341 /* Packed to planar */
343 switch (filter
->fmt_out
.video
.i_chroma
)
346 filter
->pf_video_filter
= YUYV_I422_Filter
;
353 switch (filter
->fmt_out
.video
.i_chroma
)
356 filter
->pf_video_filter
= UYVY_I422_Filter
;
363 switch (filter
->fmt_out
.video
.i_chroma
)
366 filter
->pf_video_filter
= YVYU_I422_Filter
;
374 switch (filter
->fmt_out
.video
.i_chroma
)
377 filter
->pf_video_filter
= VYUY_I422_Filter
;