mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-02 12:44:28 +03:00
Merge pull request #7209 from Yay295/bytes_tests
This commit is contained in:
commit
016415800a
|
@ -33,36 +33,38 @@ from .helper import (
|
|||
skip_unless_feature,
|
||||
)
|
||||
|
||||
# name, pixel size
|
||||
image_modes = (
|
||||
("1", 1),
|
||||
("L", 1),
|
||||
("LA", 4),
|
||||
("La", 4),
|
||||
("P", 1),
|
||||
("PA", 4),
|
||||
("F", 4),
|
||||
("I", 4),
|
||||
("I;16", 2),
|
||||
("I;16L", 2),
|
||||
("I;16B", 2),
|
||||
("I;16N", 2),
|
||||
("RGB", 4),
|
||||
("RGBA", 4),
|
||||
("RGBa", 4),
|
||||
("RGBX", 4),
|
||||
("BGR;15", 2),
|
||||
("BGR;16", 2),
|
||||
("BGR;24", 3),
|
||||
("CMYK", 4),
|
||||
("YCbCr", 4),
|
||||
("HSV", 4),
|
||||
("LAB", 4),
|
||||
)
|
||||
|
||||
image_mode_names = [name for name, _ in image_modes]
|
||||
|
||||
|
||||
class TestImage:
|
||||
@pytest.mark.parametrize(
|
||||
"mode",
|
||||
(
|
||||
"1",
|
||||
"P",
|
||||
"PA",
|
||||
"L",
|
||||
"LA",
|
||||
"La",
|
||||
"F",
|
||||
"I",
|
||||
"I;16",
|
||||
"I;16L",
|
||||
"I;16B",
|
||||
"I;16N",
|
||||
"RGB",
|
||||
"RGBX",
|
||||
"RGBA",
|
||||
"RGBa",
|
||||
"BGR;15",
|
||||
"BGR;16",
|
||||
"BGR;24",
|
||||
"CMYK",
|
||||
"YCbCr",
|
||||
"LAB",
|
||||
"HSV",
|
||||
),
|
||||
)
|
||||
@pytest.mark.parametrize("mode", image_mode_names)
|
||||
def test_image_modes_success(self, mode: str) -> None:
|
||||
Image.new(mode, (1, 1))
|
||||
|
||||
|
@ -1042,6 +1044,35 @@ class TestImage:
|
|||
assert im.fp is None
|
||||
|
||||
|
||||
class TestImageBytes:
|
||||
@pytest.mark.parametrize("mode", image_mode_names)
|
||||
def test_roundtrip_bytes_constructor(self, mode: str) -> None:
|
||||
im = hopper(mode)
|
||||
source_bytes = im.tobytes()
|
||||
|
||||
reloaded = Image.frombytes(mode, im.size, source_bytes)
|
||||
assert reloaded.tobytes() == source_bytes
|
||||
|
||||
@pytest.mark.parametrize("mode", image_mode_names)
|
||||
def test_roundtrip_bytes_method(self, mode: str) -> None:
|
||||
im = hopper(mode)
|
||||
source_bytes = im.tobytes()
|
||||
|
||||
reloaded = Image.new(mode, im.size)
|
||||
reloaded.frombytes(source_bytes)
|
||||
assert reloaded.tobytes() == source_bytes
|
||||
|
||||
@pytest.mark.parametrize(("mode", "pixelsize"), image_modes)
|
||||
def test_getdata_putdata(self, mode: str, pixelsize: int) -> None:
|
||||
im = Image.new(mode, (2, 2))
|
||||
source_bytes = bytes(range(im.width * im.height * pixelsize))
|
||||
im.frombytes(source_bytes)
|
||||
|
||||
reloaded = Image.new(mode, im.size)
|
||||
reloaded.putdata(im.getdata())
|
||||
assert_image_equal(im, reloaded)
|
||||
|
||||
|
||||
class MockEncoder(ImageFile.PyEncoder):
|
||||
pass
|
||||
|
||||
|
|
|
@ -1578,7 +1578,17 @@ if (PySequence_Check(op)) { \
|
|||
int bigendian = 0;
|
||||
if (image->type == IMAGING_TYPE_SPECIAL) {
|
||||
// I;16*
|
||||
bigendian = strcmp(image->mode, "I;16B") == 0;
|
||||
if (strcmp(image->mode, "I;16N") == 0) {
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
bigendian = 1;
|
||||
#else
|
||||
bigendian = 0;
|
||||
#endif
|
||||
} else if (strcmp(image->mode, "I;16B") == 0) {
|
||||
bigendian = 1;
|
||||
} else {
|
||||
bigendian = 0;
|
||||
}
|
||||
}
|
||||
for (i = x = y = 0; i < n; i++) {
|
||||
set_value_to_item(seq, i);
|
||||
|
|
Loading…
Reference in New Issue
Block a user