invert.c 6.12 KB
Newer Older
1 2 3
/*****************************************************************************
 * invert.c : Invert video plugin for vlc
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2000-2006 VLC authors and VideoLAN
5
 * $Id$
6 7 8
 *
 * Authors: Samuel Hocevar <sam@zoy.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
 * (at your option) any later version.
13
 *
14 15
 * 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 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include <vlc_common.h>
33
#include <vlc_plugin.h>
34

Rémi Duraffort's avatar
Rémi Duraffort committed
35
#include <vlc_filter.h>
36
#include "filter_picture.h"
37 38 39 40

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
41 42
static int  Create      ( vlc_object_t * );
static void Destroy     ( vlc_object_t * );
43

44
static picture_t *Filter( filter_t *, picture_t * );
45

46 47 48
/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
49 50 51 52 53
vlc_module_begin ()
    set_description( N_("Invert video filter") )
    set_shortname( N_("Color inversion" ))
    set_category( CAT_VIDEO )
    set_subcategory( SUBCAT_VIDEO_VFILTER )
54
    set_capability( "video filter", 0 )
55 56 57
    add_shortcut( "invert" )
    set_callbacks( Create, Destroy )
vlc_module_end ()
58 59 60 61 62 63 64 65

/*****************************************************************************
 * Create: allocates Invert video thread output method
 *****************************************************************************
 * This function allocates and initializes a Invert vout method.
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
{
66
    filter_t *p_filter = (filter_t *)p_this;
67
    vlc_fourcc_t fourcc = p_filter->fmt_in.video.i_chroma;
68

69
    if( fourcc == VLC_CODEC_YUVP || fourcc == VLC_CODEC_RGBP
70
     || fourcc == VLC_CODEC_RGBA || fourcc == VLC_CODEC_ARGB )
71 72 73 74
        return VLC_EGENERIC;

    const vlc_chroma_description_t *p_chroma =
        vlc_fourcc_GetChromaDescription( fourcc );
75
    if( p_chroma == NULL || p_chroma->plane_count == 0
76 77
     || p_chroma->pixel_size * 8 != p_chroma->pixel_bits )
        return VLC_EGENERIC;
78

79
    p_filter->pf_video_filter = Filter;
80
    return VLC_SUCCESS;
81 82 83 84 85 86 87 88
}

/*****************************************************************************
 * Destroy: destroy Invert video thread output method
 *****************************************************************************
 * Terminate an output method created by InvertCreateOutputMethod
 *****************************************************************************/
static void Destroy( vlc_object_t *p_this )
89
{
90
    (void)p_this;
91 92 93 94 95 96 97 98 99
}

/*****************************************************************************
 * Render: displays previously rendered output
 *****************************************************************************
 * This function send the currently rendered image to Invert image, waits
 * until it is displayed and switch the two rendering buffers, preparing next
 * frame.
 *****************************************************************************/
100
static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
101 102
{
    picture_t *p_outpic;
103
    int i_planes;
104

105 106
    if( !p_pic ) return NULL;

Laurent Aimar's avatar
Laurent Aimar committed
107
    p_outpic = filter_NewPicture( p_filter );
108
    if( !p_outpic )
109
    {
110
        msg_Warn( p_filter, "can't get output picture" );
111
        picture_Release( p_pic );
112
        return NULL;
113
    }
114

115
    if( p_pic->format.i_chroma == VLC_CODEC_YUVA )
116 117 118
    {
        /* We don't want to invert the alpha plane */
        i_planes = p_pic->i_planes - 1;
Rafaël Carré's avatar
Rafaël Carré committed
119
        memcpy(
120 121 122 123 124 125 126 127
            p_outpic->p[A_PLANE].p_pixels, p_pic->p[A_PLANE].p_pixels,
            p_pic->p[A_PLANE].i_pitch *  p_pic->p[A_PLANE].i_lines );
    }
    else
    {
        i_planes = p_pic->i_planes;
    }

128
    for( int i_index = 0 ; i_index < i_planes ; i_index++ )
129
    {
130
        uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
131 132

        p_in = p_pic->p[i_index].p_pixels;
133
        p_in_end = p_in + p_pic->p[i_index].i_visible_lines
134
                           * p_pic->p[i_index].i_pitch;
135 136 137

        p_out = p_outpic->p[i_index].p_pixels;

138
        while( p_in < p_in_end )
139
        {
140 141
            uint64_t *p_in64, *p_out64;

142 143
            p_line_end = p_in + p_pic->p[i_index].i_visible_pitch - 64;

144 145 146
            p_in64 = (uint64_t*)p_in;
            p_out64 = (uint64_t*)p_out;

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
147
            while( p_in64 < (uint64_t *)p_line_end )
148
            {
149
                /* Do 64 pixels at a time */
150 151 152 153
                *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
                *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
                *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
                *p_out64++ = ~*p_in64++; *p_out64++ = ~*p_in64++;
154 155
            }

156 157
            p_in = (uint8_t*)p_in64;
            p_out = (uint8_t*)p_out64;
158 159
            p_line_end += 64;

160
            while( p_in < p_line_end )
161 162 163 164 165 166 167 168
            {
                *p_out++ = ~( *p_in++ );
            }

            p_in += p_pic->p[i_index].i_pitch
                     - p_pic->p[i_index].i_visible_pitch;
            p_out += p_outpic->p[i_index].i_pitch
                     - p_outpic->p[i_index].i_visible_pitch;
169 170 171
        }
    }

172
    return CopyInfoAndRelease( p_outpic, p_pic );
Gildas Bazin's avatar
 
Gildas Bazin committed
173
}