]> git.sesse.net Git - vlc/blob - modules/video_filter/rv32.c
Remove trailing space.
[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 #include <vlc/vlc.h>
28 #include <vlc_vout.h>
29 #include "vlc_filter.h"
30
31 /*****************************************************************************
32  * filter_sys_t : filter descriptor
33  *****************************************************************************/
34 struct filter_sys_t
35 {
36     es_format_t fmt_in;
37     es_format_t fmt_out;
38 };
39
40 /****************************************************************************
41  * Local prototypes
42  ****************************************************************************/
43 static int  OpenFilter ( vlc_object_t * );
44 static void CloseFilter( vlc_object_t * );
45
46 static picture_t *Filter( filter_t *, picture_t * );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51 vlc_module_begin();
52     set_description( _("RV32 conversion filter") );
53     set_capability( "video filter2", 1 );
54     set_callbacks( OpenFilter, CloseFilter );
55 vlc_module_end();
56
57 /*****************************************************************************
58  * OpenFilter: probe the filter and return score
59  *****************************************************************************/
60 static int OpenFilter( vlc_object_t *p_this )
61 {
62     filter_t *p_filter = (filter_t*)p_this;
63     filter_sys_t *p_sys;
64
65     /* XXX Only support RV24 -> RV32 conversion */
66     if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('R','V','2','4') ||
67         p_filter->fmt_out.video.i_chroma != VLC_FOURCC('R', 'V', '3', '2') )
68     {
69         return VLC_EGENERIC;
70     }
71
72     /* Allocate the memory needed to store the decoder's structure */
73     if( ( p_filter->p_sys = p_sys =
74           (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
75     {
76         msg_Err( p_filter, "out of memory" );
77         return VLC_EGENERIC;
78     }
79
80     p_filter->pf_video_filter = Filter;
81
82     return VLC_SUCCESS;
83 }
84
85 /*****************************************************************************
86  * CloseFilter: clean up the filter
87  *****************************************************************************/
88 static void CloseFilter( vlc_object_t *p_this )
89 {
90     filter_t *p_filter = (filter_t*)p_this;
91     filter_sys_t *p_sys = p_filter->p_sys;
92
93     free( p_sys );
94 }
95
96 /****************************************************************************
97  * Filter: the whole thing
98  ****************************************************************************/
99 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
100 {
101     picture_t *p_pic_dst;
102     int i_plane, i;
103     unsigned int j;
104
105     /* Request output picture */
106     p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
107     if( !p_pic_dst )
108     {
109         msg_Warn( p_filter, "can't get output picture" );
110         if( p_pic->pf_release )
111             p_pic->pf_release( p_pic );
112         return NULL;
113     }
114
115     /* Convert RV24 to RV32 */
116     for( i_plane = 0; i_plane < p_pic_dst->i_planes; i_plane++ )
117     {
118         uint8_t *p_src = p_pic->p[i_plane].p_pixels;
119         uint8_t *p_dst = p_pic_dst->p[i_plane].p_pixels;
120         unsigned int i_width = p_filter->fmt_out.video.i_width;
121
122         for( i = 0; i < p_pic_dst->p[i_plane].i_lines; i++ )
123         {
124             for( j = 0; j < i_width; j++ )
125             {
126                 *(p_dst++) = p_src[2];
127                 *(p_dst++) = p_src[1];
128                 *(p_dst++) = p_src[0];
129                 *(p_dst++) = 0xff;  /* Alpha */
130                 p_src += 3;
131             }
132             p_src += p_pic->p[i_plane].i_pitch - 3 * i_width;
133             p_dst += p_pic_dst->p[i_plane].i_pitch - 4 * i_width;
134         }
135     }
136
137     p_pic_dst->date = p_pic->date;
138     p_pic_dst->b_force = p_pic->b_force;
139     p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
140     p_pic_dst->b_progressive = p_pic->b_progressive;
141     p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
142
143     p_pic->pf_release( p_pic );
144     return p_pic_dst;
145 }
146