[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
assert reloaded.readonly == 1
def test_multiblock_l_image():
block_size = Image.core.get_block_size()
# check a 2 block image in single channel mode
size = (4096, 2*block_size//4096)
img = Image.new('L', size, 128)
size = (4096, 2 * block_size // 4096)
img = Image.new("L", size, 128)
with pytest.raises(ValueError):
(schema, arr) = img.__arrow_c_array__()
def test_multiblock__rgba_image():
block_size = Image.core.get_block_size()
# check a 2 block image in 4 channel mode
size = (4096, (block_size//4096) //2)
img = Image.new('RGBA', size, (128,127,126,125))
size = (4096, (block_size // 4096) // 2)
img = Image.new("RGBA", size, (128, 127, 126, 125))
with pytest.raises(ValueError):
(schema, arr) = img.__arrow_c_array__()
@ -184,18 +186,19 @@ def test_multiblock_l_schema():
block_size = Image.core.get_block_size()
# check a 2 block image in single channel mode
size = (4096, 2*block_size//4096)
img = Image.new('L', size, 128)
size = (4096, 2 * block_size // 4096)
img = Image.new("L", size, 128)
with pytest.raises(ValueError):
schema = img.__arrow_c_schema__()
def test_multiblock__rgba_schema():
block_size = Image.core.get_block_size()
# check a 2 block image in 4 channel mode
size = (4096, (block_size//4096) //2)
img = Image.new('RGBA', size, (128,127,126,125))
size = (4096, (block_size // 4096) // 2)
img = Image.new("RGBA", size, (128, 127, 126, 125))
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 *
ArrowError(int err) {
if (err == IMAGING_CODEC_MEMORY) {
return ImagingError_MemoryError();
return ImagingError_MemoryError();
}
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) {
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");
}
@ -257,7 +259,7 @@ ExportArrowSchemaPyCapsule(ImagingObject *self) {
(struct ArrowSchema *)calloc(1, sizeof(struct ArrowSchema));
int err = export_imaging_schema(self->image, schema);
if (err == 0) {
return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule);
return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule);
}
free(schema);
return ArrowError(err);
@ -279,14 +281,13 @@ ExportArrowArrayPyCapsule(ImagingObject *self) {
(struct ArrowArray *)calloc(1, sizeof(struct ArrowArray));
int err = export_imaging_array(self->image, array);
if (err == 0) {
return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule);
return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule);
}
free(array);
// raise error here
return ArrowError(err);
}
static PyObject *
_new_arrow(PyObject *self, PyObject *args) {
char *mode;

View File

@ -76,15 +76,15 @@ export_named_type(struct ArrowSchema *schema, char *format, char *name) {
strncpy(namep, name, name_len);
*schema = (struct ArrowSchema){// Type description
.format = formatp,
.name = namep,
.metadata = NULL,
.flags = 0,
.n_children = 0,
.children = NULL,
.dictionary = NULL,
// Bookkeeping
.release = &ReleaseExportedSchema
.format = formatp,
.name = namep,
.metadata = NULL,
.flags = 0,
.n_children = 0,
.children = NULL,
.dictionary = NULL,
// Bookkeeping
.release = &ReleaseExportedSchema
};
return 0;
}
@ -98,7 +98,7 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
}
/* 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;
}
@ -123,8 +123,6 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
return 0;
}
static void
release_const_array(struct ArrowArray *array) {
Imaging im = (Imaging)array->private_data;
@ -140,8 +138,8 @@ release_const_array(struct ArrowArray *array) {
}
if (array->children) {
// undone -- does arrow release all the children recursively.
for (int i=0; i < array->n_children; i++) {
if (array->children[i]->release){
for (int i = 0; i < array->n_children; i++) {
if (array->children[i]->release) {
array->children[i]->release(array->children[i]);
array->children[i]->release = NULL;
free(array->children[i]);
@ -159,7 +157,7 @@ export_single_channel_array(Imaging im, struct ArrowArray *array) {
int length = im->xsize * im->ysize;
/* 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;
}
@ -274,7 +272,7 @@ export_fixed_pixel_array(Imaging im, struct ArrowArray *array) {
}
return 0;
err:
err:
if (array->children[0]) {
free(array->children[0]);
}

View File

@ -121,8 +121,6 @@ struct ImagingMemoryInstance {
#ifdef Py_GIL_DISABLED
PyMutex mutex;
#endif
};
#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_MEMORY_LAYOUT -11
#include "ImagingUtils.h"
extern UINT8 *clip8_lookups;

View File

@ -303,8 +303,8 @@ ImagingDelete(Imaging im) {
im->refcount--;
if (im->refcount > 0) {
MUTEX_UNLOCK(im->mutex);
return;
MUTEX_UNLOCK(im->mutex);
return;
}
MUTEX_UNLOCK(im->mutex);
@ -702,10 +702,10 @@ ImagingNewArrow(
// fmt:off // don't reformat this
if (((strcmp(schema->format, "I") == 0 // int32
&& im->pixelsize == 4 // 4xchar* storage
&& im->bands >= 2) // INT32 into any INT32 Storage mode
|| // (()||()) &&
(strcmp(schema->format, im->arrow_band_format) == 0 // same mode
&& im->bands == 1)) // Single band match
&& im->bands >= 2) // INT32 into any INT32 Storage mode
|| // (()||()) &&
(strcmp(schema->format, im->arrow_band_format) == 0 // same mode
&& 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)) {