From 14733d68a40a03a62ec2ffd10c917038cd9c1bb7 Mon Sep 17 00:00:00 2001 From: Niels Elburg Date: Mon, 19 Mar 2007 12:53:14 +0000 Subject: [PATCH] fixed possible segfault in mmx blur git-svn-id: svn://code.dyne.org/veejay/trunk@867 eb8d1916-c9e9-0310-b8de-cf0c9472ead5 --- veejay-current/libvje/effects/diff.c | 2 +- veejay-current/libvje/effects/radioactive.c | 75 ++++++++++----------- veejay-current/libvje/effects/softblur.c | 2 +- veejay-current/libvje/effects/timedistort.c | 2 +- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/veejay-current/libvje/effects/diff.c b/veejay-current/libvje/effects/diff.c index 3868cc7c..03e0749e 100644 --- a/veejay-current/libvje/effects/diff.c +++ b/veejay-current/libvje/effects/diff.c @@ -78,7 +78,7 @@ int diff_malloc(void **d, int width, int height) my->current = my->data + (width*height); if(static_bg == NULL) - static_bg = (uint8_t*) vj_calloc( ru8(width * height * sizeof(uint8_t)) ); + static_bg = (uint8_t*) vj_calloc( ru8( width + width * height * sizeof(uint8_t)) ); return 1; } diff --git a/veejay-current/libvje/effects/radioactive.c b/veejay-current/libvje/effects/radioactive.c index 7f210754..6cae798f 100644 --- a/veejay-current/libvje/effects/radioactive.c +++ b/veejay-current/libvje/effects/radioactive.c @@ -49,20 +49,21 @@ vj_effect *radioactivetv_init(int w, int h) ve->limits[1][2] = 255; ve->limits[0][3] = 0; //diff threhsold ve->limits[1][3] = 255; - ve->defaults[0] = 2; + ve->defaults[0] = 0; ve->defaults[1] = 95; ve->defaults[2] = 0; - ve->defaults[3] = 59; + ve->defaults[3] = 40; ve->description = "RadioActive EffecTV"; ve->sub_format = 1; ve->extra_frame = 1; ve->has_user = 0; return ve; } +#define RUP8(num)(((num)+8)&~8) + static uint8_t *diffbuf = NULL; static uint8_t *blurzoombuf = NULL; -static uint8_t *snapframe = NULL; static int *blurzoomx = NULL; static int *blurzoomy = NULL; static int buf_width_blocks = 0; @@ -124,7 +125,7 @@ static void kentaro_blur(void) for(y=buf_height-2; y>0; y--) { for(x=width-2; x>0; x--) { - v = (*(p-width) + *(p-1) + *(p+1) + *(p+width))>>2 - 1; + v = (*(p-width) + *(p-1) + *(p+1) + *(p+width))/4 - 1; if(v == 255) v = 0; *q = v; p++; @@ -179,12 +180,12 @@ int radioactivetv_malloc(int w, int h) buf_margin_left = (w - buf_width ) >> 1; buf_margin_right = (w - buf_width - buf_margin_left); - blurzoombuf = (uint8_t*) vj_malloc( buf_area * 2 ); + blurzoombuf = (uint8_t*) vj_calloc( RUP8(buf_area * 2 )); if(!blurzoombuf) return 0; - blurzoomx = (int*) vj_malloc(buf_width * sizeof(int)); - blurzoomy = (int*) vj_malloc(buf_width * sizeof(int)); + blurzoomx = (int*) vj_calloc( RUP8(buf_width * sizeof(int))); + blurzoomy = (int*) vj_calloc( RUP8(buf_width * sizeof(int))); if( blurzoomx == NULL || blurzoomy == NULL ) { @@ -192,13 +193,13 @@ int radioactivetv_malloc(int w, int h) return 0; } - snapframe = (uint8_t*) vj_malloc( w * h * sizeof(uint8_t)); - diffbuf = (uint8_t*) vj_malloc( w * h * sizeof(uint8_t)); + diffbuf = (uint8_t*) vj_malloc( RUP8((4*w) + 2 * w * h * sizeof(uint8_t))); setTable(); first_frame = 0; - + last_mode = 0; + ratio_ = 0.95; return 1; } @@ -212,8 +213,8 @@ void radioactivetv_free() if(blurzoomy ) free(blurzoomy); blurzoomy = NULL; - if(snapframe) free(snapframe); if(diffbuf) free(diffbuf); + diffbuf = NULL; } @@ -222,6 +223,7 @@ void radioactivetv_apply( VJFrame *frame, VJFrame *blue, int width, int height, { unsigned int x, y; uint8_t *diff = diffbuf; + uint8_t *prev = diff + frame->len; const int len = frame->len; uint8_t *lum = frame->data[0]; uint8_t *dstY = lum; @@ -234,7 +236,7 @@ void radioactivetv_apply( VJFrame *frame, VJFrame *blue, int width, int height, float new_ratio = ratio_; VJFrame smooth; veejay_memcpy( &smooth, frame, sizeof(VJFrame)); - smooth.data[0] = diffbuf; + smooth.data[0] = prev; //@ set new zoom ratio new_ratio = (snapRatio * 0.01); @@ -254,7 +256,8 @@ void radioactivetv_apply( VJFrame *frame, VJFrame *blue, int width, int height, if( !first_frame ) { //@ take current - veejay_memcpy( diff, lum , len ); + veejay_memcpy( prev, lum , len ); + softblur_apply( &smooth, width,height,0); first_frame++; return; } @@ -263,76 +266,74 @@ void radioactivetv_apply( VJFrame *frame, VJFrame *blue, int width, int height, { case 0: for( y = 0; y < len; y ++ ) { - if( abs(lum[y] - diff[y]) < threshold ) - diff[y] = 0; - else - diff[y] = 0xff; + diff[y] = abs(lum[y] - prev[y]); + if(diff[y] < threshold ) + diff[y] = 0; + prev[y] = lum[y]; } break; case 1: for( y = 0; y < len; y ++ ){ - diff[y] = ( diff[y] >> 1 ) + lum[y] >> 1; + diff[y] = ( prev[y] >> 1 ) + lum[y] >> 1; if( diff[y] < threshold ) diff[y] = 0; + prev[y] = lum[y]; } break; case 2: threshold = 0xff - threshold; for( y = 0; y < len; y ++ ) { - diff[y] = abs( lum[y] - diff[y] ); - diff[y] = (lum[y] - diff[y])>>1; + diff[y] = abs( lum[y] - prev[y] ); + diff[y] = (lum[y] - prev[y])>>1; if( diff[y] < threshold ) - { diff[y] = 0; - } + prev[y] = lum[y]; } break; case 3: for( y = 0; y < len; y ++ ) { - diff[y] = abs( lum[y] - diff[y] ); - diff[y] = (diff[y] + lum[y] + lum[y] + lum[y])>>2; + diff[y] = abs( lum[y] - prev[y] ); + diff[y] = (prev[y] + lum[y] + lum[y] + lum[y])>>2; if( diff[y] < threshold ) - { diff[y] = 0; - } + prev[y] = diff[y]; } break; case 4: threshold = 0xff - threshold; for( y = 0; y < len; y ++ ) { - diff[y] = abs( lum[y] - diff[y] ); - diff[y] = (lum[y] - diff[y])>>1; + diff[y] = abs( lum[y] - prev[y] ); + diff[y] = (lum[y] - prev[y])>>1; if( diff[y] < threshold ) { if(diff[y]) diff[y]--; } + prev[y] = lum[y]; } break; case 5: for( y = 0; y < len; y ++ ){ - if( abs( lum[y] - diff[y]) > threshold ) + if( abs( lum[y] - prev[y]) > threshold ) diff[y] = 0xff; else diff[y] = 0; + prev[y] = lum[y]; } break; case 6: threshold = 255 - threshold; for( y = 0; y < len; y ++ ){ - if( abs( lum[y] - diff[y]) > threshold ) + if( abs( lum[y] - prev[y]) > threshold ) diff[y] = lum[y]>>2; else diff[y] = 0; + prev[y] = lum[y]; } break; } - - //@ to the blur zoom - - blurzoomcore(); - + softblur_apply( &smooth, width,height,0); uint8_t *diff_ptr = diff; diff_ptr += buf_margin_left; @@ -352,9 +353,7 @@ void radioactivetv_apply( VJFrame *frame, VJFrame *blue, int width, int height, veejay_memcpy( dstY, blurzoombuf, len ); } - veejay_memcpy( diff, lum , len ); - softblur_apply( &smooth, width,height,0); - + blurzoomcore(); p = blurzoombuf; uint32_t k =0; diff --git a/veejay-current/libvje/effects/softblur.c b/veejay-current/libvje/effects/softblur.c index 1e76c62d..d2cdf5ff 100644 --- a/veejay-current/libvje/effects/softblur.c +++ b/veejay-current/libvje/effects/softblur.c @@ -159,7 +159,7 @@ static void mmx_blur(uint8_t *buffer, int width, int height) len = (width*height)-1; - for (i = len; i > scrsh; i -= 4) { + for (i = len-1; i > scrsh; i -= 4) { __asm __volatile ("\n\t movd %[buf], %%mm0" "\n\t movd %[add1], %%mm1" diff --git a/veejay-current/libvje/effects/timedistort.c b/veejay-current/libvje/effects/timedistort.c index 9c0e77cc..ec4efb97 100644 --- a/veejay-current/libvje/effects/timedistort.c +++ b/veejay-current/libvje/effects/timedistort.c @@ -72,7 +72,7 @@ int timedistort_malloc( int w, int h ) { unsigned int i; if(nonmap) timedistort_free(); - nonmap = vj_malloc( RUP8(2 * w * h) * sizeof(uint8_t)); + nonmap = vj_malloc( RUP8(w + 2 * w * h) * sizeof(uint8_t)); if(!nonmap) return 0;