-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(blur): use rendered surface after commit
- Fix blur logic - Reused rendered surface to optimize future render on comitted blur - Include gaussian kernel function Closes #20 Closes #22
- Loading branch information
Showing
10 changed files
with
226 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <glib.h> | ||
|
||
struct gaussian_kernel { | ||
gdouble *kernel; | ||
gint size; | ||
gdouble sigma; | ||
gdouble sum; | ||
}; | ||
|
||
struct gaussian_kernel *gaussian_kernel(gint width, gdouble sigma); | ||
void gaussian_kernel_free(gpointer data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "algebra.h" | ||
|
||
#include <glib.h> | ||
#include <math.h> | ||
|
||
struct gaussian_kernel *gaussian_kernel(int width, double sigma) { | ||
double sum = 0; | ||
gint size = width * width + 1; | ||
double *kernel = g_new(double, size); | ||
struct gaussian_kernel *gaussian = g_new(struct gaussian_kernel, 1); | ||
for (gint y = 0; y < width; y++) { | ||
for (gint x = 0; x < width; x++) { | ||
double j = y - width; | ||
double i = x - width; | ||
double cell = ((1.0 / (2.0 * G_PI * sigma)) * | ||
exp((-(i * i + j * j)) / (2.0 * sigma * sigma))) * | ||
0xff; | ||
kernel[y * width + x] = cell; | ||
sum += cell; | ||
} | ||
} | ||
|
||
gaussian->kernel = kernel; | ||
gaussian->size = size; | ||
gaussian->sigma = sigma; | ||
gaussian->sum = sum; | ||
|
||
return gaussian; | ||
} | ||
|
||
void gaussian_kernel_free(gpointer data) { | ||
struct gaussian_kernel *gaussian = (struct gaussian_kernel *)data; | ||
if (gaussian != NULL) { | ||
g_free(gaussian->kernel); | ||
g_free(gaussian); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.