diff --git a/src/libImaging/Arrow.c b/src/libImaging/Arrow.c index 2f7b154a1..2fd8e5233 100644 --- a/src/libImaging/Arrow.c +++ b/src/libImaging/Arrow.c @@ -199,9 +199,9 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) { } if (im->bands == 1) { - retval = export_named_type(schema, - im->modedata->arrow_band_format, - im->modedata->band_names[0]); + retval = export_named_type( + schema, im->modedata->arrow_band_format, im->modedata->band_names[0] + ); if (retval != 0) { return retval; } diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index 056c96580..db8f7b96e 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -79,12 +79,12 @@ typedef struct { struct ImagingMemoryInstance { /* Format */ - ModeID mode; /* Image mode (IMAGING_MODE_*) */ + ModeID mode; /* Image mode (IMAGING_MODE_*) */ const ModeData *modedata; /* mode data struct */ - int type; /* Data type (IMAGING_TYPE_*) */ - int depth; /* Depth (ignored in this version) */ - int bands; /* Number of bands (1, 2, 3, or 4) */ - int xsize; /* Image dimension. */ + int type; /* Data type (IMAGING_TYPE_*) */ + int depth; /* Depth (ignored in this version) */ + int bands; /* Number of bands (1, 2, 3, or 4) */ + int xsize; /* Image dimension. */ int ysize; /* Colour palette (for "P" images only) */ @@ -106,7 +106,7 @@ struct ImagingMemoryInstance { void (*destroy)(Imaging im); /* 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 */ PyObject *arrow_array_capsule; /* upstream arrow array source */ diff --git a/src/libImaging/Mode.c b/src/libImaging/Mode.c index 05ce3dfa1..9d8ff9c98 100644 --- a/src/libImaging/Mode.c +++ b/src/libImaging/Mode.c @@ -9,154 +9,175 @@ const ModeData MODES[] = { [IMAGING_MODE_UNKNOWN] = {""}, - [IMAGING_MODE_1] = { - .name = "1", - .arrow_band_format = "C", - .bands = 1, - .pixelsize = 1, - .band_names = {"1"}, - }, - [IMAGING_MODE_CMYK] = { - .name = "CMYK", - .bands = 4, - .pixelsize = 4, - .arrow_band_format = "C", - .band_names = {"C", "M", "Y", "K"}, - }, - [IMAGING_MODE_F] = { - .name = "F", - .bands = 1, - .pixelsize = 4, - .arrow_band_format = "f", - .band_names = {"F"}, - }, - [IMAGING_MODE_HSV] = { - .name = "HSV", - .bands = 3, - .pixelsize = 4, - .arrow_band_format = "C", - .band_names = {"H", "S", "V", "X"}, - }, - [IMAGING_MODE_I] = { - .name = "I", - .bands = 1, - .pixelsize = 4, - .arrow_band_format = "i", - .band_names = {"I"}, - }, - [IMAGING_MODE_L] = { - .name = "L", - .bands = 1, - .pixelsize = 1, - .arrow_band_format = "C", - .band_names = {"L"}, - }, - [IMAGING_MODE_LA] = { - .name = "LA", - .bands = 2, - .pixelsize = 4, - .arrow_band_format = "C", - .band_names = {"L", "X", "X", "A"}, - }, - [IMAGING_MODE_LAB] = { - .name = "LAB", - .bands = 3, - .pixelsize = 4, - .arrow_band_format = "C", - .band_names = {"L", "a", "b", "X"}, - }, - [IMAGING_MODE_La] = { - .name = "La", - .bands = 2, - .pixelsize = 4, - .arrow_band_format = "C", - .band_names = {"L", "X", "X", "a"}, - }, - [IMAGING_MODE_P] = { - .name = "P", - .bands = 1, - .pixelsize = 1, - .arrow_band_format = "C", - .band_names = {"P"}, - }, - [IMAGING_MODE_PA] = { - .name = "PA", - .bands = 2, - .pixelsize = 4, - .arrow_band_format = "C", - .band_names = {"P", "X", "X", "A"}, - }, - [IMAGING_MODE_RGB] = { - .name = "RGB", - .bands = 3, - .pixelsize = 4, - .arrow_band_format = "C", - .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_RGBX] = { - .name = "RGBX", - .bands = 4, - .pixelsize = 4, - .arrow_band_format = "C", - .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_1] = + { + .name = "1", + .arrow_band_format = "C", + .bands = 1, + .pixelsize = 1, + .band_names = {"1"}, + }, + [IMAGING_MODE_CMYK] = + { + .name = "CMYK", + .bands = 4, + .pixelsize = 4, + .arrow_band_format = "C", + .band_names = {"C", "M", "Y", "K"}, + }, + [IMAGING_MODE_F] = + { + .name = "F", + .bands = 1, + .pixelsize = 4, + .arrow_band_format = "f", + .band_names = {"F"}, + }, + [IMAGING_MODE_HSV] = + { + .name = "HSV", + .bands = 3, + .pixelsize = 4, + .arrow_band_format = "C", + .band_names = {"H", "S", "V", "X"}, + }, + [IMAGING_MODE_I] = + { + .name = "I", + .bands = 1, + .pixelsize = 4, + .arrow_band_format = "i", + .band_names = {"I"}, + }, + [IMAGING_MODE_L] = + { + .name = "L", + .bands = 1, + .pixelsize = 1, + .arrow_band_format = "C", + .band_names = {"L"}, + }, + [IMAGING_MODE_LA] = + { + .name = "LA", + .bands = 2, + .pixelsize = 4, + .arrow_band_format = "C", + .band_names = {"L", "X", "X", "A"}, + }, + [IMAGING_MODE_LAB] = + { + .name = "LAB", + .bands = 3, + .pixelsize = 4, + .arrow_band_format = "C", + .band_names = {"L", "a", "b", "X"}, + }, + [IMAGING_MODE_La] = + { + .name = "La", + .bands = 2, + .pixelsize = 4, + .arrow_band_format = "C", + .band_names = {"L", "X", "X", "a"}, + }, + [IMAGING_MODE_P] = + { + .name = "P", + .bands = 1, + .pixelsize = 1, + .arrow_band_format = "C", + .band_names = {"P"}, + }, + [IMAGING_MODE_PA] = + { + .name = "PA", + .bands = 2, + .pixelsize = 4, + .arrow_band_format = "C", + .band_names = {"P", "X", "X", "A"}, + }, + [IMAGING_MODE_RGB] = + { + .name = "RGB", + .bands = 3, + .pixelsize = 4, + .arrow_band_format = "C", + .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_RGBX] = + { + .name = "RGBX", + .bands = 4, + .pixelsize = 4, + .arrow_band_format = "C", + .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] = { - .name = "I;16", - .bands = 1, - .pixelsize = 2, - .arrow_band_format = "s", - .band_names = {"I"}, - }, - [IMAGING_MODE_I_16L] = { - .name = "I;16L", - .bands = 1, - .pixelsize = 2, - .arrow_band_format = "s", - .band_names = {"I"}, - }, - [IMAGING_MODE_I_16B] = { - .name = "I;16B", - .bands = 1, - .pixelsize = 2, - .arrow_band_format = "s", - .band_names = {"I"}, - }, - [IMAGING_MODE_I_16N] = { - .name = "I;16N", - .bands = 1, - .pixelsize = 2, - .arrow_band_format = "s", - .band_names = {"I"}, - }, - [IMAGING_MODE_I_32L] = { - .name = "I;32L", - .bands = 1, - .pixelsize = 4, - .arrow_band_format = "i", - .band_names = {"I"}, - }, + [IMAGING_MODE_I_16] = + { + .name = "I;16", + .bands = 1, + .pixelsize = 2, + .arrow_band_format = "s", + .band_names = {"I"}, + }, + [IMAGING_MODE_I_16L] = + { + .name = "I;16L", + .bands = 1, + .pixelsize = 2, + .arrow_band_format = "s", + .band_names = {"I"}, + }, + [IMAGING_MODE_I_16B] = + { + .name = "I;16B", + .bands = 1, + .pixelsize = 2, + .arrow_band_format = "s", + .band_names = {"I"}, + }, + [IMAGING_MODE_I_16N] = + { + .name = "I;16N", + .bands = 1, + .pixelsize = 2, + .arrow_band_format = "s", + .band_names = {"I"}, + }, + [IMAGING_MODE_I_32L] = + { + .name = "I;32L", + .bands = 1, + .pixelsize = 4, + .arrow_band_format = "i", + .band_names = {"I"}, + }, [IMAGING_MODE_I_32B] = { .name = "I;32B", .bands = 1, diff --git a/src/libImaging/Mode.h b/src/libImaging/Mode.h index b7c5851b2..4baf04319 100644 --- a/src/libImaging/Mode.h +++ b/src/libImaging/Mode.h @@ -34,7 +34,7 @@ typedef struct { const char *const arrow_band_format; const int bands; const int pixelsize; - const char *band_names[4]; /* names of bands */ + const char *band_names[4]; /* names of bands */ } ModeData; const ModeID diff --git a/src/libImaging/Storage.c b/src/libImaging/Storage.c index c810f9bb8..f8c73988a 100644 --- a/src/libImaging/Storage.c +++ b/src/libImaging/Storage.c @@ -130,7 +130,6 @@ ImagingNewPrologueSubtype(const ModeID mode, int xsize, int ysize, int size) { return (Imaging)ImagingError_ValueError("unrecognized image mode"); } - /* Setup image descriptor */ im->mode = mode; @@ -608,7 +607,7 @@ ImagingNewArrow( && im->bands >= 2) // INT32 into any INT32 Storage 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) { // one arrow element per, and it matches a pixelsize*char if (ImagingBorrowArrow(im, external_array, im->pixelsize, array_capsule)) { @@ -620,11 +619,11 @@ ImagingNewArrow( && im->pixelsize == 4 // storage as 32 bpc && schema->n_children > 0 // 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 - && pixels == external_array->length // expected length - && external_array->n_children == 1 // array is well formed - && external_array->children // array is well formed + && pixels == external_array->length // expected length + && external_array->n_children == 1 // array is well formed + && 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)) { @@ -632,11 +631,11 @@ ImagingNewArrow( } } // Stored as [r,g,b,a,r,g,b,a,...] - if (strcmp(schema->format, "C") == 0 // uint8 - && im->pixelsize == 4 // storage as 32 bpc - && schema->n_children == 0 // make sure schema is well formed. + if (strcmp(schema->format, "C") == 0 // uint8 + && im->pixelsize == 4 // storage as 32 bpc + && schema->n_children == 0 // make sure schema is well formed. && 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. if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) { return im;