chroma_yuv.c 9.01 KB
Newer Older
1
/*****************************************************************************
Pere Orga's avatar
Pere Orga committed
2
 * chroma_yuv.c : ARM NEONv1 YUV 4:2:0 to YUV :2:2 chroma conversion for VLC
3 4 5 6
 *****************************************************************************
 * Copyright (C) 2009 Rémi Denis-Courmont
 *
 * This program is free software; you can redistribute it and/or modify
7 8
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
9 10 11 12 13
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16 17 18
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 20 21 22 23 24 25 26 27
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_filter.h>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
28
#include <vlc_cpu.h>
29
#include "chroma_neon.h"
30 31 32 33 34 35 36 37 38

static int Open (vlc_object_t *);

vlc_module_begin ()
    set_description (N_("ARM NEON video chroma conversions"))
    set_capability ("video filter2", 250)
    set_callbacks (Open, NULL)
vlc_module_end ()

39 40 41 42 43 44 45 46
#define DEFINE_PACK(pack, pict) \
    struct yuv_pack pack = { (pict)->Y_PIXELS, (pict)->Y_PITCH }
#define DEFINE_PLANES(planes, pict) \
    struct yuv_planes planes = { \
        (pict)->Y_PIXELS, (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->Y_PITCH }
#define DEFINE_PLANES_SWAP(planes, pict) \
    struct yuv_planes planes = { \
        (pict)->Y_PIXELS, (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->Y_PITCH }
47

48
/* Planar YUV420 to packed YUV422 */
49 50
static void I420_YUYV (filter_t *filter, picture_t *src, picture_t *dst)
{
51 52 53 54
    DEFINE_PACK(out, dst);
    DEFINE_PLANES(in, src);
    i420_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
55
}
56 57
VIDEO_FILTER_WRAPPER (I420_YUYV)

58
static void I420_YVYU (filter_t *filter, picture_t *src, picture_t *dst)
59
{
60 61 62 63
    DEFINE_PACK(out, dst);
    DEFINE_PLANES_SWAP(in, src);
    i420_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
64
}
65
VIDEO_FILTER_WRAPPER (I420_YVYU)
66 67 68

static void I420_UYVY (filter_t *filter, picture_t *src, picture_t *dst)
{
69 70 71 72
    DEFINE_PACK(out, dst);
    DEFINE_PLANES(in, src);
    i420_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
73 74 75
}
VIDEO_FILTER_WRAPPER (I420_UYVY)

76
static void I420_VYUY (filter_t *filter, picture_t *src, picture_t *dst)
77
{
78 79 80 81
    DEFINE_PACK(out, dst);
    DEFINE_PLANES_SWAP(in, src);
    i420_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
82
}
83
VIDEO_FILTER_WRAPPER (I420_VYUY)
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

/* Planar YUV422 to packed YUV422 */
static void I422_YUYV (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PACK(out, dst);
    DEFINE_PLANES(in, src);
    i422_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (I422_YUYV)

static void I422_YVYU (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PACK(out, dst);
    DEFINE_PLANES_SWAP(in, src);
    i422_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (I422_YVYU)

static void I422_UYVY (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PACK(out, dst);
    DEFINE_PLANES(in, src);
    i422_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (I422_UYVY)

static void I422_VYUY (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PACK(out, dst);
    DEFINE_PLANES_SWAP(in, src);
    i422_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (I422_VYUY)


124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
/* Packedr YUV422 to planar YUV422 */
static void YUYV_I422 (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PLANES(out, dst);
    DEFINE_PACK(in, src);
    yuyv_i422_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (YUYV_I422)

static void YVYU_I422 (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PLANES_SWAP(out, dst);
    DEFINE_PACK(in, src);
    yuyv_i422_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (YVYU_I422)

static void UYVY_I422 (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PLANES(out, dst);
    DEFINE_PACK(in, src);
    uyvy_i422_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (UYVY_I422)

static void VYUY_I422 (filter_t *filter, picture_t *src, picture_t *dst)
{
    DEFINE_PLANES_SWAP(out, dst);
    DEFINE_PACK(in, src);
    uyvy_i422_neon (&out, &in, filter->fmt_in.video.i_width,
                    filter->fmt_in.video.i_height);
}
VIDEO_FILTER_WRAPPER (VYUY_I422)

161 162 163 164
static int Open (vlc_object_t *obj)
{
    filter_t *filter = (filter_t *)obj;

165
    if (!vlc_CPU_ARM_NEON())
166
        return VLC_EGENERIC;
167
    if ((filter->fmt_in.video.i_width != filter->fmt_out.video.i_width)
168 169 170 171 172
     || (filter->fmt_in.video.i_height != filter->fmt_out.video.i_height))
        return VLC_EGENERIC;

    switch (filter->fmt_in.video.i_chroma)
    {
173
        /* Planar to packed */
174 175 176 177 178 179 180 181 182
        case VLC_CODEC_I420:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_YUYV:
                    filter->pf_video_filter = I420_YUYV_Filter;
                    break;
                case VLC_CODEC_UYVY:
                    filter->pf_video_filter = I420_UYVY_Filter;
                    break;
183 184 185 186 187 188
                case VLC_CODEC_YVYU:
                    filter->pf_video_filter = I420_YVYU_Filter;
                    break;
                case VLC_CODEC_VYUY:
                    filter->pf_video_filter = I420_VYUY_Filter;
                    break;
189 190 191 192 193
                default:
                    return VLC_EGENERIC;
            }
            break;

194 195 196 197
        case VLC_CODEC_YV12:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_YUYV:
198
                    filter->pf_video_filter = I420_YVYU_Filter;
199 200
                    break;
                case VLC_CODEC_UYVY:
201 202 203 204 205 206 207
                    filter->pf_video_filter = I420_VYUY_Filter;
                    break;
                case VLC_CODEC_YVYU:
                    filter->pf_video_filter = I420_YUYV_Filter;
                    break;
                case VLC_CODEC_VYUY:
                    filter->pf_video_filter = I420_UYVY_Filter;
208 209 210 211 212 213
                    break;
                default:
                    return VLC_EGENERIC;
            }
            break;

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
        case VLC_CODEC_I422:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_YUYV:
                    filter->pf_video_filter = I422_YUYV_Filter;
                    break;
                case VLC_CODEC_UYVY:
                    filter->pf_video_filter = I422_UYVY_Filter;
                    break;
                case VLC_CODEC_YVYU:
                    filter->pf_video_filter = I422_YVYU_Filter;
                    break;
                case VLC_CODEC_VYUY:
                    filter->pf_video_filter = I422_VYUY_Filter;
                    break;
                default:
                    return VLC_EGENERIC;
            }
            break;

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        /* Packed to planar */
        case VLC_CODEC_YUYV:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_I422:
                    filter->pf_video_filter = YUYV_I422_Filter;
                    break;
                default:
                    return VLC_EGENERIC;
            }

        case VLC_CODEC_UYVY:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_I422:
                    filter->pf_video_filter = UYVY_I422_Filter;
                    break;
                default:
                    return VLC_EGENERIC;
            }

        case VLC_CODEC_YVYU:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_I422:
                    filter->pf_video_filter = YVYU_I422_Filter;
                    break;
                default:
                    return VLC_EGENERIC;
            }


        case VLC_CODEC_VYUY:
            switch (filter->fmt_out.video.i_chroma)
            {
                case VLC_CODEC_I422:
                    filter->pf_video_filter = VYUY_I422_Filter;
                    break;
                default:
                    return VLC_EGENERIC;
            }

276 277 278 279 280
        default:
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}