Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,9 @@ _new_arrow(PyObject *self, PyObject *args) {
mode_id = findModeID(mode);

// ImagingBorrowArrow is responsible for retaining the array_capsule
ret = PyImagingNew(
return PyImagingNew(
ImagingNewArrow(mode_id, xsize, ysize, schema_capsule, array_capsule)
);
if (!ret) {
return ImagingError_ValueError("Invalid Arrow array mode or size mismatch");
}
return ret;
}

/* -------------------------------------------------------------------- */
Expand Down
31 changes: 19 additions & 12 deletions src/libImaging/Storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ ImagingDestroyArrow(Imaging im) {
}
}

Imaging
int
ImagingBorrowArrow(
Imaging im,
struct ArrowArray *external_array,
Expand All @@ -571,9 +571,8 @@ ImagingBorrowArrow(
}

if (!borrowed_buffer) {
return (Imaging)ImagingError_ValueError(
"Arrow Array, exactly 2 buffers required"
);
ImagingError_ValueError("Arrow Array, exactly 2 buffers required");
return 0;
}

for (y = i = 0; y < im->ysize; y++) {
Expand All @@ -585,7 +584,7 @@ ImagingBorrowArrow(
im->arrow_array_capsule = arrow_capsule;
im->destroy = ImagingDestroyArrow;

return im;
return 1;
}

/* --------------------------------------------------------------------
Expand Down Expand Up @@ -709,9 +708,11 @@ ImagingNewArrow(
&& 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, array_capsule)) {
return im;
if (!ImagingBorrowArrow(im, external_array, im->pixelsize, array_capsule)) {
ImagingDelete(im);
return NULL;
}
return im;
}
// Stored as [[r,g,b,a],...]
if (strcmp(schema->format, "+w:4") == 0 // 4 up array
Expand All @@ -725,9 +726,11 @@ ImagingNewArrow(
&& 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, array_capsule)) {
return im;
if (!ImagingBorrowArrow(im, external_array, 1, array_capsule)) {
ImagingDelete(im);
return NULL;
}
return im;
}
// Stored as [r,g,b,a,r,g,b,a,...]
if (strcmp(schema->format, "C") == 0 // uint8
Expand All @@ -736,13 +739,17 @@ ImagingNewArrow(
&& strcmp(im->arrow_band_format, "C") == 0 // expected format
&& 4 * pixels == external_array->length) { // expected length
// single flat array, interleaved storage.
if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) {
return im;
if (!ImagingBorrowArrow(im, external_array, 1, array_capsule)) {
ImagingDelete(im);
return NULL;
}
return im;
}
// fmt: on
ImagingDelete(im);
return NULL;
return (Imaging)ImagingError_ValueError(
"Invalid Arrow array mode or size mismatch"
);
}

Imaging
Expand Down
Loading