[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-10-21 20:11:11 +00:00
parent 4a71709b37
commit 787d899a37
5 changed files with 187 additions and 167 deletions

View File

@ -199,9 +199,9 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
} }
if (im->bands == 1) { if (im->bands == 1) {
retval = export_named_type(schema, retval = export_named_type(
im->modedata->arrow_band_format, schema, im->modedata->arrow_band_format, im->modedata->band_names[0]
im->modedata->band_names[0]); );
if (retval != 0) { if (retval != 0) {
return retval; return retval;
} }

View File

@ -79,12 +79,12 @@ typedef struct {
struct ImagingMemoryInstance { struct ImagingMemoryInstance {
/* Format */ /* Format */
ModeID mode; /* Image mode (IMAGING_MODE_*) */ ModeID mode; /* Image mode (IMAGING_MODE_*) */
const ModeData *modedata; /* mode data struct */ const ModeData *modedata; /* mode data struct */
int type; /* Data type (IMAGING_TYPE_*) */ int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */ int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */ int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */ int xsize; /* Image dimension. */
int ysize; int ysize;
/* Colour palette (for "P" images only) */ /* Colour palette (for "P" images only) */
@ -106,7 +106,7 @@ struct ImagingMemoryInstance {
void (*destroy)(Imaging im); void (*destroy)(Imaging im);
/* arrow */ /* arrow */
int refcount; /* Number of arrow arrays that have been allocated */ int refcount; /* Number of arrow arrays that have been allocated */
int read_only; /* flag for read-only. set for arrow borrowed arrays */ int read_only; /* flag for read-only. set for arrow borrowed arrays */
PyObject *arrow_array_capsule; /* upstream arrow array source */ PyObject *arrow_array_capsule; /* upstream arrow array source */

View File

@ -9,154 +9,175 @@
const ModeData MODES[] = { const ModeData MODES[] = {
[IMAGING_MODE_UNKNOWN] = {""}, [IMAGING_MODE_UNKNOWN] = {""},
[IMAGING_MODE_1] = { [IMAGING_MODE_1] =
.name = "1", {
.arrow_band_format = "C", .name = "1",
.bands = 1, .arrow_band_format = "C",
.pixelsize = 1, .bands = 1,
.band_names = {"1"}, .pixelsize = 1,
}, .band_names = {"1"},
[IMAGING_MODE_CMYK] = { },
.name = "CMYK", [IMAGING_MODE_CMYK] =
.bands = 4, {
.pixelsize = 4, .name = "CMYK",
.arrow_band_format = "C", .bands = 4,
.band_names = {"C", "M", "Y", "K"}, .pixelsize = 4,
}, .arrow_band_format = "C",
[IMAGING_MODE_F] = { .band_names = {"C", "M", "Y", "K"},
.name = "F", },
.bands = 1, [IMAGING_MODE_F] =
.pixelsize = 4, {
.arrow_band_format = "f", .name = "F",
.band_names = {"F"}, .bands = 1,
}, .pixelsize = 4,
[IMAGING_MODE_HSV] = { .arrow_band_format = "f",
.name = "HSV", .band_names = {"F"},
.bands = 3, },
.pixelsize = 4, [IMAGING_MODE_HSV] =
.arrow_band_format = "C", {
.band_names = {"H", "S", "V", "X"}, .name = "HSV",
}, .bands = 3,
[IMAGING_MODE_I] = { .pixelsize = 4,
.name = "I", .arrow_band_format = "C",
.bands = 1, .band_names = {"H", "S", "V", "X"},
.pixelsize = 4, },
.arrow_band_format = "i", [IMAGING_MODE_I] =
.band_names = {"I"}, {
}, .name = "I",
[IMAGING_MODE_L] = { .bands = 1,
.name = "L", .pixelsize = 4,
.bands = 1, .arrow_band_format = "i",
.pixelsize = 1, .band_names = {"I"},
.arrow_band_format = "C", },
.band_names = {"L"}, [IMAGING_MODE_L] =
}, {
[IMAGING_MODE_LA] = { .name = "L",
.name = "LA", .bands = 1,
.bands = 2, .pixelsize = 1,
.pixelsize = 4, .arrow_band_format = "C",
.arrow_band_format = "C", .band_names = {"L"},
.band_names = {"L", "X", "X", "A"}, },
}, [IMAGING_MODE_LA] =
[IMAGING_MODE_LAB] = { {
.name = "LAB", .name = "LA",
.bands = 3, .bands = 2,
.pixelsize = 4, .pixelsize = 4,
.arrow_band_format = "C", .arrow_band_format = "C",
.band_names = {"L", "a", "b", "X"}, .band_names = {"L", "X", "X", "A"},
}, },
[IMAGING_MODE_La] = { [IMAGING_MODE_LAB] =
.name = "La", {
.bands = 2, .name = "LAB",
.pixelsize = 4, .bands = 3,
.arrow_band_format = "C", .pixelsize = 4,
.band_names = {"L", "X", "X", "a"}, .arrow_band_format = "C",
}, .band_names = {"L", "a", "b", "X"},
[IMAGING_MODE_P] = { },
.name = "P", [IMAGING_MODE_La] =
.bands = 1, {
.pixelsize = 1, .name = "La",
.arrow_band_format = "C", .bands = 2,
.band_names = {"P"}, .pixelsize = 4,
}, .arrow_band_format = "C",
[IMAGING_MODE_PA] = { .band_names = {"L", "X", "X", "a"},
.name = "PA", },
.bands = 2, [IMAGING_MODE_P] =
.pixelsize = 4, {
.arrow_band_format = "C", .name = "P",
.band_names = {"P", "X", "X", "A"}, .bands = 1,
}, .pixelsize = 1,
[IMAGING_MODE_RGB] = { .arrow_band_format = "C",
.name = "RGB", .band_names = {"P"},
.bands = 3, },
.pixelsize = 4, [IMAGING_MODE_PA] =
.arrow_band_format = "C", {
.band_names = {"R", "G", "B", "X"}, .name = "PA",
}, .bands = 2,
[IMAGING_MODE_RGBA] = { .pixelsize = 4,
.name = "RGBA", .arrow_band_format = "C",
.bands = 4, .band_names = {"P", "X", "X", "A"},
.pixelsize = 4, },
.arrow_band_format = "C", [IMAGING_MODE_RGB] =
.band_names = {"R", "G", "B", "A"}, {
}, .name = "RGB",
[IMAGING_MODE_RGBX] = { .bands = 3,
.name = "RGBX", .pixelsize = 4,
.bands = 4, .arrow_band_format = "C",
.pixelsize = 4, .band_names = {"R", "G", "B", "X"},
.arrow_band_format = "C", },
.band_names = {"R", "G", "B", "X"}, [IMAGING_MODE_RGBA] =
}, {
[IMAGING_MODE_RGBa] = { .name = "RGBA",
.name = "RGBa", .bands = 4,
.bands = 4, .pixelsize = 4,
.pixelsize = 4, .arrow_band_format = "C",
.arrow_band_format = "C", .band_names = {"R", "G", "B", "A"},
.band_names = {"R", "G", "B", "a"}, },
}, [IMAGING_MODE_RGBX] =
[IMAGING_MODE_YCbCr] = { {
.name = "YCbCr", .name = "RGBX",
.bands = 3, .bands = 4,
.pixelsize = 4, .pixelsize = 4,
.arrow_band_format = "C", .arrow_band_format = "C",
.band_names = {"Y", "Cb", "Cr", "X"}, .band_names = {"R", "G", "B", "X"},
}, },
[IMAGING_MODE_RGBa] =
{
.name = "RGBa",
.bands = 4,
.pixelsize = 4,
.arrow_band_format = "C",
.band_names = {"R", "G", "B", "a"},
},
[IMAGING_MODE_YCbCr] =
{
.name = "YCbCr",
.bands = 3,
.pixelsize = 4,
.arrow_band_format = "C",
.band_names = {"Y", "Cb", "Cr", "X"},
},
[IMAGING_MODE_I_16] = { [IMAGING_MODE_I_16] =
.name = "I;16", {
.bands = 1, .name = "I;16",
.pixelsize = 2, .bands = 1,
.arrow_band_format = "s", .pixelsize = 2,
.band_names = {"I"}, .arrow_band_format = "s",
}, .band_names = {"I"},
[IMAGING_MODE_I_16L] = { },
.name = "I;16L", [IMAGING_MODE_I_16L] =
.bands = 1, {
.pixelsize = 2, .name = "I;16L",
.arrow_band_format = "s", .bands = 1,
.band_names = {"I"}, .pixelsize = 2,
}, .arrow_band_format = "s",
[IMAGING_MODE_I_16B] = { .band_names = {"I"},
.name = "I;16B", },
.bands = 1, [IMAGING_MODE_I_16B] =
.pixelsize = 2, {
.arrow_band_format = "s", .name = "I;16B",
.band_names = {"I"}, .bands = 1,
}, .pixelsize = 2,
[IMAGING_MODE_I_16N] = { .arrow_band_format = "s",
.name = "I;16N", .band_names = {"I"},
.bands = 1, },
.pixelsize = 2, [IMAGING_MODE_I_16N] =
.arrow_band_format = "s", {
.band_names = {"I"}, .name = "I;16N",
}, .bands = 1,
[IMAGING_MODE_I_32L] = { .pixelsize = 2,
.name = "I;32L", .arrow_band_format = "s",
.bands = 1, .band_names = {"I"},
.pixelsize = 4, },
.arrow_band_format = "i", [IMAGING_MODE_I_32L] =
.band_names = {"I"}, {
}, .name = "I;32L",
.bands = 1,
.pixelsize = 4,
.arrow_band_format = "i",
.band_names = {"I"},
},
[IMAGING_MODE_I_32B] = { [IMAGING_MODE_I_32B] = {
.name = "I;32B", .name = "I;32B",
.bands = 1, .bands = 1,

View File

@ -34,7 +34,7 @@ typedef struct {
const char *const arrow_band_format; const char *const arrow_band_format;
const int bands; const int bands;
const int pixelsize; const int pixelsize;
const char *band_names[4]; /* names of bands */ const char *band_names[4]; /* names of bands */
} ModeData; } ModeData;
const ModeID const ModeID

View File

@ -130,7 +130,6 @@ ImagingNewPrologueSubtype(const ModeID mode, int xsize, int ysize, int size) {
return (Imaging)ImagingError_ValueError("unrecognized image mode"); return (Imaging)ImagingError_ValueError("unrecognized image mode");
} }
/* Setup image descriptor */ /* Setup image descriptor */
im->mode = mode; im->mode = mode;
@ -608,7 +607,7 @@ ImagingNewArrow(
&& im->bands >= 2) // INT32 into any INT32 Storage mode && im->bands >= 2) // INT32 into any INT32 Storage mode
|| // (()||()) && || // (()||()) &&
(strcmp(schema->format, im->modedata->arrow_band_format) == 0 // same mode (strcmp(schema->format, im->modedata->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, array_capsule)) { if (ImagingBorrowArrow(im, external_array, im->pixelsize, array_capsule)) {
@ -620,11 +619,11 @@ ImagingNewArrow(
&& im->pixelsize == 4 // storage as 32 bpc && im->pixelsize == 4 // storage as 32 bpc
&& schema->n_children > 0 // make sure schema is well formed. && schema->n_children > 0 // make sure schema is well formed.
&& schema->children // make sure schema is well formed && schema->children // make sure schema is well formed
&& strcmp(schema->children[0]->format, "C") == 0 // Expected format && strcmp(schema->children[0]->format, "C") == 0 // Expected format
&& strcmp(im->modedata->arrow_band_format, "C") == 0 // Expected Format && strcmp(im->modedata->arrow_band_format, "C") == 0 // Expected Format
&& pixels == external_array->length // expected length && pixels == external_array->length // expected length
&& external_array->n_children == 1 // array is well formed && external_array->n_children == 1 // array is well formed
&& external_array->children // array is well formed && external_array->children // array is well formed
&& 4 * pixels == external_array->children[0]->length) { && 4 * pixels == external_array->children[0]->length) {
// 4 up element of char into pixelsize == 4 // 4 up element of char into pixelsize == 4
if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) { if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) {
@ -632,11 +631,11 @@ ImagingNewArrow(
} }
} }
// Stored as [r,g,b,a,r,g,b,a,...] // Stored as [r,g,b,a,r,g,b,a,...]
if (strcmp(schema->format, "C") == 0 // uint8 if (strcmp(schema->format, "C") == 0 // uint8
&& im->pixelsize == 4 // storage as 32 bpc && im->pixelsize == 4 // storage as 32 bpc
&& schema->n_children == 0 // make sure schema is well formed. && schema->n_children == 0 // make sure schema is well formed.
&& strcmp(im->modedata->arrow_band_format, "C") == 0 // expected format && strcmp(im->modedata->arrow_band_format, "C") == 0 // expected format
&& 4 * pixels == external_array->length) { // expected length && 4 * pixels == external_array->length) { // expected length
// single flat array, interleaved storage. // single flat array, interleaved storage.
if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) { if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) {
return im; return im;