Skip to content
Draft
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
20 changes: 11 additions & 9 deletions src/libImaging/Arrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
json,
len,
format,
im->band_names[0],
im->band_names[1],
im->band_names[2],
im->band_names[3]
im->modedata->band_names[0],
im->modedata->band_names[1],
im->modedata->band_names[2],
im->modedata->band_names[3]
);
if (err < 0) {
return NULL;
Expand All @@ -98,7 +98,7 @@
return NULL;
}

err = PyOS_snprintf(json, len, format, im->band_names[0]);
err = PyOS_snprintf(json, len, format, im->modedata->band_names[0]);
if (err < 0) {
return NULL;
}
Expand Down Expand Up @@ -189,7 +189,7 @@
int retval = 0;
char *band_json;

if (strcmp(im->arrow_band_format, "") == 0) {
if (strcmp(im->modedata->arrow_band_format, "") == 0) {
return IMAGING_ARROW_INCOMPATIBLE_MODE;
}

Expand All @@ -199,7 +199,9 @@
}

if (im->bands == 1) {
retval = export_named_type(schema, im->arrow_band_format, im->band_names[0]);
retval = export_named_type(
schema, im->modedata->arrow_band_format, im->modedata->band_names[0]

Check warning on line 203 in src/libImaging/Arrow.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.14

passing argument 2 of ‘export_named_type’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
);
if (retval != 0) {
return retval;
}
Expand All @@ -221,7 +223,7 @@
schema->children = calloc(1, sizeof(struct ArrowSchema *));
schema->children[0] = (struct ArrowSchema *)calloc(1, sizeof(struct ArrowSchema));
retval = export_named_type(
schema->children[0], im->arrow_band_format, getModeData(im->mode)->name
schema->children[0], im->modedata->arrow_band_format, im->modedata->name

Check warning on line 226 in src/libImaging/Arrow.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.14

passing argument 2 of ‘export_named_type’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
);
if (retval != 0) {
free(schema->children[0]);
Expand Down Expand Up @@ -405,7 +407,7 @@

int
export_imaging_array(Imaging im, struct ArrowArray *array) {
if (strcmp(im->arrow_band_format, "") == 0) {
if (strcmp(im->modedata->arrow_band_format, "") == 0) {
return IMAGING_ARROW_INCOMPATIBLE_MODE;
}

Expand Down
15 changes: 7 additions & 8 deletions src/libImaging/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ typedef struct {

struct ImagingMemoryInstance {
/* Format */
ModeID mode; /* Image mode (IMAGING_MODE_*) */
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. */
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 ysize;

/* Colour palette (for "P" images only) */
Expand All @@ -105,9 +106,7 @@ struct ImagingMemoryInstance {
void (*destroy)(Imaging im);

/* arrow */
int refcount; /* Number of arrow arrays that have been allocated */
char band_names[4][3]; /* names of bands, max 2 char + null terminator */
char arrow_band_format[2]; /* single character + null terminator */
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 */
Expand Down
186 changes: 175 additions & 11 deletions src/libImaging/Mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,182 @@
const ModeData MODES[] = {
[IMAGING_MODE_UNKNOWN] = {""},

[IMAGING_MODE_1] = {"1"}, [IMAGING_MODE_CMYK] = {"CMYK"},
[IMAGING_MODE_F] = {"F"}, [IMAGING_MODE_HSV] = {"HSV"},
[IMAGING_MODE_I] = {"I"}, [IMAGING_MODE_L] = {"L"},
[IMAGING_MODE_LA] = {"LA"}, [IMAGING_MODE_LAB] = {"LAB"},
[IMAGING_MODE_La] = {"La"}, [IMAGING_MODE_P] = {"P"},
[IMAGING_MODE_PA] = {"PA"}, [IMAGING_MODE_RGB] = {"RGB"},
[IMAGING_MODE_RGBA] = {"RGBA"}, [IMAGING_MODE_RGBX] = {"RGBX"},
[IMAGING_MODE_RGBa] = {"RGBa"}, [IMAGING_MODE_YCbCr] = {"YCbCr"},
[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] = {"I;16"}, [IMAGING_MODE_I_16L] = {"I;16L"},
[IMAGING_MODE_I_16B] = {"I;16B"}, [IMAGING_MODE_I_16N] = {"I;16N"},
[IMAGING_MODE_I_32L] = {"I;32L"}, [IMAGING_MODE_I_32B] = {"I;32B"},
[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,
.pixelsize = 4,
.arrow_band_format = "i",
.band_names = {"I"},
},
};

const ModeID
Expand Down
4 changes: 4 additions & 0 deletions src/libImaging/Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ typedef enum {

typedef struct {
const char *const name;
const char *const arrow_band_format;
const int bands;
const int pixelsize;
const char *band_names[4]; /* names of bands */
} ModeData;

const ModeID
Expand Down
Loading
Loading