1 /*****************************************************************************
2 * yuv_rgb.c : ARM NEONv1 YUV to RGB32 chroma conversion for VLC
3 *****************************************************************************
4 * Copyright (C) 2011 Sébastien Toque
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
26 #include <vlc_common.h>
27 #include <vlc_plugin.h>
28 #include <vlc_filter.h>
29 #include <vlc_picture.h>
31 #include "arm_neon/chroma_neon.h"
33 static int Open (vlc_object_t
*);
36 set_description (N_("ARM NEON video chroma YUV->RGBA"))
37 set_capability ("video converter", 250)
38 set_callbacks (Open
, NULL
)
42 static int CoefY[256];
43 static int CoefRV[256];
44 static int CoefGU[256];
45 static int CoefGV[256];
46 static int CoefBU[256];
48 // C reference version of the converter
49 static void I420_RGBA_C (filter_t *filter, picture_t *src, picture_t *dst)
51 const uint8_t *const out = dst->p->p_pixels;
52 const size_t width = src->p[Y_PLANE].i_visible_pitch;
53 const size_t height = src->p[Y_PLANE].i_visible_lines;
55 const int ypitch = src->p[Y_PLANE].i_pitch;
56 const int uvpitch = src->p[U_PLANE].i_pitch;
57 const int dpitch = dst->p->i_pitch / dst->p->i_pixel_pitch;
59 for (size_t j = 0; j < height; ++j)
61 const int y = j * ypitch;
62 const int u = (j>>1) * uvpitch;
63 const int d = j * dpitch;
65 for (size_t i = 0; i < width; ++i)
67 uint8_t Y = src->Y_PIXELS[y + i];
68 uint8_t U = src->U_PIXELS[u + (i>>1)];
69 uint8_t V = src->V_PIXELS[u + (i>>1)];
71 //coef = float * Precision + .5 (Precision=32768)
72 int R = CoefY[Y] + CoefRV[V];
73 int G = CoefY[Y] + CoefGU[U] + CoefGV[V];
74 int B = CoefY[Y] + CoefBU[U];
76 //rgb = (rgb+Precision/2) / Precision (Precision=32768)
81 if (unlikely(R < 0)) R = 0;
82 if (unlikely(G < 0)) G = 0;
83 if (unlikely(B < 0)) B = 0;
84 if (unlikely(R > 255)) R = 255;
85 if (unlikely(G > 255)) G = 255;
86 if (unlikely(B > 255)) B = 255;
88 ((uint32_t*)out)[d + i] = R | (G<<8) | (B<<16) | (0xff<<24);
93 static void I420_RGBA (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
95 struct yuv_pack out
= { dst
->p
->p_pixels
, dst
->p
->i_pitch
};
96 struct yuv_planes in
= { src
->Y_PIXELS
, src
->U_PIXELS
, src
->V_PIXELS
, src
->Y_PITCH
};
97 i420_rgb_neon (&out
, &in
, filter
->fmt_in
.video
.i_visible_width
, filter
->fmt_in
.video
.i_visible_height
);
100 static void I420_RV16 (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
102 struct yuv_pack out
= { dst
->p
->p_pixels
, dst
->p
->i_pitch
};
103 struct yuv_planes in
= { src
->Y_PIXELS
, src
->U_PIXELS
, src
->V_PIXELS
, src
->Y_PITCH
};
104 i420_rv16_neon (&out
, &in
, filter
->fmt_in
.video
.i_visible_width
, filter
->fmt_in
.video
.i_visible_height
);
107 static void YV12_RGBA (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
109 struct yuv_pack out
= { dst
->p
->p_pixels
, dst
->p
->i_pitch
};
110 struct yuv_planes in
= { src
->Y_PIXELS
, src
->V_PIXELS
, src
->U_PIXELS
, src
->Y_PITCH
};
111 i420_rgb_neon (&out
, &in
, filter
->fmt_in
.video
.i_visible_width
, filter
->fmt_in
.video
.i_visible_height
);
114 static void NV21_RGBA (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
116 struct yuv_pack out
= { dst
->p
->p_pixels
, dst
->p
->i_pitch
};
117 struct yuv_planes in
= { src
->Y_PIXELS
, src
->U_PIXELS
, src
->V_PIXELS
, src
->Y_PITCH
};
118 nv21_rgb_neon (&out
, &in
, filter
->fmt_in
.video
.i_visible_width
, filter
->fmt_in
.video
.i_visible_height
);
121 static void NV12_RGBA (filter_t
*filter
, picture_t
*src
, picture_t
*dst
)
123 struct yuv_pack out
= { dst
->p
->p_pixels
, dst
->p
->i_pitch
};
124 struct yuv_planes in
= { src
->Y_PIXELS
, src
->U_PIXELS
, src
->V_PIXELS
, src
->Y_PITCH
};
125 nv12_rgb_neon (&out
, &in
, filter
->fmt_in
.video
.i_visible_width
, filter
->fmt_in
.video
.i_visible_height
);
128 VIDEO_FILTER_WRAPPER (I420_RGBA
)
129 VIDEO_FILTER_WRAPPER (I420_RV16
)
130 VIDEO_FILTER_WRAPPER (YV12_RGBA
)
131 VIDEO_FILTER_WRAPPER (NV21_RGBA
)
132 VIDEO_FILTER_WRAPPER (NV12_RGBA
)
134 static int Open (vlc_object_t
*obj
)
136 filter_t
*filter
= (filter_t
*)obj
;
138 if (!vlc_CPU_ARM_NEON())
141 if (((filter
->fmt_in
.video
.i_width
| filter
->fmt_in
.video
.i_height
) & 1)
142 || (filter
->fmt_in
.video
.i_width
!= filter
->fmt_out
.video
.i_width
)
143 || (filter
->fmt_in
.video
.i_height
!= filter
->fmt_out
.video
.i_height
)
144 || (filter
->fmt_in
.video
.orientation
!= filter
->fmt_out
.video
.orientation
))
147 switch (filter
->fmt_out
.video
.i_chroma
)
149 case VLC_CODEC_RGB16
:
150 switch (filter
->fmt_in
.video
.i_chroma
)
153 filter
->pf_video_filter
= I420_RV16_Filter
;
160 case VLC_CODEC_RGB32
:
161 if( filter
->fmt_out
.video
.i_rmask
!= 0x000000ff
162 || filter
->fmt_out
.video
.i_gmask
!= 0x0000ff00
163 || filter
->fmt_out
.video
.i_bmask
!= 0x00ff0000 )
166 switch (filter
->fmt_in
.video
.i_chroma
)
169 filter
->pf_video_filter
= I420_RGBA_Filter
;
172 filter
->pf_video_filter
= YV12_RGBA_Filter
;
175 filter
->pf_video_filter
= NV21_RGBA_Filter
;
178 filter
->pf_video_filter
= NV12_RGBA_Filter
;
189 //precompute some values for the C version
190 /*const int coefY = (int)(1.164 * 32768 + 0.5);
191 const int coefRV = (int)(1.793 * 32768 + 0.5);
192 const int coefGU = (int)(0.213 * 32768 + 0.5);
193 const int coefGV = (int)(0.533 * 32768 + 0.5);
194 const int coefBU = (int)(2.113 * 32768 + 0.5);
195 for (int i=0; i<256; ++i)
197 CoefY[i] = coefY * (i-16) + 16384;
198 CoefRV[i] = coefRV*(i-128);
199 CoefGU[i] = -coefGU*(i-128);
200 CoefGV[i] = -coefGV*(i-128);
201 CoefBU[i] = coefBU*(i-128);
204 msg_Dbg(filter
, "%4.4s(%dx%d) to %4.4s(%dx%d)",
205 (char*)&filter
->fmt_in
.video
.i_chroma
, filter
->fmt_in
.video
.i_visible_width
, filter
->fmt_in
.video
.i_visible_height
,
206 (char*)&filter
->fmt_out
.video
.i_chroma
, filter
->fmt_out
.video
.i_visible_width
, filter
->fmt_out
.video
.i_visible_height
);