[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

@ -230,13 +230,15 @@ PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view) {
PyObject * PyObject *
ArrowError(int err) { ArrowError(int err) {
if (err == IMAGING_CODEC_MEMORY) { if (err == IMAGING_CODEC_MEMORY) {
return ImagingError_MemoryError(); return ImagingError_MemoryError();
} }
if (err == IMAGING_ARROW_INCOMPATIBLE_MODE) { if (err == IMAGING_ARROW_INCOMPATIBLE_MODE) {
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");
} }
@ -257,7 +259,7 @@ ExportArrowSchemaPyCapsule(ImagingObject *self) {
(struct ArrowSchema *)calloc(1, sizeof(struct ArrowSchema)); (struct ArrowSchema *)calloc(1, sizeof(struct ArrowSchema));
int err = export_imaging_schema(self->image, schema); int err = export_imaging_schema(self->image, schema);
if (err == 0) { if (err == 0) {
return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule); return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule);
} }
free(schema); free(schema);
return ArrowError(err); return ArrowError(err);
@ -279,14 +281,13 @@ ExportArrowArrayPyCapsule(ImagingObject *self) {
(struct ArrowArray *)calloc(1, sizeof(struct ArrowArray)); (struct ArrowArray *)calloc(1, sizeof(struct ArrowArray));
int err = export_imaging_array(self->image, array); int err = export_imaging_array(self->image, array);
if (err == 0) { if (err == 0) {
return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule); return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule);
} }
free(array); free(array);
// raise error here // raise error here
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

@ -76,15 +76,15 @@ export_named_type(struct ArrowSchema *schema, char *format, char *name) {
strncpy(namep, name, name_len); strncpy(namep, name, name_len);
*schema = (struct ArrowSchema){// Type description *schema = (struct ArrowSchema){// Type description
.format = formatp, .format = formatp,
.name = namep, .name = namep,
.metadata = NULL, .metadata = NULL,
.flags = 0, .flags = 0,
.n_children = 0, .n_children = 0,
.children = NULL, .children = NULL,
.dictionary = NULL, .dictionary = NULL,
// Bookkeeping // Bookkeeping
.release = &ReleaseExportedSchema .release = &ReleaseExportedSchema
}; };
return 0; return 0;
} }
@ -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;

View File

@ -303,8 +303,8 @@ ImagingDelete(Imaging im) {
im->refcount--; im->refcount--;
if (im->refcount > 0) { if (im->refcount > 0) {
MUTEX_UNLOCK(im->mutex); MUTEX_UNLOCK(im->mutex);
return; return;
} }
MUTEX_UNLOCK(im->mutex); MUTEX_UNLOCK(im->mutex);
@ -702,10 +702,10 @@ ImagingNewArrow(
// fmt:off // don't reformat this // fmt:off // don't reformat this
if (((strcmp(schema->format, "I") == 0 // int32 if (((strcmp(schema->format, "I") == 0 // int32
&& im->pixelsize == 4 // 4xchar* storage && im->pixelsize == 4 // 4xchar* storage
&& im->bands >= 2) // INT32 into any INT32 Storage mode && im->bands >= 2) // INT32 into any INT32 Storage mode
|| // (()||()) && || // (()||()) &&
(strcmp(schema->format, im->arrow_band_format) == 0 // same mode (strcmp(schema->format, im->arrow_band_format) == 0 // same mode
&& im->bands == 1)) // Single band match && im->bands == 1)) // Single band match
&& pixels == external_array->length) { && pixels == external_array->length) {
// one arrow element per, and it matches a pixelsize*char // one arrow element per, and it matches a pixelsize*char
if (ImagingBorrowArrow(im, external_array, im->pixelsize)) { if (ImagingBorrowArrow(im, external_array, im->pixelsize)) {