]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/yuvp.c
mft: Link to mfplat when building with msvc
[vlc] / modules / video_filter / yuvp.c
index 97031855866b82e79bab063a166b005f25203ce3..c8ffbf203a70643988ca5751c001ce999fe09149 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * yuvp.c: YUVP to YUVA/RGBA chroma converter
  *****************************************************************************
- * Copyright (C) 2008 the VideoLAN team
+ * Copyright (C) 2008 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar < fenrir @ videolan.org >
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * 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
  * (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
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU 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.
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -30,8 +30,8 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_vout.h>
-#include "vlc_filter.h"
+#include <vlc_filter.h>
+#include <assert.h>
 
 /* TODO:
  *  Add anti-aliasing support (specially for DVD where only 4 colors are used)
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( N_("YUVP converter") );
-    set_capability( "video filter2", 10 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("YUVP converter") )
+    set_capability( "video filter2", 10 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /****************************************************************************
  * Local prototypes
@@ -64,11 +64,13 @@ static int Open( vlc_object_t *p_this )
 
     /* It only supports YUVP to YUVA/RGBA without scaling
      * (if scaling is required another filter can do it) */
-    if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','P') ||
-        ( p_filter->fmt_out.video.i_chroma != VLC_FOURCC('Y','U','V','A') &&
-          p_filter->fmt_out.video.i_chroma != VLC_FOURCC('R','G','B','A') ) ||
+    if( p_filter->fmt_in.video.i_chroma != VLC_CODEC_YUVP ||
+        ( p_filter->fmt_out.video.i_chroma != VLC_CODEC_YUVA &&
+          p_filter->fmt_out.video.i_chroma != VLC_CODEC_RGBA &&
+          p_filter->fmt_out.video.i_chroma != VLC_CODEC_ARGB ) ||
         p_filter->fmt_in.video.i_width  != p_filter->fmt_out.video.i_width ||
-        p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
+        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 )
     {
         return VLC_EGENERIC;
     }
@@ -102,7 +104,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     const video_palette_t *p_yuvp = p_filter->fmt_in.video.p_palette;
 
     assert( p_yuvp != NULL );
-    assert( p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','U','V','P') );
+    assert( p_filter->fmt_in.video.i_chroma == VLC_CODEC_YUVP );
     assert( p_filter->fmt_in.video.i_width == p_filter->fmt_out.video.i_width );
     assert( p_filter->fmt_in.video.i_height == p_filter->fmt_out.video.i_height );
 
@@ -114,7 +116,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         return NULL;
     }
 
-    if( p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','U','V','A') )
+    if( p_filter->fmt_out.video.i_chroma == VLC_CODEC_YUVA )
     {
         for( unsigned int y = 0; y < p_filter->fmt_in.video.i_height; y++ )
         {
@@ -138,12 +140,11 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
             }
         }
     }
-    else
+    else if( p_filter->fmt_out.video.i_chroma == VLC_CODEC_RGBA )
     {
-        assert( p_filter->fmt_out.video.i_chroma == VLC_FOURCC('R','G','B','A') );
+        video_palette_t rgbp;
 
         /* Create a RGBA palette */
-        video_palette_t rgbp;
         rgbp.i_entries = p_yuvp->i_entries;
         for( int i = 0; i < p_yuvp->i_entries; i++ )
         {
@@ -152,7 +153,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
             rgbp.palette[i][3] = p_yuvp->palette[i][3];
         }
 
-        /* */
         for( unsigned int y = 0; y < p_filter->fmt_in.video.i_height; y++ )
         {
             const uint8_t *p_line = &p_pic->p->p_pixels[y*p_pic->p->i_pitch];
@@ -162,7 +162,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
             {
                 const int v = p_line[x];
 
-                if( v > rgbp.i_entries )  /* maybe assert ? */
+                if( v >= rgbp.i_entries )  /* maybe assert ? */
                     continue;
 
                 p_rgba[4*x+0] = rgbp.palette[v][0];
@@ -172,6 +172,40 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
             }
         }
     }
+    else
+    {
+        video_palette_t rgbp;
+
+        assert( p_filter->fmt_out.video.i_chroma == VLC_CODEC_ARGB );
+        /* Create a RGBA palette */
+        rgbp.i_entries = p_yuvp->i_entries;
+        for( int i = 0; i < p_yuvp->i_entries; i++ )
+        {
+            Yuv2Rgb( &rgbp.palette[i][1], &rgbp.palette[i][2], &rgbp.palette[i][3],
+                     p_yuvp->palette[i][0], p_yuvp->palette[i][1], p_yuvp->palette[i][2] );
+            rgbp.palette[i][0] = p_yuvp->palette[i][3];
+        }
+
+        for( unsigned int y = 0; y < p_filter->fmt_in.video.i_height; y++ )
+        {
+            const uint8_t *p_line = &p_pic->p->p_pixels[y*p_pic->p->i_pitch];
+            uint8_t *p_rgba = &p_out->p->p_pixels[y*p_out->p->i_pitch];
+
+            for( unsigned int x = 0; x < p_filter->fmt_in.video.i_width; x++ )
+            {
+                const int v = p_line[x];
+
+                if( v >= rgbp.i_entries )  /* maybe assert ? */
+                    continue;
+
+                p_rgba[4*x+0] = rgbp.palette[v][0];
+                p_rgba[4*x+1] = rgbp.palette[v][1];
+                p_rgba[4*x+2] = rgbp.palette[v][2];
+                p_rgba[4*x+3] = rgbp.palette[v][3];
+            }
+        }
+
+    }
 
     picture_CopyProperties( p_out, p_pic );
     picture_Release( p_pic );