image_convert.c 3.5 KB
Newer Older
Z
Zhang Rui 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*****************************************************************************
 * yuv_rgb.c : ARM NEONv1 YUV to RGB32 chroma conversion for VLC
 *****************************************************************************
 * Copyright (C) 2011 Sébastien Toque
 *                    Rémi Denis-Courmont
 * Copyright (C) 2013 Zhang Rui <bbcallen@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify 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
 * (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
 * GNU Lesser General Public License for more details.
 *
 * 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.
 *****************************************************************************/

#include "../ijksdl_image_convert.h"

#include <cpu-features.h>
#include "chroma_neon.h"

static void ijk_i420_rgb32_neon(int width, int height, uint8_t **dst_data, int *dst_linesize, const uint8_t **src_data, int *src_linesize)
{
    struct yuv_pack out = { dst_data[0], dst_linesize[0] };
    struct yuv_planes_in in = { src_data[0], src_data[1], src_data[2], src_linesize[0] };
    i420_rgb_neon(&out, &in, width, height);
}

static void ijk_i420_rgb16_neon(int width, int height, uint8_t **dst_data, int *dst_linesize, const uint8_t **src_data, int *src_linesize)
{
    struct yuv_pack out = { dst_data[0], dst_linesize[0] };
    struct yuv_planes_in in = { src_data[0], src_data[1], src_data[2], src_linesize[0] };
    i420_rv16_neon(&out, &in, width, height);
}

Z
Zhang Rui 已提交
42
// TODO: 9 need nv12 and nv21 test sample
Z
Zhang Rui 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#if 0
static void ijk_nv21_rgb32_neon(int width, int height, uint8_t **dst_data, int *dst_linesize, const uint8_t **src_data, int *src_linesize)
{
    struct yuv_pack out = {dst_data[0], dst_linesize[0]};
    struct yuv_planes_in in = {src_data[0], src_data[1], src_data[2], src_linesize[0]};
    nv21_rgb_neon(&out, &in, width, height);
}

static void ijk_nv12_rgb32_neon(int width, int height, uint8_t **dst_data, int *dst_linesize, const uint8_t **src_data, int *src_linesize)
{
    struct yuv_pack out = {dst_data[0], dst_linesize[0]};
    struct yuv_planes_in in = {src_data[0], src_data[1], src_data[2], src_linesize[0]};
    nv12_rgb_neon(&out, &in, width, height);
}
#endif

int ijk_image_convert(int width, int height,
    enum AVPixelFormat dst_format, uint8_t **dst_data, int *dst_linesize,
    enum AVPixelFormat src_format, const uint8_t **src_data, int *src_linesize)
{
    if (!(android_getCpuFeatures() & (ANDROID_CPU_ARM_FEATURE_ARMv7 | ANDROID_CPU_ARM_FEATURE_NEON)))
        return -1;

    switch (src_format) {
    case AV_PIX_FMT_YUV420P:
Z
Zhang Rui 已提交
68
    case AV_PIX_FMT_YUVJ420P: // FIXME: 9 not equal to AV_PIX_FMT_YUV420P, but a workaround
Z
Zhang Rui 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        switch (dst_format) {
        case AV_PIX_FMT_RGB565:
            ijk_i420_rgb16_neon(width, height, dst_data, dst_linesize, src_data, src_linesize);
            return 0;
            break;
        case AV_PIX_FMT_0BGR32:
            ijk_i420_rgb32_neon(width, height, dst_data, dst_linesize, src_data, src_linesize);
            return 0;
        default:
            break;
        }
        break;
    default:
        break;
    }

    return -1;
}