mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
ad492ee4d8
commit
d02417e411
|
@ -68,11 +68,12 @@ def test_to_array(mode: str, dtype: Any, mask: Any) -> None:
|
|||
|
||||
assert_image_equal(img, reloaded)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mode, dest_modes",
|
||||
(
|
||||
("L", ["I", "F", "LA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr", "HSV"]),
|
||||
("I", ["L", "F"]), # Technically I32 can work for any 4x8bit storage.
|
||||
("I", ["L", "F"]), # Technically I32 can work for any 4x8bit storage.
|
||||
("F", ["I", "L", "LA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr", "HSV"]),
|
||||
("LA", ["L", "F"]),
|
||||
("RGB", ["L", "F"]),
|
||||
|
@ -89,12 +90,13 @@ def test_invalid_array_type(mode: str, dest_modes: List[str]) -> None:
|
|||
with pytest.raises(ValueError):
|
||||
Image.fromarrow(img, dest_mode, img.size)
|
||||
|
||||
def test_invalid_array_size():
|
||||
img = hopper('RGB')
|
||||
|
||||
assert img.size != (10,10)
|
||||
def test_invalid_array_size():
|
||||
img = hopper("RGB")
|
||||
|
||||
assert img.size != (10, 10)
|
||||
with pytest.raises(ValueError):
|
||||
Image.fromarrow(img, 'RGB', (10,10))
|
||||
Image.fromarrow(img, "RGB", (10, 10))
|
||||
|
||||
|
||||
def test_lifetime():
|
||||
|
@ -137,20 +139,21 @@ def test_lifetime2():
|
|||
|
||||
def test_release_schema():
|
||||
# these should not error out, valgrind should be clean
|
||||
img = hopper('L')
|
||||
img = hopper("L")
|
||||
schema = img.__arrow_c_schema__()
|
||||
del(schema)
|
||||
del schema
|
||||
|
||||
|
||||
def test_release_array():
|
||||
# these should not error out, valgrind should be clean
|
||||
img = hopper('L')
|
||||
img = hopper("L")
|
||||
array, schema = img.__arrow_c_array__()
|
||||
del(array)
|
||||
del(schema)
|
||||
del array
|
||||
del schema
|
||||
|
||||
|
||||
def test_readonly():
|
||||
img = hopper('L')
|
||||
img = hopper("L")
|
||||
reloaded = Image.fromarrow(img, img.mode, img.size)
|
||||
assert reloaded.readonly == 1
|
||||
reloaded._readonly = 0
|
||||
|
|
|
@ -571,9 +571,7 @@ ImagingDestroyArrow(Imaging im) {
|
|||
}
|
||||
|
||||
Imaging
|
||||
ImagingBorrowArrow(Imaging im,
|
||||
struct ArrowArray *external_array,
|
||||
int offset_width) {
|
||||
ImagingBorrowArrow(Imaging im, struct ArrowArray *external_array, int offset_width) {
|
||||
// offset_width is the # of char* for a single offset from arrow
|
||||
Py_ssize_t y, i;
|
||||
|
||||
|
@ -586,11 +584,12 @@ ImagingBorrowArrow(Imaging im,
|
|||
if (arr->n_buffers == 2) {
|
||||
// buffer 0 is the null list
|
||||
// buffer 1 is the data
|
||||
borrowed_buffer = (char *)arr->buffers[1] + (offset_width*arr->offset);
|
||||
borrowed_buffer = (char *)arr->buffers[1] + (offset_width * arr->offset);
|
||||
}
|
||||
|
||||
if (!borrowed_buffer) {
|
||||
return (Imaging)ImagingError_ValueError("Arrow Array, exactly 2 buffers required");
|
||||
return (Imaging
|
||||
)ImagingError_ValueError("Arrow Array, exactly 2 buffers required");
|
||||
}
|
||||
|
||||
for (y = i = 0; y < im->ysize; y++) {
|
||||
|
@ -698,12 +697,10 @@ ImagingNewArrow(
|
|||
int64_t pixels = (int64_t)xsize * (int64_t)ysize;
|
||||
|
||||
// fmt:off // don't reformat this
|
||||
if (((strcmp(schema->format, "I") == 0
|
||||
&& im->pixelsize == 4
|
||||
&& im->bands >= 2) // INT32 into any INT32 Storage mode
|
||||
||
|
||||
(strcmp(schema->format, im->arrow_band_format) == 0
|
||||
&& im->bands == 1)) // Single band match
|
||||
if (((strcmp(schema->format, "I") == 0 && im->pixelsize == 4 && im->bands >= 2
|
||||
) // INT32 into any INT32 Storage mode
|
||||
|| (strcmp(schema->format, im->arrow_band_format) == 0 && im->bands == 1)
|
||||
) // Single band match
|
||||
&& pixels == external_array->length) {
|
||||
// one arrow element per, and it matches a pixelsize*char
|
||||
if (ImagingBorrowArrow(im, external_array, im->pixelsize)) {
|
||||
|
@ -711,15 +708,15 @@ ImagingNewArrow(
|
|||
}
|
||||
}
|
||||
// linter: don't mess with the formatting here
|
||||
if (strcmp(schema->format, "+w:4") == 0 // 4 up array
|
||||
&& im->pixelsize == 4 // storage as 32 bpc
|
||||
&& schema->n_children > 0 // make sure schema is well formed.
|
||||
&& schema->children // make sure schema is well formed
|
||||
&& strcmp(schema->children[0]->format, "C") == 0 // Expected format
|
||||
&& strcmp(im->arrow_band_format, "C") == 0 // Expected Format
|
||||
&& pixels == external_array->length // expected length
|
||||
&& external_array->n_children == 1 // array is well formed
|
||||
&& external_array->children // array is well formed
|
||||
if (strcmp(schema->format, "+w:4") == 0 // 4 up array
|
||||
&& im->pixelsize == 4 // storage as 32 bpc
|
||||
&& schema->n_children > 0 // make sure schema is well formed.
|
||||
&& schema->children // make sure schema is well formed
|
||||
&& strcmp(schema->children[0]->format, "C") == 0 // Expected format
|
||||
&& strcmp(im->arrow_band_format, "C") == 0 // Expected Format
|
||||
&& pixels == external_array->length // expected length
|
||||
&& external_array->n_children == 1 // array is well formed
|
||||
&& external_array->children // array is well formed
|
||||
&& 4 * pixels == external_array->children[0]->length) {
|
||||
// 4 up element of char into pixelsize == 4
|
||||
if (ImagingBorrowArrow(im, external_array, 1)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user