From d91d7b9826bb877e18498f60dfa2be3621735dec Mon Sep 17 00:00:00 2001 From: homm Date: Sat, 18 Oct 2014 23:56:17 +0400 Subject: [PATCH] significant speed improvement (about 55%) --- libImaging/BoxBlur.c | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/libImaging/BoxBlur.c b/libImaging/BoxBlur.c index 2f72e407c..57f97e595 100644 --- a/libImaging/BoxBlur.c +++ b/libImaging/BoxBlur.c @@ -202,7 +202,7 @@ HorizontalBoxBlur(Imaging im, Imaging imOut, float floatRadius) ); // Commit. for (x = 0; x < im->xsize; x++) { - imOut->image8[x][y] = ((UINT8 *)lineOut)[x]; + imOut->image8[y][x] = ((UINT8 *)lineOut)[x]; } } } @@ -218,7 +218,7 @@ HorizontalBoxBlur(Imaging im, Imaging imOut, float floatRadius) ); // Commit. for (x = 0; x < im->xsize; x++) { - imOut->image32[x][y] = lineOut[x]; + imOut->image32[y][x] = lineOut[x]; } } } @@ -230,6 +230,42 @@ HorizontalBoxBlur(Imaging im, Imaging imOut, float floatRadius) return imOut; } +void +TransposeImage(Imaging im, Imaging imOut) +{ + int x, y, xx, yy, xxsize, yysize; + int size = 64; + + if (im->image8) + { + for (y = 0; y < im->ysize; y += size) { + for (x = 0; x < im->xsize; x += size) { + yysize = MIN(size, im->ysize - y); + xxsize = MIN(size, im->xsize - x); + for (yy = 0; yy < yysize; yy++) { + for (xx = 0; xx < xxsize; xx++) { + imOut->image8[x + xx][y + yy] = im->image8[y + yy][x + xx]; + } + } + } + } + } + else + { + for (y = 0; y < im->ysize; y += size) { + for (x = 0; x < im->xsize; x += size) { + yysize = MIN(size, im->ysize - y); + xxsize = MIN(size, im->xsize - x); + for (yy = 0; yy < yysize; yy++) { + for (xx = 0; xx < xxsize; xx++) { + imOut->image32[x + xx][y + yy] = im->image32[y + yy][x + xx]; + } + } + } + } + } +} + Imaging ImagingBoxBlur(Imaging im, Imaging imOut, float radius) @@ -259,12 +295,14 @@ ImagingBoxBlur(Imaging im, Imaging imOut, float radius) /* Apply one-dimensional blur. HorizontalBoxBlur32 transposes image at same time. */ - HorizontalBoxBlur(im, temp, radius); + HorizontalBoxBlur(im, imOut, radius); + TransposeImage(imOut, temp); /* Blur transposed result from previout step in same direction. Reseult will be transposed again. We'll get original image blurred in both directions. */ - HorizontalBoxBlur(temp, imOut, radius); + HorizontalBoxBlur(temp, temp, radius); + TransposeImage(temp, imOut); ImagingDelete(temp);