mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-28 02:04:36 +03:00
big radius special case
This commit is contained in:
parent
d3d4ff69eb
commit
da84cd7ea6
|
@ -2,6 +2,10 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
HorizontalBoxBlur32(Imaging im, Imaging imOut, float floatRadius)
|
HorizontalBoxBlur32(Imaging im, Imaging imOut, float floatRadius)
|
||||||
{
|
{
|
||||||
|
@ -20,8 +24,8 @@ HorizontalBoxBlur32(Imaging im, Imaging imOut, float floatRadius)
|
||||||
int w = 256 * (radius * 2 + 1) + rem * 2;
|
int w = 256 * (radius * 2 + 1) + rem * 2;
|
||||||
int w2 = w / 2;
|
int w2 = w / 2;
|
||||||
|
|
||||||
int cornerA = radius + 1;
|
int edgeA = MIN(radius + 1, im->xsize);
|
||||||
int cornerB = im->xsize - radius - 1;
|
int edgeB = MAX(im->xsize - radius - 1, 0);
|
||||||
|
|
||||||
// printf("%d %d %d\n", rem, w, w2);
|
// printf("%d %d %d\n", rem, w, w2);
|
||||||
|
|
||||||
|
@ -60,26 +64,47 @@ HorizontalBoxBlur32(Imaging im, Imaging imOut, float floatRadius)
|
||||||
acc[3] += line[pix][3];
|
acc[3] += line[pix][3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Substract pixel from left ("0").
|
if (edgeA <= edgeB)
|
||||||
Add pixels from radius. */
|
{
|
||||||
for (x = 0; x < cornerA; x++) {
|
/* Substract pixel from left ("0").
|
||||||
MOVE_ACC(acc, 0, x + radius);
|
Add pixels from radius. */
|
||||||
ADD_FAR(bulk, acc, 0, x + radius + 1);
|
for (x = 0; x < edgeA; x++) {
|
||||||
imOut->image32[x][y] = SAVE(bulk);
|
MOVE_ACC(acc, 0, x + radius);
|
||||||
|
ADD_FAR(bulk, acc, 0, x + radius + 1);
|
||||||
|
imOut->image32[x][y] = SAVE(bulk);
|
||||||
|
}
|
||||||
|
/* Substract previous pixel from "-radius".
|
||||||
|
Add pixels from radius. */
|
||||||
|
for (x = edgeA; x < edgeB; x++) {
|
||||||
|
MOVE_ACC(acc, x - radius - 1, x + radius);
|
||||||
|
ADD_FAR(bulk, acc, x - radius - 1, x + radius + 1);
|
||||||
|
imOut->image32[x][y] = SAVE(bulk);
|
||||||
|
}
|
||||||
|
/* Substract previous pixel from "-radius".
|
||||||
|
Add last pixel. */
|
||||||
|
for (x = edgeB; x < im->xsize; x++) {
|
||||||
|
MOVE_ACC(acc, x - radius - 1, lastx);
|
||||||
|
ADD_FAR(bulk, acc, x - radius - 1, lastx);
|
||||||
|
imOut->image32[x][y] = SAVE(bulk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Substract previous pixel from "-radius".
|
else
|
||||||
Add pixels from radius. */
|
{
|
||||||
for (x = cornerA; x < cornerB; x++) {
|
for (x = 0; x < edgeB; x++) {
|
||||||
MOVE_ACC(acc, x - radius - 1, x + radius);
|
MOVE_ACC(acc, 0, x + radius);
|
||||||
ADD_FAR(bulk, acc, x - radius - 1, x + radius + 1);
|
ADD_FAR(bulk, acc, 0, x + radius + 1);
|
||||||
imOut->image32[x][y] = SAVE(bulk);
|
imOut->image32[x][y] = SAVE(bulk);
|
||||||
}
|
}
|
||||||
/* Substract previous pixel from "-radius".
|
for (x = edgeB; x < edgeA; x++) {
|
||||||
Add last pixel. */
|
MOVE_ACC(acc, 0, lastx);
|
||||||
for (x = cornerB; x < im->xsize; x++) {
|
ADD_FAR(bulk, acc, 0, lastx);
|
||||||
MOVE_ACC(acc, x - radius - 1, lastx);
|
imOut->image32[x][y] = SAVE(bulk);
|
||||||
ADD_FAR(bulk, acc, x - radius - 1, lastx);
|
}
|
||||||
imOut->image32[x][y] = SAVE(bulk);
|
for (x = edgeA; x < im->xsize; x++) {
|
||||||
|
MOVE_ACC(acc, x - radius - 1, lastx);
|
||||||
|
ADD_FAR(bulk, acc, x - radius - 1, lastx);
|
||||||
|
imOut->image32[x][y] = SAVE(bulk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +131,8 @@ HorizontalBoxBlur8(Imaging im, Imaging imOut, float floatRadius)
|
||||||
int w = 256 * (radius * 2 + 1) + rem * 2;
|
int w = 256 * (radius * 2 + 1) + rem * 2;
|
||||||
int w2 = w / 2;
|
int w2 = w / 2;
|
||||||
|
|
||||||
int cornerA = radius + 1;
|
int edgeA = MIN(radius + 1, im->xsize);
|
||||||
int cornerB = im->xsize - radius - 1;
|
int edgeB = MAX(im->xsize - radius - 1, 0);
|
||||||
|
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
|
@ -119,20 +144,41 @@ HorizontalBoxBlur8(Imaging im, Imaging imOut, float floatRadius)
|
||||||
acc += line[pix];
|
acc += line[pix];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0; x < cornerA; x++) {
|
if (edgeA <= edgeB)
|
||||||
acc = acc + line[x + radius] - line[0];
|
{
|
||||||
bulk = (acc << 8) + (line[0] + line[x + radius + 1]) * rem;
|
for (x = 0; x < edgeA; x++) {
|
||||||
imOut->image8[x][y] = (UINT8)((bulk + w2) / w);
|
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 = edgeA; x < edgeB; 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 = edgeB; 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (x = cornerA; x < cornerB; x++) {
|
else
|
||||||
acc = acc + line[x + radius] - line[x - radius - 1];
|
{
|
||||||
bulk = (acc << 8) + (line[x - radius - 1] + line[x + radius + 1]) * rem;
|
for (x = 0; x < edgeB; x++) {
|
||||||
imOut->image8[x][y] = (UINT8)((bulk + w2) / w);
|
acc = acc + line[x + radius] - line[0];
|
||||||
}
|
bulk = (acc << 8) + (line[0] + line[x + radius + 1]) * rem;
|
||||||
for (x = cornerB; x < im->xsize; x++) {
|
imOut->image8[x][y] = (UINT8)((bulk + w2) / w);
|
||||||
acc = acc + line[lastx] - line[x - radius - 1];
|
}
|
||||||
bulk = (acc << 8) + (line[x - radius - 1] + line[lastx]) * rem;
|
for (x = edgeB; x < edgeA; x++) {
|
||||||
imOut->image8[x][y] = (UINT8)((bulk + w2) / w);
|
acc = acc + line[lastx] - line[0];
|
||||||
|
bulk = (acc << 8) + (line[0] + line[lastx]) * rem;
|
||||||
|
imOut->image8[x][y] = (UINT8)((bulk + w2) / w);
|
||||||
|
}
|
||||||
|
for (x = edgeA; 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user