[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2025-02-03 15:29:27 +00:00
parent e7bd152aac
commit 9f94d4f9f8
5 changed files with 39 additions and 40 deletions

View File

@ -159,22 +159,24 @@ def test_readonly():
reloaded._readonly = 0 reloaded._readonly = 0
assert reloaded.readonly == 1 assert reloaded.readonly == 1
def test_multiblock_l_image(): def test_multiblock_l_image():
block_size = Image.core.get_block_size() block_size = Image.core.get_block_size()
# check a 2 block image in single channel mode # check a 2 block image in single channel mode
size = (4096, 2*block_size//4096) size = (4096, 2 * block_size // 4096)
img = Image.new('L', size, 128) img = Image.new("L", size, 128)
with pytest.raises(ValueError): with pytest.raises(ValueError):
(schema, arr) = img.__arrow_c_array__() (schema, arr) = img.__arrow_c_array__()
def test_multiblock__rgba_image(): def test_multiblock__rgba_image():
block_size = Image.core.get_block_size() block_size = Image.core.get_block_size()
# check a 2 block image in 4 channel mode # check a 2 block image in 4 channel mode
size = (4096, (block_size//4096) //2) size = (4096, (block_size // 4096) // 2)
img = Image.new('RGBA', size, (128,127,126,125)) img = Image.new("RGBA", size, (128, 127, 126, 125))
with pytest.raises(ValueError): with pytest.raises(ValueError):
(schema, arr) = img.__arrow_c_array__() (schema, arr) = img.__arrow_c_array__()
@ -184,18 +186,19 @@ def test_multiblock_l_schema():
block_size = Image.core.get_block_size() block_size = Image.core.get_block_size()
# check a 2 block image in single channel mode # check a 2 block image in single channel mode
size = (4096, 2*block_size//4096) size = (4096, 2 * block_size // 4096)
img = Image.new('L', size, 128) img = Image.new("L", size, 128)
with pytest.raises(ValueError): with pytest.raises(ValueError):
schema = img.__arrow_c_schema__() schema = img.__arrow_c_schema__()
def test_multiblock__rgba_schema(): def test_multiblock__rgba_schema():
block_size = Image.core.get_block_size() block_size = Image.core.get_block_size()
# check a 2 block image in 4 channel mode # check a 2 block image in 4 channel mode
size = (4096, (block_size//4096) //2) size = (4096, (block_size // 4096) // 2)
img = Image.new('RGBA', size, (128,127,126,125)) img = Image.new("RGBA", size, (128, 127, 126, 125))
with pytest.raises(ValueError): with pytest.raises(ValueError):
schema= img.__arrow_c_schema__() schema = img.__arrow_c_schema__()

View File

@ -236,7 +236,9 @@ ArrowError(int err) {
return ImagingError_ValueError("Incompatible Pillow mode for Arrow Array"); return ImagingError_ValueError("Incompatible Pillow mode for Arrow Array");
} }
if (err == IMAGING_ARROW_MEMORY_LAYOUT) { if (err == IMAGING_ARROW_MEMORY_LAYOUT) {
return ImagingError_ValueError("Image is in multiple array blocks, use imaging_new_block for zero copy"); return ImagingError_ValueError(
"Image is in multiple array blocks, use imaging_new_block for zero copy"
);
} }
return ImagingError_ValueError("Unknown Error"); return ImagingError_ValueError("Unknown Error");
} }
@ -286,7 +288,6 @@ ExportArrowArrayPyCapsule(ImagingObject *self) {
return ArrowError(err); return ArrowError(err);
} }
static PyObject * static PyObject *
_new_arrow(PyObject *self, PyObject *args) { _new_arrow(PyObject *self, PyObject *args) {
char *mode; char *mode;

View File

@ -98,7 +98,7 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
} }
/* for now, single block images */ /* for now, single block images */
if (!(im->blocks_count == 0 || im->blocks_count == 1)){ if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
return IMAGING_ARROW_MEMORY_LAYOUT; return IMAGING_ARROW_MEMORY_LAYOUT;
} }
@ -123,8 +123,6 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
return 0; return 0;
} }
static void static void
release_const_array(struct ArrowArray *array) { release_const_array(struct ArrowArray *array) {
Imaging im = (Imaging)array->private_data; Imaging im = (Imaging)array->private_data;
@ -140,8 +138,8 @@ release_const_array(struct ArrowArray *array) {
} }
if (array->children) { if (array->children) {
// undone -- does arrow release all the children recursively. // undone -- does arrow release all the children recursively.
for (int i=0; i < array->n_children; i++) { for (int i = 0; i < array->n_children; i++) {
if (array->children[i]->release){ if (array->children[i]->release) {
array->children[i]->release(array->children[i]); array->children[i]->release(array->children[i]);
array->children[i]->release = NULL; array->children[i]->release = NULL;
free(array->children[i]); free(array->children[i]);
@ -159,7 +157,7 @@ export_single_channel_array(Imaging im, struct ArrowArray *array) {
int length = im->xsize * im->ysize; int length = im->xsize * im->ysize;
/* for now, single block images */ /* for now, single block images */
if (!(im->blocks_count == 0 || im->blocks_count == 1)){ if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
return IMAGING_ARROW_MEMORY_LAYOUT; return IMAGING_ARROW_MEMORY_LAYOUT;
} }
@ -274,7 +272,7 @@ export_fixed_pixel_array(Imaging im, struct ArrowArray *array) {
} }
return 0; return 0;
err: err:
if (array->children[0]) { if (array->children[0]) {
free(array->children[0]); free(array->children[0]);
} }

View File

@ -121,8 +121,6 @@ struct ImagingMemoryInstance {
#ifdef Py_GIL_DISABLED #ifdef Py_GIL_DISABLED
PyMutex mutex; PyMutex mutex;
#endif #endif
}; };
#define IMAGING_PIXEL_1(im, x, y) ((im)->image8[(y)][(x)]) #define IMAGING_PIXEL_1(im, x, y) ((im)->image8[(y)][(x)])
@ -747,7 +745,6 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema);
#define IMAGING_ARROW_INCOMPATIBLE_MODE -10 #define IMAGING_ARROW_INCOMPATIBLE_MODE -10
#define IMAGING_ARROW_MEMORY_LAYOUT -11 #define IMAGING_ARROW_MEMORY_LAYOUT -11
#include "ImagingUtils.h" #include "ImagingUtils.h"
extern UINT8 *clip8_lookups; extern UINT8 *clip8_lookups;