mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge branch 'i16-pixelaccess' into cffi-pixelaccess
This commit is contained in:
commit
e87e0333fb
|
@ -11,49 +11,39 @@ def color(mode):
|
||||||
else:
|
else:
|
||||||
return tuple(range(1, bands+1))
|
return tuple(range(1, bands+1))
|
||||||
|
|
||||||
def test_pixel():
|
|
||||||
|
|
||||||
def pixel(mode):
|
|
||||||
|
def check(mode, c=None):
|
||||||
|
if not c:
|
||||||
c = color(mode)
|
c = color(mode)
|
||||||
im = Image.new(mode, (1, 1), None)
|
|
||||||
im.putpixel((0, 0), c)
|
#check putpixel
|
||||||
return im.getpixel((0, 0))
|
im = Image.new(mode, (1, 1), None)
|
||||||
|
im.putpixel((0, 0), c)
|
||||||
|
assert_equal(im.getpixel((0, 0)), c,
|
||||||
|
"put/getpixel roundtrip failed for mode %s, color %s" %
|
||||||
|
(mode, c))
|
||||||
|
|
||||||
|
# check inital color
|
||||||
|
im = Image.new(mode, (1, 1), c)
|
||||||
|
assert_equal(im.getpixel((0, 0)), c,
|
||||||
|
"initial color failed for mode %s, color %s " %
|
||||||
|
(mode, color))
|
||||||
|
|
||||||
assert_equal(pixel("1"), 1)
|
def test_basic():
|
||||||
assert_equal(pixel("L"), 1)
|
for mode in ("1", "L", "LA", "I", "I;16", "I;16B", "F",
|
||||||
assert_equal(pixel("LA"), (1, 2))
|
"P", "PA", "RGB", "RGBA", "RGBX", "CMYK","YCbCr"):
|
||||||
assert_equal(pixel("I"), 1)
|
check(mode)
|
||||||
assert_equal(pixel("I;16"), 1)
|
|
||||||
assert_equal(pixel("I;16B"), 1)
|
|
||||||
assert_equal(pixel("F"), 1.0)
|
|
||||||
assert_equal(pixel("P"), 1)
|
|
||||||
assert_equal(pixel("PA"), (1, 2))
|
|
||||||
assert_equal(pixel("RGB"), (1, 2, 3))
|
|
||||||
assert_equal(pixel("RGBA"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("RGBX"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("CMYK"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("YCbCr"), (1, 2, 3))
|
|
||||||
|
|
||||||
def test_image():
|
def test_signedness():
|
||||||
|
# see https://github.com/python-imaging/Pillow/issues/452
|
||||||
def pixel(mode):
|
# pixelaccess is using signed int* instead of uint*
|
||||||
im = Image.new(mode, (1, 1), color(mode))
|
for mode in ("I;16", "I;16B"):
|
||||||
return im.getpixel((0, 0))
|
check(mode, 2**15-1)
|
||||||
|
check(mode, 2**15)
|
||||||
assert_equal(pixel("1"), 1)
|
check(mode, 2**15+1)
|
||||||
assert_equal(pixel("L"), 1)
|
check(mode, 2**16-1)
|
||||||
assert_equal(pixel("LA"), (1, 2))
|
|
||||||
assert_equal(pixel("I"), 1)
|
|
||||||
assert_equal(pixel("I;16"), 1)
|
|
||||||
assert_equal(pixel("I;16B"), 1)
|
|
||||||
assert_equal(pixel("F"), 1.0)
|
|
||||||
assert_equal(pixel("P"), 1)
|
|
||||||
assert_equal(pixel("PA"), (1, 2))
|
|
||||||
assert_equal(pixel("RGB"), (1, 2, 3))
|
|
||||||
assert_equal(pixel("RGBA"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("RGBX"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("CMYK"), (1, 2, 3, 4))
|
|
||||||
assert_equal(pixel("YCbCr"), (1, 2, 3))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -463,7 +463,7 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
UINT8 b[4];
|
UINT8 b[4];
|
||||||
INT16 h;
|
UINT16 h;
|
||||||
INT32 i;
|
INT32 i;
|
||||||
FLOAT32 f;
|
FLOAT32 f;
|
||||||
} pixel;
|
} pixel;
|
||||||
|
|
|
@ -94,11 +94,11 @@ static void
|
||||||
get_pixel_16L(Imaging im, int x, int y, void* color)
|
get_pixel_16L(Imaging im, int x, int y, void* color)
|
||||||
{
|
{
|
||||||
UINT8* in = (UINT8*) &im->image[y][x+x];
|
UINT8* in = (UINT8*) &im->image[y][x+x];
|
||||||
INT16* out = color;
|
UINT16* out = color;
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
out[0] = in[0] + (in[1]<<8);
|
out[0] = in[0] + (in[1]<<8);
|
||||||
#else
|
#else
|
||||||
out[0] = *(INT16*) in;
|
out[0] = *(UINT16*) in;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +106,9 @@ static void
|
||||||
get_pixel_16B(Imaging im, int x, int y, void* color)
|
get_pixel_16B(Imaging im, int x, int y, void* color)
|
||||||
{
|
{
|
||||||
UINT8* in = (UINT8*) &im->image[y][x+x];
|
UINT8* in = (UINT8*) &im->image[y][x+x];
|
||||||
INT16* out = color;
|
UINT16* out = color;
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
out[0] = *(INT16*) in;
|
out[0] = *(UINT16*) in;
|
||||||
#else
|
#else
|
||||||
out[0] = in[1] + (in[0]<<8);
|
out[0] = in[1] + (in[0]<<8);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user