mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
implement round
fix windows build
This commit is contained in:
parent
babaaf9bbe
commit
f44a7f8b11
|
@ -156,35 +156,34 @@ class CoreResampleConsistencyTest(PillowTestCase):
|
|||
im = Image.new(mode, (512, 9), fill)
|
||||
return (im.resize((9, 512), Image.LANCZOS), im.load()[0, 0])
|
||||
|
||||
def run_cases(self, cases):
|
||||
for channel, color in cases:
|
||||
px = channel.load()
|
||||
for x in range(channel.size[0]):
|
||||
for y in range(channel.size[1]):
|
||||
if px[x, y] != color:
|
||||
message = "{} != {} for pixel {}".format(
|
||||
px[x, y], color, (x, y))
|
||||
self.assertEqual(px[x, y], color, message)
|
||||
def run_case(self, case):
|
||||
channel, color = case
|
||||
px = channel.load()
|
||||
for x in range(channel.size[0]):
|
||||
for y in range(channel.size[1]):
|
||||
if px[x, y] != color:
|
||||
message = "{} != {} for pixel {}".format(
|
||||
px[x, y], color, (x, y))
|
||||
self.assertEqual(px[x, y], color, message)
|
||||
|
||||
def test_8u(self):
|
||||
im, color = self.make_case('RGB', (0, 64, 255))
|
||||
self.run_cases(zip(im.split(), color))
|
||||
r, g, b = im.split()
|
||||
self.run_case((r, color[0]))
|
||||
self.run_case((g, color[1]))
|
||||
self.run_case((b, color[2]))
|
||||
|
||||
def test_32i(self):
|
||||
self.run_cases([
|
||||
self.make_case('I', 12),
|
||||
self.make_case('I', 0x7fffffff),
|
||||
self.make_case('I', -12),
|
||||
self.make_case('I', -1 << 31),
|
||||
])
|
||||
self.run_case(self.make_case('I', 12))
|
||||
self.run_case(self.make_case('I', 0x7fffffff))
|
||||
self.run_case(self.make_case('I', -12))
|
||||
self.run_case(self.make_case('I', -1 << 31))
|
||||
|
||||
def test_32f(self):
|
||||
self.run_cases([
|
||||
self.make_case('F', 1),
|
||||
self.make_case('F', 3.40282306074e+38),
|
||||
self.make_case('F', 1.175494e-38),
|
||||
self.make_case('F', 1.192093e-07),
|
||||
])
|
||||
self.run_case(self.make_case('F', 1))
|
||||
self.run_case(self.make_case('F', 3.40282306074e+38))
|
||||
self.run_case(self.make_case('F', 1.175494e-38))
|
||||
self.run_case(self.make_case('F', 1.192093e-07))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#define ROUND_UP(f) ((int) ((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
|
||||
|
||||
|
||||
struct filter {
|
||||
float (*filter)(float x);
|
||||
float support;
|
||||
|
@ -288,7 +292,7 @@ ImagingResampleHorizontal_32bpc(Imaging imIn, int xsize, struct filter *filterp)
|
|||
ss = 0.0;
|
||||
for (x = xmin; x < xmax; x++)
|
||||
ss += IMAGING_PIXEL_I(imIn, x, yy) * k[x - xmin];
|
||||
IMAGING_PIXEL_I(imOut, xx, yy) = lround(ss);
|
||||
IMAGING_PIXEL_I(imOut, xx, yy) = ROUND_UP(ss);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user