]> git.sesse.net Git - vlc/blob - modules/video_filter/rv32.c
68ef70f3469d67506a9aa072c80ac18991656e7a
[vlc] / modules / video_filter / rv32.c
1 /*****************************************************************************
2  * rv32.c: conversion plugin to RV32 format.
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Author: Cyril Deguet <asmax@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout.h>
34 #include "vlc_filter.h"
35
36 /*****************************************************************************
37  * filter_sys_t : filter descriptor
38  *****************************************************************************/
39 struct filter_sys_t
40 {
41     es_format_t fmt_in;
42     es_format_t fmt_out;
43 };
44
45 /****************************************************************************
46  * Local prototypes
47  ****************************************************************************/
48 static int  OpenFilter ( vlc_object_t * );
49 static void CloseFilter( vlc_object_t * );
50
51 static picture_t *Filter( filter_t *, picture_t * );
52
53 /*****************************************************************************
54  * Module descriptor
55  *****************************************************************************/
56 vlc_module_begin ()
57     set_description( N_("RV32 conversion filter") )
58     set_capability( "video filter2", 1 )
59     set_callbacks( OpenFilter, CloseFilter )
60 vlc_module_end ()
61
62 /*****************************************************************************
63  * OpenFilter: probe the filter and return score
64  *****************************************************************************/
65 static int OpenFilter( vlc_object_t *p_this )
66 {
67     filter_t *p_filter = (filter_t*)p_this;
68     filter_sys_t *p_sys;
69
70     /* XXX Only support RV24 -> RV32 conversion */
71     if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','V','2','4') ||
72         (p_filter->fmt_out.video.i_chroma != VLC_FOURCC('R', 'V', '3', '2') &&
73         p_filter->fmt_out.video.i_chroma != VLC_FOURCC('R', 'G', 'B', 'A')) )
74     {
75         return VLC_EGENERIC;
76     }
77
78     if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
79      || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
80         return -1;
81
82     /* Allocate the memory needed to store the decoder's structure */
83     if( ( p_filter->p_sys = p_sys =
84           (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
85         return VLC_ENOMEM;
86
87     p_filter->pf_video_filter = Filter;
88
89     return VLC_SUCCESS;
90 }
91
92 /*****************************************************************************
93  * CloseFilter: clean up the filter
94  *****************************************************************************/
95 static void CloseFilter( vlc_object_t *p_this )
96 {
97     filter_t *p_filter = (filter_t*)p_this;
98     filter_sys_t *p_sys = p_filter->p_sys;
99
100     free( p_sys );
101 }
102
103 /****************************************************************************
104  * Filter: the whole thing
105  ****************************************************************************/
106 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
107 {
108     picture_t *p_pic_dst;
109     int i_plane, i;
110     unsigned int j;
111
112     /* Request output picture */
113     p_pic_dst = filter_NewPicture( p_filter );
114     if( !p_pic_dst )
115     {
116         picture_Release( p_pic );
117         return NULL;
118     }
119
120     /* Convert RV24 to RV32 */
121     for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ )
122     {
123         uint8_t *p_src = p_pic->p[i_plane].p_pixels;
124         uint8_t *p_dst = p_pic_dst->p[i_plane].p_pixels;
125         unsigned int i_width = p_filter->fmt_out.video.i_width;
126
127         for( i = 0; i < p_pic_dst->p[i_plane].i_lines; i++ )
128         {
129             for( j = 0; j < i_width; j++ )
130             {
131                 *(p_dst++) = p_src[2];
132                 *(p_dst++) = p_src[1];
133                 *(p_dst++) = p_src[0];
134                 *(p_dst++) = 0xff;  /* Alpha */
135                 p_src += 3;
136             }
137             p_src += p_pic->p[i_plane].i_pitch - 3 * i_width;
138             p_dst += p_pic_dst->p[i_plane].i_pitch - 4 * i_width;
139         }
140     }
141
142     picture_CopyProperties( p_pic_dst, p_pic );
143     picture_Release( p_pic );
144
145     return p_pic_dst;
146 }
147