From 2c723abbcaad353fcde15b54265ab8a4a6fcbfaf Mon Sep 17 00:00:00 2001 From: homm Date: Sun, 12 Oct 2014 22:37:25 +0400 Subject: [PATCH] move HorizontalBoxBlur8 down and remove comments --- libImaging/BoxBlur.c | 111 +++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 61 deletions(-) diff --git a/libImaging/BoxBlur.c b/libImaging/BoxBlur.c index 85eded5dc..9f9c1a5e2 100644 --- a/libImaging/BoxBlur.c +++ b/libImaging/BoxBlur.c @@ -2,67 +2,6 @@ #include "Imaging.h" -Imaging -HorizontalBoxBlur8(Imaging im, Imaging imOut, float floatRadius) -{ - ImagingSectionCookie cookie; - - int x, y, pix; - unsigned int acc; - unsigned int bulk; - - UINT8 *line; - int lastx = im->xsize - 1; - - int radius = (int) floatRadius; - UINT8 rem = (UINT8) (256 * (floatRadius - radius)); - int w = (int) (256 * (floatRadius * 2 + 1)); - int w2 = w / 2; - - // printf("%d %d %d\n", rem, w, w2); - - ImagingSectionEnter(&cookie); - - for (y = 0; y < im->ysize; y++) { - line = im->image8[y]; - - /* Compute acc for -1 pixel (outside of image): - From "-radius-1" to "0" get first pixel, - then from "1" to "radius-1". */ - acc = line[0] * (radius + 1); - for (pix = 0; pix < radius; pix++) { - acc += line[pix]; - } - - /* Substract pixel from left ("0"). - Add pixels from radius. */ - for (x = 0; x <= radius; x++) { - acc = acc + line[x + radius] - line[0]; - bulk = (acc << 8) + (line[0] + line[x + radius + 1]) * rem; - imOut->image8[x][y] = (UINT8)((bulk + w2) / w); - } - /* Substract previous pixel from "-radius". - Add pixels from radius. */ - for (x = radius + 1; x < im->xsize - radius; x++) { - acc = acc + line[x + radius] - line[x - radius - 1]; - bulk = (acc << 8) + (line[x - radius - 1] + line[x + radius + 1]) * rem; - imOut->image8[x][y] = (UINT8)((bulk + w2) / w); - } - /* Substract previous pixel from "-radius". - Add last pixel. */ - for (x = im->xsize - radius; x < im->xsize; x++) { - acc = acc + line[lastx] - line[x - radius - 1]; - bulk = (acc << 8) + (line[x - radius - 1] + line[lastx]) * rem; - imOut->image8[x][y] = (UINT8)((bulk + w2) / w); - } - } - - ImagingSectionLeave(&cookie); - - return imOut; -} - - Imaging HorizontalBoxBlur32(Imaging im, Imaging imOut, float floatRadius) { @@ -147,6 +86,56 @@ HorizontalBoxBlur32(Imaging im, Imaging imOut, float floatRadius) } +Imaging +HorizontalBoxBlur8(Imaging im, Imaging imOut, float floatRadius) +{ + ImagingSectionCookie cookie; + + int x, y, pix; + unsigned int acc; + unsigned int bulk; + + UINT8 *line; + int lastx = im->xsize - 1; + + int radius = (int) floatRadius; + UINT8 rem = (UINT8) (256 * (floatRadius - radius)); + int w = (int) (256 * (floatRadius * 2 + 1)); + int w2 = w / 2; + + ImagingSectionEnter(&cookie); + + for (y = 0; y < im->ysize; y++) { + line = im->image8[y]; + + acc = line[0] * (radius + 1); + for (pix = 0; pix < radius; pix++) { + acc += line[pix]; + } + + for (x = 0; x <= radius; x++) { + acc = acc + line[x + radius] - line[0]; + bulk = (acc << 8) + (line[0] + line[x + radius + 1]) * rem; + imOut->image8[x][y] = (UINT8)((bulk + w2) / w); + } + for (x = radius + 1; x < im->xsize - radius; x++) { + acc = acc + line[x + radius] - line[x - radius - 1]; + bulk = (acc << 8) + (line[x - radius - 1] + line[x + radius + 1]) * rem; + imOut->image8[x][y] = (UINT8)((bulk + w2) / w); + } + for (x = im->xsize - radius; x < im->xsize; x++) { + acc = acc + line[lastx] - line[x - radius - 1]; + bulk = (acc << 8) + (line[x - radius - 1] + line[lastx]) * rem; + imOut->image8[x][y] = (UINT8)((bulk + w2) / w); + } + } + + ImagingSectionLeave(&cookie); + + return imOut; +} + + Imaging ImagingBoxBlur(Imaging im, Imaging imOut, float radius) {