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>
29 #include "arm_neon/chroma_neon.h"
31 static int Open (vlc_object_t
*);
34 set_description (N_("ARM NEON video chroma conversions"))
35 set_capability ("video filter2", 250)
36 set_callbacks (Open
, NULL
)
39 #define DEFINE_PACK(pack, pict) \
40 struct yuv_pack pack = { (pict)->Y_PIXELS, (pict)->Y_PITCH }
41 #define DEFINE_PLANES(planes, pict) \
42 struct yuv_planes planes = { \
43 (pict)->Y_PIXELS, (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->Y_PITCH }
44 #define DEFINE_PLANES_SWAP(planes, pict) \
45 struct yuv_planes planes = { \
46 (pict)->Y_PIXELS, (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->Y_PITCH }
48 #define DEFINE_UV_PLANES(planes, pict) \
49 struct uv_planes planes = { \
50 (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->U_PITCH }
51 #define DEFINE_UV_PLANES_SWAP(planes, pict) \
52 struct uv_planes planes = { \
53 (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->U_PITCH }
54 #define DEFINE_UV_PACK(pack, pict) \
55 struct yuv_pack pack = { (pict)->U_PIXELS, (pict)->U_PITCH }
57 /* Planar YUV420 to packed YUV422 */
58 static void I420_YUYV (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
60 DEFINE_PACK(out
, dst
);
61 DEFINE_PLANES(in
, src
);
62 i420_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
63 filter
->fmt_in
.video
.i_height
);
65 VIDEO_FILTER_WRAPPER (I420_YUYV
)
67 static void I420_YVYU (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
69 DEFINE_PACK(out
, dst
);
70 DEFINE_PLANES_SWAP(in
, src
);
71 i420_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
72 filter
->fmt_in
.video
.i_height
);
74 VIDEO_FILTER_WRAPPER (I420_YVYU
)
76 static void I420_UYVY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
78 DEFINE_PACK(out
, dst
);
79 DEFINE_PLANES(in
, src
);
80 i420_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
81 filter
->fmt_in
.video
.i_height
);
83 VIDEO_FILTER_WRAPPER (I420_UYVY
)
85 static void I420_VYUY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
87 DEFINE_PACK(out
, dst
);
88 DEFINE_PLANES_SWAP(in
, src
);
89 i420_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
90 filter
->fmt_in
.video
.i_height
);
92 VIDEO_FILTER_WRAPPER (I420_VYUY
)
95 /* Semiplanar NV12/21/16/24 to planar I420/YV12/I422/I444 */
96 static void copy_y_plane(filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
98 uint8_t *src_y
= src
->Y_PIXELS
;
99 uint8_t *dst_y
= dst
->Y_PIXELS
;
100 if (src
->Y_PITCH
== dst
->Y_PITCH
) {
101 memcpy(dst_y
, src_y
, dst
->Y_PITCH
* filter
->fmt_in
.video
.i_height
);
103 for (unsigned y
= 0; y
< filter
->fmt_in
.video
.i_height
;
104 y
++, dst_y
+= dst
->Y_PITCH
, src_y
+= src
->Y_PITCH
)
105 memcpy(dst_y
, src_y
, filter
->fmt_in
.video
.i_width
);
109 #define SEMIPLANAR_FILTERS(name, h_subsamp, v_subsamp) \
110 static void name (filter_t *filter, picture_t *src, \
113 DEFINE_UV_PLANES(out, dst); \
114 DEFINE_UV_PACK(in, src); \
115 copy_y_plane (filter, src, dst); \
116 deinterleave_chroma_neon (&out, &in, \
117 filter->fmt_in.video.i_width / h_subsamp, \
118 filter->fmt_in.video.i_height / v_subsamp); \
120 VIDEO_FILTER_WRAPPER (name) \
122 #define SEMIPLANAR_FILTERS_SWAP(name, h_subsamp, v_subsamp) \
123 static void name (filter_t *filter, picture_t *src, \
126 DEFINE_UV_PLANES_SWAP(out, dst); \
127 DEFINE_UV_PACK(in, src); \
128 copy_y_plane (filter, src, dst); \
129 deinterleave_chroma_neon (&out, &in, \
130 filter->fmt_in.video.i_width / h_subsamp, \
131 filter->fmt_in.video.i_height / v_subsamp); \
133 VIDEO_FILTER_WRAPPER (name) \
135 SEMIPLANAR_FILTERS (Semiplanar_Planar_420, 2, 2)
136 SEMIPLANAR_FILTERS_SWAP (Semiplanar_Planar_420_Swap
, 2, 2)
137 SEMIPLANAR_FILTERS (Semiplanar_Planar_422
, 2, 1)
138 SEMIPLANAR_FILTERS (Semiplanar_Planar_444
, 1, 1)
141 /* Planar YUV422 to packed YUV422 */
142 static void I422_YUYV (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
144 DEFINE_PACK(out
, dst
);
145 DEFINE_PLANES(in
, src
);
146 i422_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
147 filter
->fmt_in
.video
.i_height
);
149 VIDEO_FILTER_WRAPPER (I422_YUYV
)
151 static void I422_YVYU (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
153 DEFINE_PACK(out
, dst
);
154 DEFINE_PLANES_SWAP(in
, src
);
155 i422_yuyv_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
156 filter
->fmt_in
.video
.i_height
);
158 VIDEO_FILTER_WRAPPER (I422_YVYU
)
160 static void I422_UYVY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
162 DEFINE_PACK(out
, dst
);
163 DEFINE_PLANES(in
, src
);
164 i422_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
165 filter
->fmt_in
.video
.i_height
);
167 VIDEO_FILTER_WRAPPER (I422_UYVY
)
169 static void I422_VYUY (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
171 DEFINE_PACK(out
, dst
);
172 DEFINE_PLANES_SWAP(in
, src
);
173 i422_uyvy_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
174 filter
->fmt_in
.video
.i_height
);
176 VIDEO_FILTER_WRAPPER (I422_VYUY
)
179 /* Packed YUV422 to planar YUV422 */
180 static void YUYV_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
182 DEFINE_PLANES(out
, dst
);
183 DEFINE_PACK(in
, src
);
184 yuyv_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
185 filter
->fmt_in
.video
.i_height
);
187 VIDEO_FILTER_WRAPPER (YUYV_I422
)
189 static void YVYU_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
191 DEFINE_PLANES_SWAP(out
, dst
);
192 DEFINE_PACK(in
, src
);
193 yuyv_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
194 filter
->fmt_in
.video
.i_height
);
196 VIDEO_FILTER_WRAPPER (YVYU_I422
)
198 static void UYVY_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
200 DEFINE_PLANES(out
, dst
);
201 DEFINE_PACK(in
, src
);
202 uyvy_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
203 filter
->fmt_in
.video
.i_height
);
205 VIDEO_FILTER_WRAPPER (UYVY_I422
)
207 static void VYUY_I422 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
209 DEFINE_PLANES_SWAP(out
, dst
);
210 DEFINE_PACK(in
, src
);
211 uyvy_i422_neon (&out
, &in
, filter
->fmt_in
.video
.i_width
,
212 filter
->fmt_in
.video
.i_height
);
214 VIDEO_FILTER_WRAPPER (VYUY_I422
)
216 static int Open (vlc_object_t
*obj
)
218 filter_t
*filter
= (filter_t
*)obj
;
220 if (!vlc_CPU_ARM_NEON())
222 if ((filter
->fmt_in
.video
.i_width
!= filter
->fmt_out
.video
.i_width
)
223 || (filter
->fmt_in
.video
.i_height
!= filter
->fmt_out
.video
.i_height
))
226 switch (filter
->fmt_in
.video
.i_chroma
)
228 /* Planar to packed */
230 switch (filter
->fmt_out
.video
.i_chroma
)
233 filter
->pf_video_filter
= I420_YUYV_Filter
;
236 filter
->pf_video_filter
= I420_UYVY_Filter
;
239 filter
->pf_video_filter
= I420_YVYU_Filter
;
242 filter
->pf_video_filter
= I420_VYUY_Filter
;
250 switch (filter
->fmt_out
.video
.i_chroma
)
253 filter
->pf_video_filter
= I420_YVYU_Filter
;
256 filter
->pf_video_filter
= I420_VYUY_Filter
;
259 filter
->pf_video_filter
= I420_YUYV_Filter
;
262 filter
->pf_video_filter
= I420_UYVY_Filter
;
270 switch (filter
->fmt_out
.video
.i_chroma
)
273 filter
->pf_video_filter
= I422_YUYV_Filter
;
276 filter
->pf_video_filter
= I422_UYVY_Filter
;
279 filter
->pf_video_filter
= I422_YVYU_Filter
;
282 filter
->pf_video_filter
= I422_VYUY_Filter
;
289 /* Semiplanar to planar */
291 switch (filter
->fmt_out
.video
.i_chroma
)
294 filter
->pf_video_filter
= Semiplanar_Planar_420_Filter
;
297 filter
->pf_video_filter
= Semiplanar_Planar_420_Swap_Filter
;
305 switch (filter
->fmt_out
.video
.i_chroma
)
308 filter
->pf_video_filter
= Semiplanar_Planar_420_Swap_Filter
;
311 filter
->pf_video_filter
= Semiplanar_Planar_420_Filter
;
319 switch (filter
->fmt_out
.video
.i_chroma
)
322 filter
->pf_video_filter
= Semiplanar_Planar_422_Filter
;
330 switch (filter
->fmt_out
.video
.i_chroma
)
333 filter
->pf_video_filter
= Semiplanar_Planar_444_Filter
;
340 /* Packed to planar */
342 switch (filter
->fmt_out
.video
.i_chroma
)
345 filter
->pf_video_filter
= YUYV_I422_Filter
;
352 switch (filter
->fmt_out
.video
.i_chroma
)
355 filter
->pf_video_filter
= UYVY_I422_Filter
;
362 switch (filter
->fmt_out
.video
.i_chroma
)
365 filter
->pf_video_filter
= YVYU_I422_Filter
;
373 switch (filter
->fmt_out
.video
.i_chroma
)
376 filter
->pf_video_filter
= VYUY_I422_Filter
;