/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h> /* malloc(), free() */
-#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#include <vlc/vlc.h>
-#include <vlc/vout.h>
+#include <vlc_vout.h>
#include <math.h>
#include "filter_common.h"
+#include "filter_picture.h"
+
#include "vlc_image.h"
#include "vlc_input.h"
#include "vlc_playlist.h"
{
vout_thread_t *p_vout = (vout_thread_t *)p_this;
+ switch( p_vout->fmt_in.i_chroma )
+ {
+ CASE_PLANAR_YUV
+ case VLC_FOURCC('G','R','E','Y'):
+ break;
+ default:
+ msg_Err( p_vout, "Unsupported chroma" );
+ return VLC_EGENERIC;
+ }
+
/* Allocate structure */
p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
if( p_vout->p_sys == NULL )
{
int i_index;
picture_t *p_pic;
- video_format_t fmt = {0};
+ video_format_t fmt;
+ memset( &fmt, 0, sizeof(video_format_t) );
I_OUTPUTPICTURES = 0;
/* Initialize the output structure */
#define VIS_ZOOM 4
p_vout->p_sys->i_x = 0;
p_vout->p_sys->i_y = 0;
-#define ZOOM_FACTOR 100
- p_vout->p_sys->i_zoom = 200;
+#define ZOOM_FACTOR 8
+ p_vout->p_sys->i_zoom = 2*ZOOM_FACTOR;
+ p_vout->p_sys->b_visible = VLC_TRUE;
var_AddCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout );
var_AddCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout );
int o_zoom = p_vout->p_sys->i_zoom;
int x,y,o_yp,o_xp;
int v_w, v_h;
- video_format_t fmt_out = {0};
+ video_format_t fmt_out;
picture_t *p_converted;
plane_t *p_oyp=NULL;
+ int i_plane;
+ memset( &fmt_out, 0, sizeof(video_format_t) );
/* This is a new frame. Get a structure from the video_output. */
while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
== NULL )
/* background magnified image */
if( o_zoom != ZOOM_FACTOR )
{
-#define magnify( plane ) \
- o_yp = o_y*p_outpic->p[plane].i_lines/p_outpic->p[Y_PLANE].i_lines; \
- o_xp = o_x*p_outpic->p[plane].i_pitch/p_outpic->p[Y_PLANE].i_pitch; \
- for( y=0; y<p_outpic->p[plane].i_visible_lines; y++ ) \
- { \
- for( x=0; x<p_outpic->p[plane].i_visible_pitch; x++ ) \
- { \
- p_outpic->p[plane].p_pixels[y*p_outpic->p[plane].i_pitch+x] = \
- p_pic->p[plane].p_pixels[ \
- ( o_yp + y*ZOOM_FACTOR/o_zoom )*p_outpic->p[plane].i_pitch \
- + o_xp + x*ZOOM_FACTOR/o_zoom \
- ]; \
- } \
- }
- magnify( Y_PLANE );
- magnify( U_PLANE );
- magnify( V_PLANE );
-#undef magnify
+ for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+ {
+ o_yp = o_y*p_outpic->p[i_plane].i_lines
+ /p_outpic->p[Y_PLANE].i_lines;
+ o_xp = o_x*p_outpic->p[i_plane].i_pitch
+ /p_outpic->p[Y_PLANE].i_pitch;
+ int i_pitch = p_outpic->p[i_plane].i_pitch;
+#if 0
+ int o_zoom2 = o_zoom*o_zoom;
+ int o_zoom3 = o_zoom*o_zoom*o_zoom;
+ int o_zoom4 = o_zoom*o_zoom*o_zoom*o_zoom;
+ int o_zoom6 = o_zoom*o_zoom*o_zoom * o_zoom*o_zoom*o_zoom;
+#endif
+ for( y=0; y<p_outpic->p[i_plane].i_visible_lines; y++ )
+ {
+ for( x=0; x<p_outpic->p[i_plane].i_visible_pitch; x++ )
+ {
+#if 0
+ /* Nearest neighbor */
+ int nx = o_xp + x*ZOOM_FACTOR/o_zoom;
+ int ny = o_yp + y*ZOOM_FACTOR/o_zoom;
+ p_outpic->p[i_plane].p_pixels[y*i_pitch+x] =
+ p_pic->p[i_plane].p_pixels[ny*i_pitch+nx];
+#elif 1
+ /* Bi-linear */
+ int nx_real = o_xp*o_zoom + x*ZOOM_FACTOR;
+ int ny_real = o_yp*o_zoom + y*ZOOM_FACTOR;
+ int nx = nx_real/o_zoom;
+ int ny = ny_real/o_zoom;
+ int wtl = ((nx+1)*o_zoom-nx_real)*((ny+1)*o_zoom-ny_real);
+ int wtr = (nx_real-nx*o_zoom)*((ny+1)*o_zoom-ny_real);
+ int wbl = ((nx+1)*o_zoom-nx_real)*(ny_real-ny*o_zoom);
+ int wbr = (nx_real-nx*o_zoom)*(ny_real-ny*o_zoom);
+ p_outpic->p[i_plane].p_pixels[y*i_pitch+x] =
+ ( wtl*p_pic->p[i_plane].p_pixels[ny*i_pitch+nx]
+ + wtr*p_pic->p[i_plane].p_pixels[ny*i_pitch+(nx+1)]
+ + wbl*p_pic->p[i_plane].p_pixels[(ny+1)*i_pitch+nx]
+ + wbr*p_pic->p[i_plane].p_pixels[(ny+1)*i_pitch+(nx+1)]
+ ) / (o_zoom*o_zoom);
+#else
+ /* Bi-cubic */
+ /* FIXME: doesn't work */
+ /* \Sigma_{i=0..3} \Sigma_{j=0..3} \alpha_{i,j} x^i y^j
+ * 16 \alpha_{i,j} so we need to use the 16 nearest pixels
+ *
+ * In fact we should be able to write it as:
+ * \Pi_{i=1..16} [ \Pi_{j!=i} ( x - x_j ) * ( y - y_j ) ]
+ * * z_i / [ \Pi_{j!=i} ( x_i - x_j ) * ( y_i - y_j ) ]
+ * We also have to make sure that we don't use any
+ * x_j == x_i or y_j == y_i in the \Pi on j (else we get
+ * a 0/0 which kind of sucks) .
+ */
+ uint8_t *p = p_pic->p[i_plane].p_pixels;
+ int nx_real = o_xp*o_zoom + x*ZOOM_FACTOR;
+ int ny_real = o_yp*o_zoom + y*ZOOM_FACTOR;
+
+ int nx = nx_real/o_zoom;
+ int ny = ny_real/o_zoom;
+
+ int xi, yi, xj, yj;
+ int my = __MAX( ny-1, 0 );
+ int mx = __MAX( nx-1, 0 );
+ //p_outpic->p[i_plane].i_visible_lines - 4
+ //p_outpic->p[i_plane].i_visible_pitch - 4
+ int v = 1;
+ for( yi = my; yi <= my+3; yi++ )
+ {
+ int numy = 1;
+ int deny = 1;
+ /*
+ for( yj = my; yj <= my+3; yj++ )
+ {
+ if( yj != yi )
+ {
+ numy *= (ny_real-yj*o_zoom);
+ deny *= (yi - yj);
+ }
+ }
+ numy /= o_zoom2;*/
+ for( xi = mx; xi <= mx+3; xi++ )
+ {
+ int num = numy;
+ int den = deny;
+ for( xj = mx; xj <= mx+3; xj++ )
+ {
+ if( xj != xi )
+ {
+ num *= (nx_real-xj*o_zoom);
+ den *= (xi - xj);
+ }
+ }
+ v = ( v * (p[yi*i_pitch+xi] * num) ) / ( den * o_zoom3 );
+ }
+ }
+ p_outpic->p[i_plane].p_pixels[y*i_pitch+x] = v;
+#endif
+ }
+ }
+ }
}
else
{
-#define copy( plane ) \
- memcpy( p_outpic->p[plane].p_pixels, p_pic->p[plane].p_pixels, \
- p_outpic->p[plane].i_lines * p_outpic->p[plane].i_pitch );
- copy( Y_PLANE );
- copy( U_PLANE );
- copy( V_PLANE );
-#undef copy
+ for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+ {
+ p_vout->p_libvlc->
+ pf_memcpy( p_outpic->p[i_plane].p_pixels, p_pic->p[i_plane].p_pixels,
+ p_outpic->p[i_plane].i_lines * p_outpic->p[i_plane].i_pitch );
+ }
}
if( p_vout->p_sys->b_visible )
fmt_out.i_height = p_vout->render.i_height/VIS_ZOOM;
p_converted = image_Convert( p_vout->p_sys->p_image, p_pic,
&(p_pic->format), &fmt_out );
- #define copyimage( plane ) \
- for( y=0; y<p_converted->p[plane].i_visible_lines; y++) \
- { \
- memcpy( p_outpic->p[plane].p_pixels+y*p_outpic->p[plane].i_pitch, \
- p_converted->p[plane].p_pixels+y*p_converted->p[plane].i_pitch, \
- p_converted->p[plane].i_visible_pitch ); \
+ for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+ {
+ for( y=0; y<p_converted->p[i_plane].i_visible_lines; y++)
+ {
+ p_vout->p_libvlc->pf_memcpy(
+ p_outpic->p[i_plane].p_pixels+y*p_outpic->p[i_plane].i_pitch,
+ p_converted->p[i_plane].p_pixels+y*p_converted->p[i_plane].i_pitch,
+ p_converted->p[i_plane].i_visible_pitch );
+ }
}
- copyimage( Y_PLANE );
- copyimage( U_PLANE );
- copyimage( V_PLANE );
- #undef copyimage
p_converted->pf_release( p_converted );
/* white rectangle on visualization */
v_w = p_oyp->i_pitch*ZOOM_FACTOR/(VIS_ZOOM*o_zoom);
v_h = (o_y+p_oyp->i_lines*ZOOM_FACTOR/o_zoom)/VIS_ZOOM;
/* top line */
- memset( p_oyp->p_pixels
- + o_y/VIS_ZOOM*p_oyp->i_pitch
- + o_x/VIS_ZOOM, 0xff, v_w+1 );
+ p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
+ + o_y/VIS_ZOOM*p_oyp->i_pitch
+ + o_x/VIS_ZOOM, 0xff, v_w+1 );
for( y = o_y/VIS_ZOOM+1; y < v_h; y++ )
{
] = 0xff;
}
/* bottom line */
- memset( p_oyp->p_pixels
- + v_h*p_oyp->i_pitch
- + o_x/VIS_ZOOM, 0xff, v_w+1 );
+ p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
+ + v_h*p_oyp->i_pitch
+ + o_x/VIS_ZOOM, 0xff, v_w+1 );
/* */
v_h = p_oyp->i_lines/VIS_ZOOM;
if( p_vout->p_sys->b_visible )
{
/* zoom gauge */
- memset( p_oyp->p_pixels
- + (v_h+9)*p_oyp->i_pitch,
- 0xff, 41 );
+ p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
+ + (v_h+9)*p_oyp->i_pitch,
+ 0xff, 41 );
for( y = v_h + 10; y < v_h + 90; y++ )
{
int width = v_h + 90 - y;
width = (width*width)/160;
if( (80 - y + v_h)*10 < o_zoom )
{
- memset( p_oyp->p_pixels
- + y*p_oyp->i_pitch,
- 0xff, width );
+ p_vout->p_libvlc->pf_memset( p_oyp->p_pixels
+ + y*p_oyp->i_pitch,
+ 0xff, width );
}
else
{
static int SendEvents( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
+ VLC_UNUSED(p_this); VLC_UNUSED(oldval);
var_Set( (vlc_object_t *)p_data, psz_var, newval );
return VLC_SUCCESS;
static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
+ VLC_UNUSED(p_data); VLC_UNUSED(oldval);
vout_thread_t *p_vout = (vout_thread_t *)p_this;
var_Set( p_vout->p_sys->p_vout, psz_var, newval );
return VLC_SUCCESS;
static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
+ VLC_UNUSED(p_this);
vout_thread_t *p_vout = (vout_thread_t*)p_data;
vlc_value_t vald,valx,valy;