@@ -18,7 +18,8 @@
* FUNC1 standard function name
* FUNC2 separable function name
* PIXEL pixel type
* GRAY 1 (grayscale) or 0 (classic RGBA)
* FLAGS 1 (grayscale)
* 2 (loop)
*/
static pipi_image_t *FUNC1(pipi_image_t *src, int m, int n, double mat[])
@@ -31,20 +32,20 @@ static pipi_image_t *FUNC1(pipi_image_t *src, int m, int n, double mat[])
w = src->w;
h = src->h;
srcp = GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F)
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
srcp = FLAG_ GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F)
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
srcdata = (PIXEL *)srcp->pixels;
dst = pipi_new(w, h);
dstp = GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstp = FLAG_ GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstdata = (PIXEL *)dstp->pixels;
for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
if(GRAY)
if(FLAG_ GRAY)
{
double Y = 0.;
int x2, y2;
@@ -52,14 +53,14 @@ static pipi_image_t *FUNC1(pipi_image_t *src, int m, int n, double mat[])
for(j = 0; j < n; j++)
{
y2 = y + j - n / 2;
if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;
if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0;
else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1;
for(i = 0; i < m; i++)
{
x2 = x + i - m / 2;
if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;
if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0;
else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1;
Y += mat[j * m + i] * srcdata[y2 * w + x2];
}
@@ -75,16 +76,16 @@ static pipi_image_t *FUNC1(pipi_image_t *src, int m, int n, double mat[])
for(j = 0; j < n; j++)
{
y2 = y + j - n / 2;
if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;
if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0;
else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1;
for(i = 0; i < m; i++)
{
double f = mat[j * m + i];
x2 = x + i - m / 2;
if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;
if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0;
else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1;
R += f * srcdata[(y2 * w + x2) * 4];
G += f * srcdata[(y2 * w + x2) * 4 + 1];
@@ -114,22 +115,22 @@ static pipi_image_t *FUNC2(pipi_image_t *src,
w = src->w;
h = src->h;
srcp = GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F)
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
srcp = FLAG_ GRAY ? pipi_getpixels(src, PIPI_PIXELS_Y_F)
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
srcdata = (PIXEL *)srcp->pixels;
dst = pipi_new(w, h);
dstp = GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstp = FLAG_ GRAY ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstdata = (PIXEL *)dstp->pixels;
buffer = malloc(w * h * (GRAY ? 1 : 4) * sizeof(double));
buffer = malloc(w * h * (FLAG_ GRAY ? 1 : 4) * sizeof(double));
for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
if(GRAY)
if(FLAG_ GRAY)
{
double Y = 0.;
int x2;
@@ -137,8 +138,8 @@ static pipi_image_t *FUNC2(pipi_image_t *src,
for(i = 0; i < m; i++)
{
x2 = x + i - m / 2;
if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;
if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0;
else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1;
Y += hvec[i] * srcdata[y * w + x2];
}
@@ -155,8 +156,8 @@ static pipi_image_t *FUNC2(pipi_image_t *src,
double f = hvec[i];
x2 = x + i - m / 2;
if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;
if(x2 < 0) x2 = FLAG_WRAP ? (w - 1 - (-x2 - 1) % w) : 0;
else if(x2 >= w) x2 = FLAG_WRAP ? x2 % w : w - 1;
R += f * srcdata[(y * w + x2) * 4];
G += f * srcdata[(y * w + x2) * 4 + 1];
@@ -174,7 +175,7 @@ static pipi_image_t *FUNC2(pipi_image_t *src,
{
for(x = 0; x < w; x++)
{
if(GRAY)
if(FLAG_ GRAY)
{
double Y = 0.;
int y2;
@@ -182,8 +183,8 @@ static pipi_image_t *FUNC2(pipi_image_t *src,
for(j = 0; j < n; j++)
{
y2 = y + j - n / 2;
if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;
if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0;
else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1;
Y += vvec[j] * buffer[y2 * w + x];
}
@@ -200,8 +201,8 @@ static pipi_image_t *FUNC2(pipi_image_t *src,
double f = vvec[j];
y2 = y + j - n / 2;
if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;
if(y2 < 0) y2 = FLAG_WRAP ? (h - 1 - (-y2 - 1) % h) : 0;
else if(y2 >= h) y2 = FLAG_WRAP ? y2 % h : h - 1;
R += f * buffer[(y2 * w + x) * 4];
G += f * buffer[(y2 * w + x) * 4 + 1];