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