fix #53, add alpha parameter to zoom fx

This commit is contained in:
niels
2015-11-16 19:05:33 +01:00
parent 39bcf6a5fc
commit 0b4ea3afaa
6 changed files with 159 additions and 10 deletions

View File

@@ -27,7 +27,7 @@
vj_effect *zoom_init(int width , int height)
{
vj_effect *ve = (vj_effect *) vj_calloc(sizeof(vj_effect));
ve->num_params = 4;
ve->num_params = 5;
ve->defaults = (int *) vj_calloc(sizeof(int) * ve->num_params); /* default values */
ve->limits[0] = (int *) vj_calloc(sizeof(int) * ve->num_params); /* min */
ve->limits[1] = (int *) vj_calloc(sizeof(int) * ve->num_params); /* max */
@@ -35,6 +35,7 @@ vj_effect *zoom_init(int width , int height)
ve->defaults[1] = height/2;
ve->defaults[2] = 50;
ve->defaults[3] = 1;
ve->defaults[4] = 0;
ve->limits[0][0] = 0;
ve->limits[1][0] = width;
@@ -48,11 +49,14 @@ vj_effect *zoom_init(int width , int height)
ve->limits[0][3] = 0;
ve->limits[1][3] = 1;
ve->limits[0][4] = 0;
ve->limits[1][4] = 1;
ve->description = "Zoom";
ve->sub_format = 1;
ve->extra_frame = 0;
ve->has_user = 0;
ve->param_description = vje_build_param_list( ve->num_params, "Width", "Height", "Factor", "Mode" );
ve->param_description = vje_build_param_list( ve->num_params, "Width", "Height", "Factor", "Mode", "Update Alpha" );
return ve;
}
static int zoom_[4] = { 0,0,0,0 };
@@ -63,7 +67,7 @@ static uint8_t *zoom_private_[4] = { NULL, NULL, NULL, NULL };
int zoom_malloc(int width, int height)
{
int i;
for( i = 0; i < 3; i ++ ) {
for( i = 0; i < 4; i ++ ) {
zoom_private_[i] = (uint8_t*) vj_malloc( sizeof(uint8_t) * RUP8(width*height+width));
if(!zoom_private_[i])
return 0;
@@ -74,7 +78,7 @@ int zoom_malloc(int width, int height)
void zoom_free() {
int i;
for( i = 0; i < 3; i ++ ) {
for( i = 0; i < 4; i ++ ) {
if( zoom_private_[i] )
free(zoom_private_[i] );
zoom_private_[i] = NULL;
@@ -84,7 +88,7 @@ void zoom_free() {
zoom_vp_ = NULL;
}
void zoom_apply( VJFrame *frame, int width, int height, int x, int y, int factor, int dir)
void zoom_apply( VJFrame *frame, int width, int height, int x, int y, int factor, int dir, int alpha)
{
if( zoom_[0] != x || zoom_[1] != y || zoom_[2] != factor || !zoom_vp_ || dir != zoom_[3])
{
@@ -96,10 +100,15 @@ void zoom_apply( VJFrame *frame, int width, int height, int x, int y, int factor
zoom_[0] = x; zoom_[1] = y; zoom_[2] = factor; zoom_[3] = dir;
}
int strides[4] = { (width*height),(width*height),(width*height), 0 };
int strides[4] = { (width*height),(width*height),(width*height), (alpha ? width * height : 0 ) };
vj_frame_copy( frame->data, zoom_private_, strides );
viewport_process_dynamic( zoom_vp_, zoom_private_, frame->data );
if(alpha == 0) {
viewport_process_dynamic( zoom_vp_, zoom_private_, frame->data );
}
else {
viewport_process_dynamic_alpha( zoom_vp_, zoom_private_, frame->data );
}
}

View File

@@ -29,5 +29,5 @@ vj_effect *zoom_init(int width, int height);
int zoom_malloc(int w, int h);
void zoom_free();
void zoom_apply(VJFrame *frame, int width,
int height, int x_offset, int y_offset, int factor, int dir);
int height, int x_offset, int y_offset, int factor, int dir, int alpha);
#endif

View File

@@ -502,7 +502,7 @@ extern void bathroom_apply(VJFrame *frame, int width, int height, int mode, int
extern void slice_apply(VJFrame *frame, int width, int height, int val, int reinit);
extern void zoom_apply(VJFrame *frame, int w, int h , int xo, int yo, int f, int dir);
extern void zoom_apply(VJFrame *frame, int w, int h , int xo, int yo, int f, int dir, int alpha);
extern void perspective_apply( VJFrame *frame, int width, int height, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int reverse);

View File

@@ -383,7 +383,7 @@ void vj_effman_apply_image_effect(
rgbchannel_apply(frames[0],frames[0]->width,frames[0]->height,arg[0],arg[1],arg[2]);
break;
case VJ_IMAGE_EFFECT_ZOOM:
zoom_apply(frames[0], frames[0]->width, frames[0]->height,arg[0],arg[1],arg[2],arg[3]);
zoom_apply(frames[0], frames[0]->width, frames[0]->height,arg[0],arg[1],arg[2],arg[3],arg[4]);
break;
case VJ_IMAGE_EFFECT_CROSSPIXEL:
crosspixel_apply(frames[0],frames[0]->width,frames[0]->height,arg[0],arg[1]);

View File

@@ -1280,6 +1280,145 @@ void viewport_process_dynamic( void *data, uint8_t *in[3], uint8_t *out[3] )
#endif
}
void viewport_process_dynamic_alpha( void *data, uint8_t *in[4], uint8_t *out[4] )
{
viewport_t *v = (viewport_t*) data;
const int32_t w = v->w;
const int32_t h = v->h;
const int32_t X = v->x0;
const int32_t Y = v->y0;
matrix_t *m = v->m;
const float xinc = m->m[0][0];
const float yinc = m->m[1][0];
const float winc = m->m[2][0];
const int32_t tx1 = v->ttx1;
const int32_t tx2 = v->ttx2;
const int32_t ty1 = v->tty1;
const int32_t ty2 = v->tty2;
const float m01 = m->m[0][1];
const float m11 = m->m[1][1];
const float m21 = m->m[2][1];
const float m02 = m->m[0][2];
const float m12 = m->m[1][2];
const float m22 = m->m[2][2];
const uint8_t *inY = in[0];
const uint8_t *inU = in[1];
const uint8_t *inV = in[2];
const uint8_t *inA = in[3];
uint8_t *outY = out[0];
uint8_t *outU = out[1];
uint8_t *outV = out[2];
uint8_t *outA = out[3];
float tx,ty,tw;
float ttx,tty;
int32_t x,y;
int32_t itx,ity;
#if defined (HAVE_ASM_MMX) || defined (HAVE_AMS_SSE )
fast_memset_dirty( outY , 0, ty1 * v->w );
fast_memset_dirty( outU , 128, ty1 * v->w );
fast_memset_dirty( outV , 128, ty1 * v->w );
fast_memset_dirty( outA,0, ty1*v->w);
fast_memset_finish();
#else
for( y =0 ; y < ty1; y ++ )
{
for( x = 0 ; x < w ; x ++ )
{
outY[ (y * w +x ) ] = 0;
outU[ (y * w +x ) ] = 128;
outV[ (y * w +x ) ] = 128;
outA[ (y*w +x) ] = 0;
}
}
#endif
for( y = ty1; y < ty2; y ++ )
{
tx = xinc * ( tx1 + 0.5 ) + m01 * ( y + 0.5) + m02;
ty = yinc * ( tx1 + 0.5 ) + m11 * ( y + 0.5) + m12;
tw = winc * ( tx1 + 0.5 ) + m21 * ( y + 0.5) + m22;
for( x = 0; x < tx1; x ++ )
{
outY[(y*w+x)] = 0;
outU[(y*w+x)] = 128;
outV[(y*w+x)] = 128;
outA[(y*w+x)] = 0;
}
for( x = tx1; x < tx2 ; x ++ )
{
if( tw == 0.0 ) {
ttx = 0.0;
tty = 0.0;
} else if ( tw != 1.0 ) {
ttx = tx / tw;
tty = ty / tw;
} else {
ttx = tx;
tty = ty;
}
itx = (int32_t) ttx;
ity = (int32_t) tty;
if( itx >= X && itx <= w && ity >= Y && ity < h )
{
outY[(y*w+x)] = inY[(ity*w+itx)];
outU[(y*w+x)] = inU[(ity*w+itx)];
outV[(y*w+x)] = inV[(ity*w+itx)];
outA[(y*w+x)] = inA[(ity*w+itx)];
}
else
{
outY[(y*w+x)] = 0;
outU[(y*w+x)] = 128;
outV[(y*w+x)] = 128;
outA[(y*w+x)] = 0;
}
tx += xinc;
ty += yinc;
tw += winc;
}
for( x = tx2; x < w; x ++ )
{
outY[(y*w+x)] = 0;
outU[(y*w+x)] = 128;
outV[(y*w+x)] = 128;
outA[(y*w+x)] = 0;
}
}
#if defined (HAVE_ASM_MMX) || defined (HAVE_AMS_SSE )
int rest = h - ty2;
fast_memset_dirty( outY + (ty2 * v->w),0, rest * v->w );
fast_memset_dirty( outU + (ty2 * v->w), 128, rest * v->w );
fast_memset_dirty( outV + (ty2 * v->w), 128, rest * v->w );
fast_memset_dirty( outA + (ty2 * v->w), 0, rest * v->w );
fast_memset_finish();
#else
for( y = ty2 ; y < h; y ++ )
{
for( x = 0; x < w; x ++ )
{
outY[(y*w+x)] = 0;
outU[(y*w+x)] = 128;
outV[(y*w+x)] = 128;
outA[(y*w+x)] = 0;
}
}
#endif
}
void viewport_destroy( void *data )
{

View File

@@ -22,6 +22,7 @@
/* Viewport component for FX */
#define VP_QUADZOOM 1
void viewport_process_dynamic_alpha( void *data, uint8_t *in[4], uint8_t *out[4] );
void viewport_process_dynamic( void *data, uint8_t *in[3], uint8_t *out[3] );
void viewport_process_dynamic_map( void *data, uint8_t *in[3], uint8_t *out[3], uint32_t *map, int feather );
void *viewport_fx_init_map( int wid, int hei, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int reverse);