Pillow
Pillow copied to clipboard
New struct for image mode data
Currently all of the data about the format/mode of an image is stored in the image itself.
https://github.com/python-pillow/Pillow/blob/ad7be550aa539dc4c79da928dad071cf0150b731/src/libImaging/Imaging.h#L80-L107
I think it would be cleaner if this information was stored in a separate struct.
struct ImageMode {
char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */
int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
};
Furthermore, I think some more changes could be made that would simplify coding for some calculations, and allow for more image formats to be processed (#1888).
struct BandDataType {
char dataType; /* 'u' = unsigned integer, 's' = signed integer, 'f' = floating point */
UINT8 numBytes;
} BAND_DATA_TYPES[] = {
{'u', 1}, /* UINT8 */
{'u', 2}, /* UINT16 */
{'s', 4}, /* INT32 */
{'f', 4}, /* FLOAT32 */
};
/* Normal bands are treated normally */
/* Alpha bands may be treated specially by some calculations */
/* Extra bands are ignored (this could be used for padding, or maybe storing non-image data) */
enum BandType { NORMAL, ALPHA, EXTRA };
struct Band {
char *name; /* "R", "G", "B", "Y", "Cb", "Cr", etc. */
BandDataType dataType;
BandType type;
};
struct ImageFormat {
char *name; /* Format name ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
Band *bands; /* Array of bands in this format */
UINT32 numBands; /* Number of bands in this format */
UINT32 numBytes; /* Total size in bytes of one pixel in this format */
};