rv32.c 4.2 KB
Newer Older
1 2 3
/*****************************************************************************
 * rv32.c: conversion plugin to RV32 format.
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2005 VLC authors and VideoLAN
5 6 7 8
 * $Id$
 *
 * Author: Cyril Deguet <asmax@videolan.org>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
9 10 11
 * 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
12 13 14 15
 * (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
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
19 20 21
 * 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.
22 23 24 25 26
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
27 28 29 30
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

31
#include <vlc_common.h>
32
#include <vlc_plugin.h>
Rémi Duraffort's avatar
Rémi Duraffort committed
33
#include <vlc_filter.h>
34 35 36 37 38 39 40 41 42 43

/****************************************************************************
 * Local prototypes
 ****************************************************************************/
static int  OpenFilter ( vlc_object_t * );
static picture_t *Filter( filter_t *, picture_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
44 45 46
vlc_module_begin ()
    set_description( N_("RV32 conversion filter") )
    set_capability( "video filter2", 1 )
47
    set_callbacks( OpenFilter, NULL )
48
vlc_module_end ()
49 50 51 52 53 54 55 56 57

/*****************************************************************************
 * OpenFilter: probe the filter and return score
 *****************************************************************************/
static int OpenFilter( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t*)p_this;

    /* XXX Only support RV24 -> RV32 conversion */
58 59 60
    if( p_filter->fmt_in.video.i_chroma != VLC_CODEC_RGB24 ||
        (p_filter->fmt_out.video.i_chroma != VLC_CODEC_RGB32 &&
        p_filter->fmt_out.video.i_chroma != VLC_CODEC_RGBA) )
61 62 63 64
    {
        return VLC_EGENERIC;
    }

65
    if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
66 67
     || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height
     || p_filter->fmt_in.video.orientation != p_filter->fmt_out.video.orientation)
68 69
        return -1;

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    p_filter->pf_video_filter = Filter;

    return VLC_SUCCESS;
}

/****************************************************************************
 * Filter: the whole thing
 ****************************************************************************/
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{
    picture_t *p_pic_dst;
    int i_plane, i;
    unsigned int j;

    /* Request output picture */
Laurent Aimar's avatar
Laurent Aimar committed
85
    p_pic_dst = filter_NewPicture( p_filter );
86 87
    if( !p_pic_dst )
    {
88
        picture_Release( p_pic );
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
        return NULL;
    }

    /* Convert RV24 to RV32 */
    for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ )
    {
        uint8_t *p_src = p_pic->p[i_plane].p_pixels;
        uint8_t *p_dst = p_pic_dst->p[i_plane].p_pixels;
        unsigned int i_width = p_filter->fmt_out.video.i_width;

        for( i = 0; i < p_pic_dst->p[i_plane].i_lines; i++ )
        {
            for( j = 0; j < i_width; j++ )
            {
                *(p_dst++) = p_src[2];
                *(p_dst++) = p_src[1];
                *(p_dst++) = p_src[0];
                *(p_dst++) = 0xff;  /* Alpha */
                p_src += 3;
            }
            p_src += p_pic->p[i_plane].i_pitch - 3 * i_width;
            p_dst += p_pic_dst->p[i_plane].i_pitch - 4 * i_width;
        }
    }

114 115
    picture_CopyProperties( p_pic_dst, p_pic );
    picture_Release( p_pic );
116 117 118 119

    return p_pic_dst;
}