Skip to content

Commit

Permalink
Improved blur
Browse files Browse the repository at this point in the history
  • Loading branch information
connornishijima committed May 24, 2024
1 parent e00214a commit a180d8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/gpu_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void run_gpu() {

//scramble_image( configuration.blur * 50.0 );

apply_fast_blur( configuration.blur * 8.0 );
apply_fast_blur( configuration.blur * 16.0 );

draw_ui_overlay(); // (ui.h)

Expand Down
30 changes: 26 additions & 4 deletions src/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,29 @@ void apply_fractional_blur(CRGBF* pixels, uint16_t num_pixels, float kernel_size
}
}

void apply_box_blur(CRGBF* pixels, uint16_t num_pixels, int kernel_size) {
void apply_box_blur(CRGBF* pixels, uint16_t num_pixels, int kernel_size){
memcpy(leds_temp, pixels, sizeof(CRGBF) * num_pixels);

for(uint16_t i = 0; i < num_pixels; i++){
int16_t kernel_far_left = i - (kernel_size);
int16_t kernel_far_right = i + (kernel_size);

if(kernel_far_left < 0){ kernel_far_left = 0; }
if(kernel_far_right >= num_pixels){ kernel_far_right = num_pixels-1; }

CRGBF sum = {0.0f, 0.0f, 0.0f};

for(int16_t j = kernel_far_left; j <= kernel_far_right; j++){
sum = add( sum, leds_temp[j] );
}

pixels[i] = sum;
}

scale_CRGBF_array_by_constant(pixels, 1.0 / (kernel_size*2.0 + 1.0), num_pixels);
}

void apply_box_blur_old(CRGBF* pixels, uint16_t num_pixels, int kernel_size) {
// Ensure kernel size is odd for symmetry around the central pixel
if (kernel_size % 2 == 0) {
kernel_size -= 1;
Expand Down Expand Up @@ -828,9 +850,9 @@ void apply_fast_blur( float kernel_size ){
return;
}

apply_box_blur( leds, NUM_LEDS, 3.0 + kernel_size );
apply_box_blur( leds, NUM_LEDS, kernel_size );

if(kernel_size > 1.0){
apply_box_blur( leds, NUM_LEDS, 3.0 + kernel_size );
if(kernel_size >= 1.0){
apply_box_blur( leds, NUM_LEDS, kernel_size );
}
}

0 comments on commit a180d8b

Please sign in to comment.