implement round

fix windows build
This commit is contained in:
homm 2016-05-09 13:37:50 +02:00
parent babaaf9bbe
commit f44a7f8b11
2 changed files with 26 additions and 23 deletions

View File

@ -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__':

View File

@ -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;