Commit eb07c341 authored by Laurent Aimar's avatar Laurent Aimar

Fixed...

Fixed colorthres/erase/extract/gaussianblur/gradient/motionblur/motiondetect/noise/psychedelic/sharpen filters.

input and output picture pitches may not be equal (corruptions or segfaults).
parent 6c4aa108
...@@ -186,8 +186,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -186,8 +186,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{ {
picture_t *p_outpic; picture_t *p_outpic;
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
uint8_t *p_in_y, *p_in_u, *p_in_v, *p_in_end_u;
uint8_t *p_out_y, *p_out_u, *p_out_v;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
int i_simthres = p_sys->i_simthres; int i_simthres = p_sys->i_simthres;
...@@ -204,23 +202,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -204,23 +202,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
return NULL; return NULL;
} }
p_in_u = p_pic->p[U_PLANE].p_pixels; /* Copy the Y plane */
p_in_v = p_pic->p[V_PLANE].p_pixels; plane_CopyPixels( &p_outpic->p[Y_PLANE], &p_pic->p[Y_PLANE] );
p_in_y = p_pic->p[Y_PLANE].p_pixels;
p_in_end_u = p_in_u + p_pic->p[U_PLANE].i_visible_lines
* p_pic->p[U_PLANE].i_pitch - 8;
p_out_y = p_outpic->p[Y_PLANE].p_pixels;
p_out_u = p_outpic->p[U_PLANE].p_pixels;
p_out_v = p_outpic->p[V_PLANE].p_pixels;
/* Create grayscale version of input */
vlc_memcpy( p_out_y, p_in_y, p_pic->p[Y_PLANE].i_visible_lines
* p_pic->p[Y_PLANE].i_pitch - 8 );
vlc_memset( p_out_u, 0x80, p_pic->p[U_PLANE].i_visible_lines
* p_pic->p[U_PLANE].i_pitch - 8 );
vlc_memset( p_out_v, 0x80, p_pic->p[U_PLANE].i_visible_lines
* p_pic->p[U_PLANE].i_pitch - 8 );
/* /*
* Do the U and V planes * Do the U and V planes
...@@ -232,31 +215,44 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -232,31 +215,44 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
112 * i_blue + 128) >> 8) + 128; 112 * i_blue + 128) >> 8) + 128;
int i_v = (int8_t)(( 112 * i_red - 94 * i_green - int i_v = (int8_t)(( 112 * i_red - 94 * i_green -
18 * i_blue + 128) >> 8) + 128; 18 * i_blue + 128) >> 8) + 128;
int refu = i_u - 0x80; /*bright red*/ int refu = i_u - 0x80; /*bright red*/
int refv = i_v - 0x80; int refv = i_v - 0x80;
int reflength = sqrt(refu*refu+refv*refv); int reflength = sqrt(refu*refu+refv*refv);
while( p_in_u < p_in_end_u ) { for( int y = 0; y < p_pic->p[U_PLANE].i_visible_lines; y++ )
/* Length of color vector */ {
int inu = (*p_in_u) - 0x80; uint8_t *p_src_u = &p_pic->p[U_PLANE].p_pixels[y * p_pic->p[U_PLANE].i_pitch];
int inv = (*p_in_v) - 0x80; uint8_t *p_src_v = &p_pic->p[V_PLANE].p_pixels[y * p_pic->p[V_PLANE].i_pitch];
int length = sqrt(inu*inu+inv*inv); uint8_t *p_dst_u = &p_outpic->p[U_PLANE].p_pixels[y * p_outpic->p[U_PLANE].i_pitch];
uint8_t *p_dst_v = &p_outpic->p[V_PLANE].p_pixels[y * p_outpic->p[V_PLANE].i_pitch];
int diffu = refu * length - inu *reflength;
int diffv = refv * length - inv *reflength; for( int x = 0; x < p_pic->p[U_PLANE].i_visible_pitch; x++ )
long long int difflen2=diffu*diffu; {
difflen2 +=diffv*diffv; /* Length of color vector */
long long int thres = length*reflength; int inu = *p_src_u - 0x80;
thres *= thres; int inv = *p_src_v - 0x80;
if( length > i_satthres && (difflen2*i_simthres< thres ) ) { int length = sqrt(inu*inu+inv*inv);
*p_out_u = *p_in_u;
*p_out_v = *p_in_v; int diffu = refu * length - inu *reflength;
// fprintf(stderr,"keeping color %d %d\n", length, difflen2); int diffv = refv * length - inv *reflength;
long long int difflen2=diffu*diffu;
difflen2 +=diffv*diffv;
long long int thres = length*reflength;
thres *= thres;
if( length > i_satthres && (difflen2*i_simthres< thres ) )
{
*p_dst_u++ = *p_src_u;
*p_dst_v++ = *p_src_v;
}
else
{
*p_dst_u++ = 0x80;
*p_dst_v++ = 0x80;
}
p_src_u++;
p_src_v++;
} }
p_in_u++;
p_in_v++;
p_out_u++;
p_out_v++;
} }
return CopyInfoAndRelease( p_outpic, p_pic ); return CopyInfoAndRelease( p_outpic, p_pic );
...@@ -266,8 +262,6 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic ) ...@@ -266,8 +262,6 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
{ {
picture_t *p_outpic; picture_t *p_outpic;
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
uint8_t *p_in_y, *p_in_u, *p_in_v, *p_in_end_u;
uint8_t *p_out_y, *p_out_u, *p_out_v;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
int i_simthres = p_sys->i_simthres; int i_simthres = p_sys->i_simthres;
...@@ -287,22 +281,9 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic ) ...@@ -287,22 +281,9 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
int i_y_offset, i_u_offset, i_v_offset; int i_y_offset, i_u_offset, i_v_offset;
GetPackedYuvOffsets( p_filter->fmt_in.video.i_chroma, GetPackedYuvOffsets( p_filter->fmt_in.video.i_chroma,
&i_y_offset, &i_u_offset, &i_v_offset ); &i_y_offset, &i_u_offset, &i_v_offset );
p_in_y = p_pic->p->p_pixels+i_y_offset;
p_in_u = p_pic->p->p_pixels+i_u_offset;
p_in_v = p_pic->p->p_pixels+i_v_offset;
p_in_end_u = p_in_u + p_pic->p->i_visible_lines
* p_pic->p->i_pitch - 8;
p_out_y = p_outpic->p->p_pixels+i_y_offset;
p_out_u = p_outpic->p->p_pixels+i_u_offset;
p_out_v = p_outpic->p->p_pixels+i_v_offset;
/* Create grayscale version of input */
vlc_memcpy( p_outpic->p->p_pixels, p_pic->p->p_pixels,
p_pic->p->i_visible_lines * p_pic->p->i_pitch - 8 );
/* /*
* Do the U and V planes * Copy Y and do the U and V planes
*/ */
int i_red = ( i_color & 0xFF0000 ) >> 16; int i_red = ( i_color & 0xFF0000 ) >> 16;
int i_green = ( i_color & 0xFF00 ) >> 8; int i_green = ( i_color & 0xFF00 ) >> 8;
...@@ -315,32 +296,41 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic ) ...@@ -315,32 +296,41 @@ static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
int refv = i_v - 0x80; int refv = i_v - 0x80;
int reflength = sqrt(refu*refu+refv*refv); int reflength = sqrt(refu*refu+refv*refv);
while( p_in_u < p_in_end_u ) { for( int y = 0; y < p_pic->p->i_visible_lines; y++ )
/* Length of color vector */ {
int inu = (*p_in_u) - 0x80; uint8_t *p_src = &p_pic->p->p_pixels[y * p_pic->p->i_pitch];
int inv = (*p_in_v) - 0x80; uint8_t *p_dst = &p_outpic->p->p_pixels[y * p_outpic->p->i_pitch];
int length = sqrt(inu*inu+inv*inv);
for( int x = 0; x < p_pic->p->i_visible_pitch / 4; x++ )
int diffu = refu * length - inu *reflength;
int diffv = refv * length - inv *reflength;
long long int difflen2=diffu*diffu;
difflen2 +=diffv*diffv;
long long int thres = length*reflength;
thres *= thres;
if( length > i_satthres && (difflen2*i_simthres< thres ) ) {
*p_out_u = *p_in_u;
*p_out_v = *p_in_v;
// fprintf(stderr,"keeping color %d %d\n", length, difflen2);
}
else
{ {
*p_out_u = 0x80; p_dst[i_y_offset + 0] = p_src[i_y_offset + 0];
*p_out_v = 0x80; p_dst[i_y_offset + 2] = p_src[i_y_offset + 2];
/* Length of color vector */
int inu = p_src[i_u_offset] - 0x80;
int inv = p_src[i_v_offset] - 0x80;
int length = sqrt(inu*inu+inv*inv);
int diffu = refu * length - inu *reflength;
int diffv = refv * length - inv *reflength;
long long int difflen2=diffu*diffu;
difflen2 +=diffv*diffv;
long long int thres = length*reflength;
thres *= thres;
if( length > i_satthres && (difflen2*i_simthres< thres ) )
{
p_dst[i_u_offset] = p_src[i_u_offset];
p_dst[i_v_offset] = p_src[i_v_offset];
}
else
{
p_dst[i_u_offset] = 0x80;
p_dst[i_v_offset] = 0x80;
}
p_dst += 4;
p_src += 4;
} }
p_in_u+=4;
p_in_v+=4;
p_out_u+=4;
p_out_v+=4;
} }
return CopyInfoAndRelease( p_outpic, p_pic ); return CopyInfoAndRelease( p_outpic, p_pic );
......
...@@ -246,13 +246,11 @@ static void FilterErase( filter_t *p_filter, picture_t *p_inpic, ...@@ -246,13 +246,11 @@ static void FilterErase( filter_t *p_filter, picture_t *p_inpic,
for( int i_plane = 0; i_plane < p_inpic->i_planes; i_plane++ ) for( int i_plane = 0; i_plane < p_inpic->i_planes; i_plane++ )
{ {
const int i_pitch = p_inpic->p[i_plane].i_pitch; const int i_pitch = p_outpic->p[i_plane].i_pitch;
const int i_2pitch = i_pitch<<1; const int i_2pitch = i_pitch<<1;
const int i_visible_pitch = p_inpic->p[i_plane].i_visible_pitch; const int i_visible_pitch = p_inpic->p[i_plane].i_visible_pitch;
const int i_lines = p_inpic->p[i_plane].i_lines;
const int i_visible_lines = p_inpic->p[i_plane].i_visible_lines; const int i_visible_lines = p_inpic->p[i_plane].i_visible_lines;
uint8_t *p_inpix = p_inpic->p[i_plane].p_pixels;
uint8_t *p_outpix = p_outpic->p[i_plane].p_pixels; uint8_t *p_outpix = p_outpic->p[i_plane].p_pixels;
uint8_t *p_mask = p_sys->p_mask->A_PIXELS; uint8_t *p_mask = p_sys->p_mask->A_PIXELS;
int i_x = p_sys->i_x, i_y = p_sys->i_y; int i_x = p_sys->i_x, i_y = p_sys->i_y;
...@@ -279,7 +277,7 @@ static void FilterErase( filter_t *p_filter, picture_t *p_inpic, ...@@ -279,7 +277,7 @@ static void FilterErase( filter_t *p_filter, picture_t *p_inpic,
i_width = __MIN( i_visible_pitch - i_x, i_width ); i_width = __MIN( i_visible_pitch - i_x, i_width );
/* Copy original pixel buffer */ /* Copy original pixel buffer */
vlc_memcpy( p_outpix, p_inpix, i_pitch * i_lines ); plane_CopyPixels( &p_outpic->p[i_plane], &p_inpic->p[i_plane] );
/* Horizontal linear interpolation of masked areas */ /* Horizontal linear interpolation of masked areas */
p_outpix = p_outpic->p[i_plane].p_pixels + i_y*i_pitch + i_x; p_outpix = p_outpic->p[i_plane].p_pixels + i_y*i_pitch + i_x;
......
...@@ -330,19 +330,19 @@ static void get_custom_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -330,19 +330,19 @@ static void get_custom_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
y2in = y1in + i_pitch; y2in = y1in + i_in_pitch;
y2out = y1out + i_pitch; y2out = y1out + i_out_pitch;
while( y1in < y1end ) while( y1in < y1end )
{ {
*uout++ = crop( (*y1in * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5]) *uout++ = crop( (*y1in * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5])
...@@ -358,12 +358,12 @@ static void get_custom_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -358,12 +358,12 @@ static void get_custom_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
*y2out++ = crop( (*y2in++ * m[0] + (*uin++ - U) * m[1] + (*vin++ -V) * m[2]) *y2out++ = crop( (*y2in++ * m[0] + (*uin++ - U) * m[1] + (*vin++ -V) * m[2])
/ 65536 ); / 65536 );
} }
y1in += 2*i_pitch - i_visible_pitch; y1in += 2*i_in_pitch - i_visible_pitch;
y1out += 2*i_pitch - i_visible_pitch; y1out += 2*i_out_pitch - i_visible_pitch;
uin += i_uv_pitch - i_uv_visible_pitch; uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vin += i_uv_pitch - i_uv_visible_pitch; vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
...@@ -377,14 +377,14 @@ static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -377,14 +377,14 @@ static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
...@@ -399,12 +399,12 @@ static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -399,12 +399,12 @@ static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
*y1out++ = crop( (*y1in++ * m[0] + (*uin++ -U) * m[1] + (*vin++ -V) * m[2]) *y1out++ = crop( (*y1in++ * m[0] + (*uin++ -U) * m[1] + (*vin++ -V) * m[2])
/ 65536 ); / 65536 );
} }
y1in += i_pitch - i_visible_pitch; y1in += i_in_pitch - i_visible_pitch;
y1out += i_pitch - i_visible_pitch; y1out += i_out_pitch - i_visible_pitch;
uin += i_uv_pitch - i_uv_visible_pitch; uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vin += i_uv_pitch - i_uv_visible_pitch; vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
...@@ -425,11 +425,12 @@ static void get_custom_from_packedyuv422( picture_t *p_inpic, ...@@ -425,11 +425,12 @@ static void get_custom_from_packedyuv422( picture_t *p_inpic,
uint8_t *uout = p_outpic->p->p_pixels + i_u_offset; uint8_t *uout = p_outpic->p->p_pixels + i_u_offset;
uint8_t *vout = p_outpic->p->p_pixels + i_v_offset; uint8_t *vout = p_outpic->p->p_pixels + i_v_offset;
const int i_pitch = p_inpic->p->i_pitch; const int i_in_pitch = p_inpic->p->i_pitch;
const int i_out_pitch = p_outpic->p->i_pitch;
const int i_visible_pitch = p_inpic->p->i_visible_pitch; const int i_visible_pitch = p_inpic->p->i_visible_pitch;
const int i_visible_lines = p_inpic->p->i_visible_lines; const int i_visible_lines = p_inpic->p->i_visible_lines;
const uint8_t *yend = yin + i_visible_lines * i_pitch; const uint8_t *yend = yin + i_visible_lines * i_in_pitch;
while( yin < yend ) while( yin < yend )
{ {
const uint8_t *ylend = yin + i_visible_pitch; const uint8_t *ylend = yin + i_visible_pitch;
...@@ -452,12 +453,12 @@ static void get_custom_from_packedyuv422( picture_t *p_inpic, ...@@ -452,12 +453,12 @@ static void get_custom_from_packedyuv422( picture_t *p_inpic,
uin += 4; uin += 4;
vin += 4; vin += 4;
} }
yin += i_pitch - i_visible_pitch; yin += i_in_pitch - i_visible_pitch;
yout += i_pitch - i_visible_pitch; yout += i_out_pitch - i_visible_pitch;
uin += i_pitch - i_visible_pitch; uin += i_in_pitch - i_visible_pitch;
uout += i_pitch - i_visible_pitch; uout += i_out_pitch - i_visible_pitch;
vin += i_pitch - i_visible_pitch; vin += i_in_pitch - i_visible_pitch;
vout += i_pitch - i_visible_pitch; vout += i_out_pitch - i_visible_pitch;
} }
} }
...@@ -473,19 +474,19 @@ static void get_red_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -473,19 +474,19 @@ static void get_red_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
y2in = y1in + i_pitch; y2in = y1in + i_in_pitch;
y2out = y1out + i_pitch; y2out = y1out + i_out_pitch;
while( y1in < y1end ) while( y1in < y1end )
{ {
/* /*
...@@ -506,11 +507,11 @@ static void get_red_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -506,11 +507,11 @@ static void get_red_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
*y2out++ = crop( (*y2in++ * 19594 + (*vin++ - V) * 27473) *y2out++ = crop( (*y2in++ * 19594 + (*vin++ - V) * 27473)
/ 65536 ); / 65536 );
} }
y1in += 2*i_pitch - i_visible_pitch; y1in += 2*i_in_pitch - i_visible_pitch;
y1out += 2*i_pitch - i_visible_pitch; y1out += 2*i_out_pitch - i_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vin += i_uv_pitch - i_uv_visible_pitch; vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
...@@ -527,19 +528,20 @@ static void get_green_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -527,19 +528,20 @@ static void get_green_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
y2in = y1in + i_pitch; y2in = y1in + i_in_pitch;
y2out = y1out + i_pitch; y2out = y1out + i_out_pitch;
while( y1in < y1end ) while( y1in < y1end )
{ {
/* /*
...@@ -560,12 +562,12 @@ static void get_green_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -560,12 +562,12 @@ static void get_green_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
*y2out++ = crop( (*y2in++ * 38470 + (*uin++ - U) * -13239 + (*vin++ -V) * -27473) *y2out++ = crop( (*y2in++ * 38470 + (*uin++ - U) * -13239 + (*vin++ -V) * -27473)
/ 65536 ); / 65536 );
} }
y1in += 2*i_pitch - i_visible_pitch; y1in += 2*i_in_pitch - i_visible_pitch;
y1out += 2*i_pitch - i_visible_pitch; y1out += 2*i_out_pitch - i_visible_pitch;
uin += i_uv_pitch - i_uv_visible_pitch; uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vin += i_uv_pitch - i_uv_visible_pitch; vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
...@@ -581,19 +583,19 @@ static void get_blue_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -581,19 +583,19 @@ static void get_blue_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
y2in = y1in + i_pitch; y2in = y1in + i_in_pitch;
y2out = y1out + i_pitch; y2out = y1out + i_out_pitch;
while( y1in < y1end ) while( y1in < y1end )
{ {
/* /*
...@@ -614,11 +616,11 @@ static void get_blue_from_yuv420( picture_t *p_inpic, picture_t *p_outpic, ...@@ -614,11 +616,11 @@ static void get_blue_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
*y2out++ = crop( (*y2in++ * 7471 + (*uin++ - U) * 13239 ) *y2out++ = crop( (*y2in++ * 7471 + (*uin++ - U) * 13239 )
/ 65536 ); / 65536 );
} }
y1in += 2*i_pitch - i_visible_pitch; y1in += 2*i_in_pitch - i_visible_pitch;
y1out += 2*i_pitch - i_visible_pitch; y1out += 2*i_out_pitch - i_visible_pitch;
uin += i_uv_pitch - i_uv_visible_pitch; uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
...@@ -632,14 +634,14 @@ static void get_red_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -632,14 +634,14 @@ static void get_red_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_inpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
...@@ -659,11 +661,11 @@ static void get_red_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -659,11 +661,11 @@ static void get_red_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
*y1out++ = crop( (*y1in++ * 19595 + (*vin++ - V) * 27473) *y1out++ = crop( (*y1in++ * 19595 + (*vin++ - V) * 27473)
/ 65536 ); / 65536 );
} }
y1in += i_pitch - i_visible_pitch; y1in += i_in_pitch - i_visible_pitch;
y1out += i_pitch - i_visible_pitch; y1out += i_out_pitch - i_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vin += i_uv_pitch - i_uv_visible_pitch; vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
...@@ -678,14 +680,14 @@ static void get_green_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -678,14 +680,14 @@ static void get_green_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
...@@ -705,12 +707,12 @@ static void get_green_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -705,12 +707,12 @@ static void get_green_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
*y1out++ = crop( (*y1in++ * 38470 + (*uin++-U) * -13239 + (*vin++-V) * -27473) *y1out++ = crop( (*y1in++ * 38470 + (*uin++-U) * -13239 + (*vin++-V) * -27473)
/ 65536 ); / 65536 );
} }
y1in += i_pitch - i_visible_pitch; y1in += i_in_pitch - i_visible_pitch;
y1out += i_pitch - i_visible_pitch; y1out += i_out_pitch - i_visible_pitch;
uin += i_uv_pitch - i_uv_visible_pitch; uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vin += i_uv_pitch - i_uv_visible_pitch; vin += p_inpic->p[vp].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
...@@ -724,14 +726,14 @@ static void get_blue_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -724,14 +726,14 @@ static void get_blue_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
uint8_t *uout = p_outpic->p[up].p_pixels; uint8_t *uout = p_outpic->p[up].p_pixels;
uint8_t *vout = p_outpic->p[vp].p_pixels; uint8_t *vout = p_outpic->p[vp].p_pixels;
const int i_pitch = p_inpic->p[yp].i_pitch; const int i_in_pitch = p_inpic->p[yp].i_pitch;
const int i_out_pitch = p_outpic->p[yp].i_pitch;
const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch; const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
const int i_visible_lines = p_inpic->p[yp].i_visible_lines; const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
const int i_uv_pitch = p_inpic->p[up].i_pitch;
const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch; const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
const uint8_t *yend = y1in + i_visible_lines * i_pitch; const uint8_t *yend = y1in + i_visible_lines * i_in_pitch;
while( y1in < yend ) while( y1in < yend )
{ {
const uint8_t *y1end = y1in + i_visible_pitch; const uint8_t *y1end = y1in + i_visible_pitch;
...@@ -751,11 +753,11 @@ static void get_blue_from_yuv422( picture_t *p_inpic, picture_t *p_outpic, ...@@ -751,11 +753,11 @@ static void get_blue_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
*y1out++ = crop( (*y1in++ * 7471 + (*uin++ - U) * 13239 ) *y1out++ = crop( (*y1in++ * 7471 + (*uin++ - U) * 13239 )
/ 65536 ); / 65536 );
} }
y1in += i_pitch - i_visible_pitch; y1in += i_in_pitch - i_visible_pitch;
y1out += i_pitch - i_visible_pitch; y1out += i_out_pitch - i_visible_pitch;
uin += i_uv_pitch - i_uv_visible_pitch; uin += p_inpic->p[up].i_pitch - i_uv_visible_pitch;
uout += i_uv_pitch - i_uv_visible_pitch; uout += p_outpic->p[up].i_pitch - i_uv_visible_pitch;
vout += i_uv_pitch - i_uv_visible_pitch; vout += p_outpic->p[vp].i_pitch - i_uv_visible_pitch;
} }
} }
......
...@@ -252,7 +252,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -252,7 +252,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
const int i_visible_lines = p_pic->p[i_plane].i_visible_lines; const int i_visible_lines = p_pic->p[i_plane].i_visible_lines;
const int i_visible_pitch = p_pic->p[i_plane].i_visible_pitch; const int i_visible_pitch = p_pic->p[i_plane].i_visible_pitch;
const int i_pitch = p_pic->p[i_plane].i_pitch; const int i_in_pitch = p_pic->p[i_plane].i_pitch;
int i_line, i_col; int i_line, i_col;
const int x_factor = p_pic->p[Y_PLANE].i_visible_pitch/i_visible_pitch-1; const int x_factor = p_pic->p[Y_PLANE].i_visible_pitch/i_visible_pitch-1;
...@@ -264,7 +264,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -264,7 +264,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{ {
type_t t_value = 0; type_t t_value = 0;
int x; int x;
const int c = i_line*i_pitch+i_col; const int c = i_line*i_in_pitch+i_col;
for( x = __MAX( -i_dim, -i_col*(x_factor+1) ); for( x = __MAX( -i_dim, -i_col*(x_factor+1) );
x <= __MIN( i_dim, (i_visible_pitch - i_col)*(x_factor+1) + 1 ); x <= __MIN( i_dim, (i_visible_pitch - i_col)*(x_factor+1) + 1 );
x++ ) x++ )
...@@ -281,17 +281,17 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -281,17 +281,17 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{ {
type_t t_value = 0; type_t t_value = 0;
int y; int y;
const int c = i_line*i_pitch+i_col; const int c = i_line*i_in_pitch+i_col;
for( y = __MAX( -i_dim, (-i_line)*(y_factor+1) ); for( y = __MAX( -i_dim, (-i_line)*(y_factor+1) );
y <= __MIN( i_dim, (i_visible_lines - i_line)*(y_factor+1) - 1 ); y <= __MIN( i_dim, (i_visible_lines - i_line)*(y_factor+1) - 1 );
y++ ) y++ )
{ {
t_value += pt_distribution[y+i_dim] * t_value += pt_distribution[y+i_dim] *
pt_buffer[c+(y>>y_factor)*i_pitch]; pt_buffer[c+(y>>y_factor)*i_in_pitch];
} }
const type_t t_scale = pt_scale[(i_line<<y_factor)*(i_pitch<<x_factor)+(i_col<<x_factor)]; const type_t t_scale = pt_scale[(i_line<<y_factor)*(i_in_pitch<<x_factor)+(i_col<<x_factor)];
p_out[c] = (uint8_t)(t_value / t_scale); // FIXME wouldn't it be better to round instead of trunc ? p_out[i_line * p_outpic->p[i_plane].i_pitch + i_col] = (uint8_t)(t_value / t_scale); // FIXME wouldn't it be better to round instead of trunc ?
} }
} }
} }
......
...@@ -360,12 +360,8 @@ static void FilterGradient( filter_t *p_filter, picture_t *p_inpic, ...@@ -360,12 +360,8 @@ static void FilterGradient( filter_t *p_filter, picture_t *p_inpic,
if( p_filter->p_sys->b_cartoon ) if( p_filter->p_sys->b_cartoon )
{ {
vlc_memcpy( p_outpic->p[U_PLANE].p_pixels, plane_CopyPixels( &p_outpic->p[U_PLANE], &p_inpic->p[U_PLANE] );
p_inpic->p[U_PLANE].p_pixels, plane_CopyPixels( &p_outpic->p[V_PLANE], &p_inpic->p[V_PLANE] );
p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
p_inpic->p[V_PLANE].p_pixels,
p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
} }
else else
{ {
...@@ -504,12 +500,8 @@ static void FilterEdge( filter_t *p_filter, picture_t *p_inpic, ...@@ -504,12 +500,8 @@ static void FilterEdge( filter_t *p_filter, picture_t *p_inpic,
if( p_filter->p_sys->b_cartoon ) if( p_filter->p_sys->b_cartoon )
{ {
vlc_memcpy( p_outpic->p[U_PLANE].p_pixels, plane_CopyPixels( &p_outpic->p[U_PLANE], &p_inpic->p[U_PLANE] );
p_inpic->p[U_PLANE].p_pixels, plane_CopyPixels( &p_outpic->p[V_PLANE], &p_inpic->p[V_PLANE] );
p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
vlc_memcpy( p_outpic->p[V_PLANE].p_pixels,
p_inpic->p[V_PLANE].p_pixels,
p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
} }
else else
{ {
...@@ -687,15 +679,9 @@ static void FilterHough( filter_t *p_filter, picture_t *p_inpic, ...@@ -687,15 +679,9 @@ static void FilterHough( filter_t *p_filter, picture_t *p_inpic,
vlc_memset( p_hough, 0, i_diag * i_nb_steps * sizeof(int) ); vlc_memset( p_hough, 0, i_diag * i_nb_steps * sizeof(int) );
vlc_memcpy( plane_CopyPixels( &p_outpic->p[Y_PLANE], &p_inpic->p[Y_PLANE] );
p_outpic->p[Y_PLANE].p_pixels, p_inpic->p[Y_PLANE].p_pixels, plane_CopyPixels( &p_outpic->p[U_PLANE], &p_inpic->p[U_PLANE] );
p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch ); plane_CopyPixels( &p_outpic->p[V_PLANE], &p_inpic->p[V_PLANE] );
vlc_memcpy(
p_outpic->p[U_PLANE].p_pixels, p_inpic->p[U_PLANE].p_pixels,
p_outpic->p[U_PLANE].i_lines * p_outpic->p[U_PLANE].i_pitch );
vlc_memcpy(
p_outpic->p[V_PLANE].p_pixels, p_inpic->p[V_PLANE].p_pixels,
p_outpic->p[V_PLANE].i_lines * p_outpic->p[V_PLANE].i_pitch );
GaussianConvolution( p_inpic, p_smooth ); GaussianConvolution( p_inpic, p_smooth );
......
...@@ -43,7 +43,6 @@ static int Create ( vlc_object_t * ); ...@@ -43,7 +43,6 @@ static int Create ( vlc_object_t * );
static void Destroy ( vlc_object_t * ); static void Destroy ( vlc_object_t * );
static picture_t *Filter ( filter_t *, picture_t * ); static picture_t *Filter ( filter_t *, picture_t * );
static void RenderBlur ( filter_sys_t *, picture_t *, picture_t * ); static void RenderBlur ( filter_sys_t *, picture_t *, picture_t * );
static void Copy ( filter_t *, picture_t * );
static int MotionBlurCallback( vlc_object_t *, char const *, static int MotionBlurCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
...@@ -79,11 +78,11 @@ static const char *const ppsz_filter_options[] = { ...@@ -79,11 +78,11 @@ static const char *const ppsz_filter_options[] = {
*****************************************************************************/ *****************************************************************************/
struct filter_sys_t struct filter_sys_t
{ {
picture_t *p_tmp;
bool b_first;
vlc_spinlock_t lock; vlc_spinlock_t lock;
int i_factor; int i_factor;
uint8_t **pp_planes;
int i_planes;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -98,6 +97,14 @@ static int Create( vlc_object_t *p_this ) ...@@ -98,6 +97,14 @@ static int Create( vlc_object_t *p_this )
if( p_filter->p_sys == NULL ) if( p_filter->p_sys == NULL )
return VLC_ENOMEM; return VLC_ENOMEM;
p_filter->p_sys->p_tmp = picture_NewFromFormat( &p_filter->fmt_in.video );
if( !p_filter->p_sys->p_tmp )
{
free( p_filter->p_sys );
return VLC_ENOMEM;
}
p_filter->p_sys->b_first = true;
p_filter->pf_video_filter = Filter; p_filter->pf_video_filter = Filter;
config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
...@@ -109,8 +116,6 @@ static int Create( vlc_object_t *p_this ) ...@@ -109,8 +116,6 @@ static int Create( vlc_object_t *p_this )
var_AddCallback( p_filter, FILTER_PREFIX "factor", var_AddCallback( p_filter, FILTER_PREFIX "factor",
MotionBlurCallback, p_filter->p_sys ); MotionBlurCallback, p_filter->p_sys );
p_filter->p_sys->pp_planes = NULL;
p_filter->p_sys->i_planes = 0;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -126,9 +131,7 @@ static void Destroy( vlc_object_t *p_this ) ...@@ -126,9 +131,7 @@ static void Destroy( vlc_object_t *p_this )
MotionBlurCallback, p_filter->p_sys ); MotionBlurCallback, p_filter->p_sys );
vlc_spin_destroy( &p_filter->p_sys->lock ); vlc_spin_destroy( &p_filter->p_sys->lock );
while( p_filter->p_sys->i_planes-- ) picture_Release( p_filter->p_sys->p_tmp );
free( p_filter->p_sys->pp_planes[p_filter->p_sys->i_planes] );
free( p_filter->p_sys->pp_planes );
free( p_filter->p_sys ); free( p_filter->p_sys );
} }
...@@ -149,24 +152,16 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -149,24 +152,16 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
return NULL; return NULL;
} }
if( !p_sys->pp_planes ) if( p_sys->b_first )
{ {
/* initialise our picture buffer */ picture_CopyPixels( p_sys->p_tmp, p_pic );
int i_plane; p_sys->b_first = false;
p_sys->i_planes = p_pic->i_planes;
p_sys->pp_planes =
(uint8_t**)malloc( p_sys->i_planes * sizeof( uint8_t * ) );
for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
{
p_sys->pp_planes[i_plane] = (uint8_t*)malloc(
p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_visible_lines );
}
Copy( p_filter, p_pic );
} }
/* Get a new picture */ /* Get a new picture */
RenderBlur( p_sys, p_pic, p_outpic ); RenderBlur( p_sys, p_pic, p_outpic );
Copy( p_filter, p_outpic );
picture_CopyPixels( p_sys->p_tmp, p_outpic );
return CopyInfoAndRelease( p_outpic, p_pic ); return CopyInfoAndRelease( p_outpic, p_pic );
} }
...@@ -186,14 +181,13 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, ...@@ -186,14 +181,13 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic,
for( i_plane = 0; i_plane < p_outpic->i_planes; i_plane++ ) for( i_plane = 0; i_plane < p_outpic->i_planes; i_plane++ )
{ {
uint8_t *p_old, *p_new, *p_out, *p_out_end, *p_out_line_end; uint8_t *p_old, *p_new, *p_out, *p_out_end, *p_out_line_end;
const int i_pitch = p_outpic->p[i_plane].i_pitch;
const int i_visible_pitch = p_outpic->p[i_plane].i_visible_pitch; const int i_visible_pitch = p_outpic->p[i_plane].i_visible_pitch;
const int i_visible_lines = p_outpic->p[i_plane].i_visible_lines; const int i_visible_lines = p_outpic->p[i_plane].i_visible_lines;
p_out = p_outpic->p[i_plane].p_pixels; p_out = p_outpic->p[i_plane].p_pixels;
p_new = p_newpic->p[i_plane].p_pixels; p_new = p_newpic->p[i_plane].p_pixels;
p_old = p_sys->pp_planes[i_plane]; p_old = p_sys->p_tmp->p[i_plane].p_pixels;
p_out_end = p_out + i_pitch * i_visible_lines; p_out_end = p_out + p_outpic->p[i_plane].i_pitch * i_visible_lines;
while ( p_out < p_out_end ) while ( p_out < p_out_end )
{ {
p_out_line_end = p_out + i_visible_pitch; p_out_line_end = p_out + i_visible_pitch;
...@@ -204,24 +198,13 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic, ...@@ -204,24 +198,13 @@ static void RenderBlur( filter_sys_t *p_sys, picture_t *p_newpic,
((*p_new++) * i_newfactor)) >> 7; ((*p_new++) * i_newfactor)) >> 7;
} }
p_old += i_pitch - i_visible_pitch; p_old += p_sys->p_tmp->p[i_plane].i_pitch - i_visible_pitch;
p_new += i_pitch - i_visible_pitch; p_new += p_newpic->p[i_plane].i_pitch - i_visible_pitch;
p_out += i_pitch - i_visible_pitch; p_out += p_outpic->p[i_plane].i_pitch - i_visible_pitch;
} }
} }
} }
static void Copy( filter_t *p_filter, picture_t *p_pic )
{
int i_plane;
for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
{
vlc_memcpy(
p_filter->p_sys->pp_planes[i_plane], p_pic->p[i_plane].p_pixels,
p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_visible_lines );
}
}
static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var, static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void *p_data ) void *p_data )
......
...@@ -168,13 +168,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic ) ...@@ -168,13 +168,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels; const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch; const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
if( !p_sys->b_old )
{
picture_Copy( p_sys->p_old, p_inpic );
p_sys->b_old = true;
return p_inpic;
}
p_outpic = filter_NewPicture( p_filter ); p_outpic = filter_NewPicture( p_filter );
if( !p_outpic ) if( !p_outpic )
{ {
...@@ -183,6 +176,14 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic ) ...@@ -183,6 +176,14 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
} }
picture_Copy( p_outpic, p_inpic ); picture_Copy( p_outpic, p_inpic );
if( !p_sys->b_old )
{
picture_Copy( p_sys->p_old, p_inpic );
picture_Release( p_inpic );
p_sys->b_old = true;
return p_outpic;
}
/** /**
* Substract Y planes * Substract Y planes
*/ */
......
...@@ -100,7 +100,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -100,7 +100,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
const int i_num_lines = p_pic->p[i_index].i_visible_lines; const int i_num_lines = p_pic->p[i_index].i_visible_lines;
const int i_num_cols = p_pic->p[i_index].i_visible_pitch; const int i_num_cols = p_pic->p[i_index].i_visible_pitch;
const int i_pitch = p_pic->p[i_index].i_pitch; const int i_in_pitch = p_pic->p[i_index].i_pitch;
const int i_out_pitch = p_outpic->p[i_index].i_pitch;
int i_line, i_col; int i_line, i_col;
...@@ -109,7 +110,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -109,7 +110,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
if( vlc_mrand48()&7 ) if( vlc_mrand48()&7 )
{ {
/* line isn't noisy */ /* line isn't noisy */
vlc_memcpy( p_out+i_line*i_pitch, p_in+i_line*i_pitch, vlc_memcpy( p_out+i_line*i_out_pitch, p_in+i_line*i_in_pitch,
i_num_cols ); i_num_cols );
} }
else else
...@@ -120,12 +121,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -120,12 +121,12 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{ {
if( ((unsigned)vlc_mrand48())%noise_level ) if( ((unsigned)vlc_mrand48())%noise_level )
{ {
p_out[i_line*i_pitch+i_col] = p_out[i_line*i_out_pitch+i_col] =
p_in[i_line*i_pitch+i_col]; p_in[i_line*i_in_pitch+i_col];
} }
else else
{ {
p_out[i_line*i_pitch+i_col] = (vlc_mrand48()&3)*0x7f; p_out[i_line*i_out_pitch+i_col] = (vlc_mrand48()&3)*0x7f;
} }
} }
} }
......
...@@ -174,8 +174,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -174,8 +174,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
} }
/* luminance */ /* luminance */
vlc_memcpy( p_outpic->p[Y_PLANE].p_pixels, p_pic->p[Y_PLANE].p_pixels, plane_CopyPixels( &p_outpic->p[Y_PLANE], &p_pic->p[Y_PLANE] );
p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch );
/* image visualization */ /* image visualization */
fmt_out = p_filter->fmt_out.video; fmt_out = p_filter->fmt_out.video;
......
...@@ -184,8 +184,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -184,8 +184,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
/* process the Y plane */ /* process the Y plane */
p_src = p_pic->p[Y_PLANE].p_pixels; p_src = p_pic->p[Y_PLANE].p_pixels;
p_out = p_outpic->p[Y_PLANE].p_pixels; p_out = p_outpic->p[Y_PLANE].p_pixels;
i_src_pitch = p_pic->p[Y_PLANE].i_visible_pitch; i_src_pitch = p_pic->p[Y_PLANE].i_pitch;
i_out_pitch = p_outpic->p[Y_PLANE].i_visible_pitch; i_out_pitch = p_outpic->p[Y_PLANE].i_pitch;
/* perform convolution only on Y plane. Avoid border line. */ /* perform convolution only on Y plane. Avoid border line. */
vlc_mutex_lock( &p_filter->p_sys->lock ); vlc_mutex_lock( &p_filter->p_sys->lock );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment