From faf02b121faedf39385fd8375f6a8742b59887dd Mon Sep 17 00:00:00 2001 From: c0ntrol Date: Sun, 23 Jun 2019 22:02:15 +0200 Subject: [PATCH] add new FX Bloom (uses openMP) --- veejay-current/veejay-server/configure.ac | 4 +- .../veejay-server/libvje/Makefile.am | 2 +- .../veejay-server/libvje/effects/bloom.c | 160 ++++++++++++++++++ .../veejay-server/libvje/effects/bloom.h | 27 +++ .../veejay-server/libvje/effects/common.c | 2 +- .../veejay-server/libvje/internal.h | 4 +- .../veejay-server/libvje/vj-effect.c | 2 + .../veejay-server/libvje/vj-effman.c | 3 + 8 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 veejay-current/veejay-server/libvje/effects/bloom.c create mode 100644 veejay-current/veejay-server/libvje/effects/bloom.h diff --git a/veejay-current/veejay-server/configure.ac b/veejay-current/veejay-server/configure.ac index 30844c2e..8488ff76 100644 --- a/veejay-current/veejay-server/configure.ac +++ b/veejay-current/veejay-server/configure.ac @@ -282,7 +282,7 @@ case $host_cpu in if test "x$enable_debug" != "xyes" ; then SUBSAMPLE_CFLAGS="" - VJE_CFLAGS="-O3 -ftree-vectorize -ffast-math" + VJE_CFLAGS="-O3 -ftree-vectorize -ffast-math -fopenmp" fi AC_MSG_RESULT([x86]) @@ -296,7 +296,7 @@ case $host_cpu in VJE_CFLAGS="-O3 -ffast-math -ftree-vectorize -m64 -fPIC -DPIC" SUBSAMPLE_CFLAGS="-m64 -fPIC -DPIC" fi - CFLAGS="$CFLAGS -m64 -fPIC -DPIC" + CFLAGS="$CFLAGS -m64 -fPIC -DPIC -fopenmp" AC_MSG_RESULT([x86_64]) ;; diff --git a/veejay-current/veejay-server/libvje/Makefile.am b/veejay-current/veejay-server/libvje/Makefile.am index 7bbc9a2f..4873d3ef 100644 --- a/veejay-current/veejay-server/libvje/Makefile.am +++ b/veejay-current/veejay-server/libvje/Makefile.am @@ -54,6 +54,6 @@ libvje_la_SOURCES = vj-effect.c vj-effman.c effects/common.c \ effects/chromamagickalpha.c effects/magicoverlaysalpha.c effects/gaussblur.c effects/levelcorrection.c \ effects/masktransition.c effects/alphadampen.c effects/passthrough.c effects/alphatransition.c effects/randnoise.c \ effects/bgsubtractgauss.c effects/bwotsu.c effects/meanfilter.c effects/bgpush.c effects/pixelsort.c effects/pixelsortalpha.c \ - effects/stretch.c + effects/stretch.c effects/bloom.c diff --git a/veejay-current/veejay-server/libvje/effects/bloom.c b/veejay-current/veejay-server/libvje/effects/bloom.c new file mode 100644 index 00000000..ace89ed2 --- /dev/null +++ b/veejay-current/veejay-server/libvje/effects/bloom.c @@ -0,0 +1,160 @@ +/* + * Linux VeeJay + * + * Copyright(C)2002-2019 Niels Elburg + * + * 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 (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. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307 , USA. + */ + +#include "common.h" +#include +#include "bloom.h" + +vj_effect *bloom_init(int width,int height) +{ + vj_effect *ve = (vj_effect *) vj_calloc(sizeof(vj_effect)); + ve->num_params = 4; + 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 */ + ve->limits[0][0] = 0; + ve->limits[1][0] = 64; + ve->limits[0][1] = 0; + ve->limits[1][1] = 64; + ve->limits[0][2] = 0; + ve->limits[1][2] = 64; + ve->limits[0][3] = 0; + ve->limits[1][3] = 255; + + ve->defaults[0] = 16; + ve->defaults[1] = 22; + ve->defaults[2] = 41; + ve->defaults[3] = 180; + ve->description = "Bloom (Glow)"; + ve->sub_format = -1; + + ve->param_description = vje_build_param_list( ve->num_params, "Blur Radius 1", "Blur Radius 2","Blur Radius 3", "Luminance Threshold" ); + + return ve; +} + +uint8_t *bloom_buf = NULL; +int bloom_malloc(int width, int height) +{ + if(bloom_buf == NULL) { + bloom_buf = (uint8_t*) vj_calloc(sizeof(uint8_t) * RUP8(width * height * 8)); + } + + return 1; +} + +void bloom_free() { + if(bloom_buf) { + free(bloom_buf); + bloom_buf = NULL; + } +} + +static void rhblur_apply( uint8_t *dst , uint8_t *src, int w, int h, int r) +{ + int y; + for(y = 0; y < h ; y ++ ) + { + blur( dst + y * w, src + y *w , w, r,1, 1); + } + +} +static void rvblur_apply( uint8_t *dst, uint8_t *src, int w, int h, int r) +{ + int x; + for(x=0; x < w; x++) + { + blur( dst + x, src + x , h, r, w, w ); + } +} + + +void bloom_apply(VJFrame *frame, int a0, int b0, int c0, int threshold) { + + const unsigned int len = frame->len; + int width = frame->width; + int height = frame->height; + uint8_t *L = frame->data[0]; + uint8_t *B = bloom_buf; + uint8_t *B1h = B + RUP8(len); + uint8_t *B1v = B1h + RUP8(len); + uint8_t *B2h = B1v + RUP8(len); + uint8_t *B2v = B2h + RUP8(len); + uint8_t *B3h = B2v + RUP8(len); + uint8_t *B3v = B3h + RUP8(len); + + for( int i = 0; i < len; i ++ ) { + if( L[i] > threshold ) + B[i] = L[i]; + else + B[i] = 0; + + } + // just view threshold mask + if( a0 == 0 && b0 == 0 && c0 == 0 ) { + veejay_memcpy( frame->data[0], B, len ); + veejay_memset( frame->data[1], 128, frame->uv_len ); + veejay_memset( frame->data[2], 128, frame->uv_len ); + return; + } + +#pragma omp parallel + { + #pragma omp single + { + #pragma omp task + { + if( a0 > 0 ) { + rhblur_apply( B1h, B, width, height, a0 ); + rvblur_apply( B1v, B1h, width, height, a0 ); + } + } + + #pragma omp task + { + if( b0 > 0 ) { + rhblur_apply( B2h, B, width, height, b0 ); + rvblur_apply( B2v, B2h, width, height, b0 ); + } + } + + #pragma omp task + { + if( c0 > 0 ) { + rhblur_apply( B3h, B, width, height, c0 ); + rvblur_apply( B3v, B3h, width, height, c0 ); + } + } + + #pragma omp taskwait + + } + } // end parallel region + + for( int i = 0; i < len; i ++ ) { + uint16_t v = B1v[i] + B2v[i] + B3v[i] + L[i]; + + if( v > 0xff ) + v = 0xff; // white + + L[i] = (uint8_t) v; + } + +} diff --git a/veejay-current/veejay-server/libvje/effects/bloom.h b/veejay-current/veejay-server/libvje/effects/bloom.h new file mode 100644 index 00000000..56881ae0 --- /dev/null +++ b/veejay-current/veejay-server/libvje/effects/bloom.h @@ -0,0 +1,27 @@ +/* + * Linux VeeJay + * + * Copyright(C)2002-2019 Niels Elburg + * + * 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 (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. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307 , USA. + */ + +#ifndef BLOOM_H +#define BLOOM_H +vj_effect *bloom_init(int w, int h); +int bloom_malloc(int w, int h); +void bloom_free(); +void bloom_apply(VJFrame *Frame, int a0, int b0, int c0, int threshold); +#endif diff --git a/veejay-current/veejay-server/libvje/effects/common.c b/veejay-current/veejay-server/libvje/effects/common.c index ea6dfa5e..3f8913dc 100644 --- a/veejay-current/veejay-server/libvje/effects/common.c +++ b/veejay-current/veejay-server/libvje/effects/common.c @@ -1338,7 +1338,7 @@ void blur(uint8_t *dst, uint8_t *src, int w, int radius, int dstStep, int srcSte } sum+= src[radius*srcStep]; - for(x=0; x>16; } diff --git a/veejay-current/veejay-server/libvje/internal.h b/veejay-current/veejay-server/libvje/internal.h index 31a13761..ae81a627 100644 --- a/veejay-current/veejay-server/libvje/internal.h +++ b/veejay-current/veejay-server/libvje/internal.h @@ -188,6 +188,7 @@ #include "./effects/widthmirror.h" #include "./effects/zoom.h" #include "./effects/stretch.h" +#include "./effects/bloom.h" #include "./transitions/3bar.h" #include "./transitions/fadecolor.h" #include "./transitions/fadecolorrgb.h" @@ -199,7 +200,7 @@ #include "./transitions/vbar.h" #include "./transitions/wipe.h" -#define VJ_IMAGE_EFFECT_MIN 87 +#define VJ_IMAGE_EFFECT_MIN 86 #define VJ_IMAGE_EFFECT_MAX 199 #define VJ_VIDEO_EFFECT_MIN 200 @@ -432,6 +433,7 @@ enum { VJ_IMAGE_EFFECT_PIXELSORT = 89, VJ_IMAGE_EFFECT_PIXELSORTALPHA = 88, VJ_IMAGE_EFFECT_CREATIVESTRETCH = 87, + VJ_IMAGE_EFFECT_BLOOM = 86, VJ_IMAGE_EFFECT_DUMMY=0, }; diff --git a/veejay-current/veejay-server/libvje/vj-effect.c b/veejay-current/veejay-server/libvje/vj-effect.c index 947f9fdc..5cef248a 100644 --- a/veejay-current/veejay-server/libvje/vj-effect.c +++ b/veejay-current/veejay-server/libvje/vj-effect.c @@ -129,6 +129,7 @@ static struct { pixelsortalpha_malloc,pixelsortalpha_free,NULL,VJ_IMAGE_EFFECT_PIXELSORTALPHA }, { raster_malloc,raster_free,NULL,VJ_IMAGE_EFFECT_RASTER }, { dither_malloc,dither_free, NULL, VJ_IMAGE_EFFECT_DITHER }, +{ bloom_malloc,bloom_free, NULL, VJ_IMAGE_EFFECT_BLOOM }, { NULL,NULL,NULL,0}, }; @@ -560,6 +561,7 @@ void vj_effect_initialize(int width, int height, int full_range, int custom_cfg) vj_effects[VJ_IMAGE_EFFECT_POSTERIZE2] = posterize2_init(width,height); vj_effects[VJ_IMAGE_EFFECT_PIXELSORT] = pixelsort_init(width,height); vj_effects[VJ_IMAGE_EFFECT_PIXELSORTALPHA] = pixelsortalpha_init(width,height); + vj_effects[VJ_IMAGE_EFFECT_BLOOM] = bloom_init(width,height); max_width = width; max_height = height; diff --git a/veejay-current/veejay-server/libvje/vj-effman.c b/veejay-current/veejay-server/libvje/vj-effman.c index 9c03c3ab..700f34fd 100644 --- a/veejay-current/veejay-server/libvje/vj-effman.c +++ b/veejay-current/veejay-server/libvje/vj-effman.c @@ -437,6 +437,9 @@ static void vj_effman_apply_image_effect( case VJ_IMAGE_EFFECT_PIXELSORTALPHA: pixelsortalpha_apply(frames[0],arg[0],arg[1]); break; + case VJ_IMAGE_EFFECT_BLOOM: + bloom_apply(frames[0],arg[0],arg[1],arg[2],arg[3]); + break; } }