mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-12-04 16:54:28 +03:00
Move bands and pixel size into the mode data struct
* Just copy these in because they're ints * Calculate the line size, because it's just pixelsize * xsize
This commit is contained in:
parent
8df33d19d9
commit
4a71709b37
|
|
@ -9,30 +9,161 @@
|
||||||
const ModeData MODES[] = {
|
const ModeData MODES[] = {
|
||||||
[IMAGING_MODE_UNKNOWN] = {""},
|
[IMAGING_MODE_UNKNOWN] = {""},
|
||||||
|
|
||||||
// Name, Arrow Format, Band Names
|
[IMAGING_MODE_1] = {
|
||||||
[IMAGING_MODE_1] = {"1", "C", {"1"}},
|
.name = "1",
|
||||||
[IMAGING_MODE_CMYK] = {"CMYK", "C", {"C", "M", "Y", "K"}},
|
.arrow_band_format = "C",
|
||||||
[IMAGING_MODE_F] = {"F", "f", {"F"}},
|
.bands = 1,
|
||||||
[IMAGING_MODE_HSV] = {"HSV", "C", {"H", "S", "V", "X"}},
|
.pixelsize = 1,
|
||||||
[IMAGING_MODE_I] = {"I", "i", {"I"}},
|
.band_names = {"1"},
|
||||||
[IMAGING_MODE_L] = {"L", "C", {"L"}},
|
},
|
||||||
[IMAGING_MODE_LA] = {"LA", "C", {"L", "X", "X", "A"}},
|
[IMAGING_MODE_CMYK] = {
|
||||||
[IMAGING_MODE_LAB] = {"LAB", "C", {"L", "a", "b", "X"}},
|
.name = "CMYK",
|
||||||
[IMAGING_MODE_La] = {"La", "C", {"L", "X", "X", "a"}},
|
.bands = 4,
|
||||||
[IMAGING_MODE_P] = {"P", "C", {"P"}},
|
.pixelsize = 4,
|
||||||
[IMAGING_MODE_PA] = {"PA", "C", {"P", "X", "X", "A"}},
|
.arrow_band_format = "C",
|
||||||
[IMAGING_MODE_RGB] = {"RGB", "C", {"R", "G", "B", "X"}},
|
.band_names = {"C", "M", "Y", "K"},
|
||||||
[IMAGING_MODE_RGBA] = {"RGBA", "C", {"R", "G", "B", "A"}},
|
},
|
||||||
[IMAGING_MODE_RGBX] = {"RGBX", "C", {"R", "G", "B", "X"}},
|
[IMAGING_MODE_F] = {
|
||||||
[IMAGING_MODE_RGBa] = {"RGBa", "C", {"R", "G", "B", "a"}},
|
.name = "F",
|
||||||
[IMAGING_MODE_YCbCr] = {"YCbCr", "C", {"Y", "Cb", "Cr", "X"}},
|
.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", "s", {"I"}},
|
[IMAGING_MODE_I_16] = {
|
||||||
[IMAGING_MODE_I_16L] = {"I;16L", "s", {"I"}},
|
.name = "I;16",
|
||||||
[IMAGING_MODE_I_16B] = {"I;16B", "s", {"I"}},
|
.bands = 1,
|
||||||
[IMAGING_MODE_I_16N] = {"I;16N", "s", {"I"}},
|
.pixelsize = 2,
|
||||||
[IMAGING_MODE_I_32L] = {"I;32L", "i", {"I"}},
|
.arrow_band_format = "s",
|
||||||
[IMAGING_MODE_I_32B] = {"I;32B", "i", {"I"}},
|
.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
|
const ModeID
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *const name;
|
const char *const name;
|
||||||
const char *const arrow_band_format;
|
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;
|
} ModeData;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,114 +62,75 @@ ImagingNewPrologueSubtype(const ModeID mode, int xsize, int ysize, int size) {
|
||||||
im->type = IMAGING_TYPE_UINT8;
|
im->type = IMAGING_TYPE_UINT8;
|
||||||
im->modedata = getModeData(mode);
|
im->modedata = getModeData(mode);
|
||||||
|
|
||||||
|
im->bands = im->modedata->bands;
|
||||||
|
im->pixelsize = im->modedata->pixelsize;
|
||||||
|
im->linesize = xsize * im->pixelsize;
|
||||||
|
|
||||||
if (mode == IMAGING_MODE_1) {
|
if (mode == IMAGING_MODE_1) {
|
||||||
/* 1-bit images */
|
/* 1-bit images */
|
||||||
im->bands = im->pixelsize = 1;
|
|
||||||
im->linesize = xsize;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_P) {
|
} else if (mode == IMAGING_MODE_P) {
|
||||||
/* 8-bit palette mapped images */
|
/* 8-bit palette mapped images */
|
||||||
im->bands = im->pixelsize = 1;
|
|
||||||
im->linesize = xsize;
|
|
||||||
im->palette = ImagingPaletteNew(IMAGING_MODE_RGB);
|
im->palette = ImagingPaletteNew(IMAGING_MODE_RGB);
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_PA) {
|
} else if (mode == IMAGING_MODE_PA) {
|
||||||
/* 8-bit palette with alpha */
|
/* 8-bit palette with alpha */
|
||||||
im->bands = 2;
|
|
||||||
im->pixelsize = 4; /* store in image32 memory */
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
im->palette = ImagingPaletteNew(IMAGING_MODE_RGB);
|
im->palette = ImagingPaletteNew(IMAGING_MODE_RGB);
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_L) {
|
} else if (mode == IMAGING_MODE_L) {
|
||||||
/* 8-bit grayscale (luminance) images */
|
/* 8-bit grayscale (luminance) images */
|
||||||
im->bands = im->pixelsize = 1;
|
|
||||||
im->linesize = xsize;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_LA) {
|
} else if (mode == IMAGING_MODE_LA) {
|
||||||
/* 8-bit grayscale (luminance) with alpha */
|
/* 8-bit grayscale (luminance) with alpha */
|
||||||
im->bands = 2;
|
|
||||||
im->pixelsize = 4; /* store in image32 memory */
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_La) {
|
} else if (mode == IMAGING_MODE_La) {
|
||||||
/* 8-bit grayscale (luminance) with premultiplied alpha */
|
/* 8-bit grayscale (luminance) with premultiplied alpha */
|
||||||
im->bands = 2;
|
|
||||||
im->pixelsize = 4; /* store in image32 memory */
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_F) {
|
} else if (mode == IMAGING_MODE_F) {
|
||||||
/* 32-bit floating point images */
|
/* 32-bit floating point images */
|
||||||
im->bands = 1;
|
|
||||||
im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
im->type = IMAGING_TYPE_FLOAT32;
|
im->type = IMAGING_TYPE_FLOAT32;
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_I) {
|
} else if (mode == IMAGING_MODE_I) {
|
||||||
/* 32-bit integer images */
|
/* 32-bit integer images */
|
||||||
im->bands = 1;
|
|
||||||
im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
im->type = IMAGING_TYPE_INT32;
|
im->type = IMAGING_TYPE_INT32;
|
||||||
|
|
||||||
} else if (isModeI16(mode)) {
|
} else if (isModeI16(mode)) {
|
||||||
/* EXPERIMENTAL */
|
/* EXPERIMENTAL */
|
||||||
/* 16-bit raw integer images */
|
/* 16-bit raw integer images */
|
||||||
im->bands = 1;
|
|
||||||
im->pixelsize = 2;
|
|
||||||
im->linesize = xsize * 2;
|
|
||||||
im->type = IMAGING_TYPE_SPECIAL;
|
im->type = IMAGING_TYPE_SPECIAL;
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_RGB) {
|
} else if (mode == IMAGING_MODE_RGB) {
|
||||||
/* 24-bit true colour images */
|
/* 24-bit true colour images */
|
||||||
im->bands = 3;
|
|
||||||
im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_RGBX) {
|
} else if (mode == IMAGING_MODE_RGBX) {
|
||||||
/* 32-bit true colour images with padding */
|
/* 32-bit true colour images with padding */
|
||||||
im->bands = im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_RGBA) {
|
} else if (mode == IMAGING_MODE_RGBA) {
|
||||||
/* 32-bit true colour images with alpha */
|
/* 32-bit true colour images with alpha */
|
||||||
im->bands = im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_RGBa) {
|
} else if (mode == IMAGING_MODE_RGBa) {
|
||||||
/* 32-bit true colour images with premultiplied alpha */
|
/* 32-bit true colour images with premultiplied alpha */
|
||||||
im->bands = im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_CMYK) {
|
} else if (mode == IMAGING_MODE_CMYK) {
|
||||||
/* 32-bit colour separation */
|
/* 32-bit colour separation */
|
||||||
im->bands = im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_YCbCr) {
|
} else if (mode == IMAGING_MODE_YCbCr) {
|
||||||
/* 24-bit video format */
|
/* 24-bit video format */
|
||||||
im->bands = 3;
|
|
||||||
im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_LAB) {
|
} else if (mode == IMAGING_MODE_LAB) {
|
||||||
/* 24-bit color, luminance, + 2 color channels */
|
/* 24-bit color, luminance, + 2 color channels */
|
||||||
/* L is uint8, a,b are int8 */
|
/* L is uint8, a,b are int8 */
|
||||||
im->bands = 3;
|
|
||||||
im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else if (mode == IMAGING_MODE_HSV) {
|
} else if (mode == IMAGING_MODE_HSV) {
|
||||||
/* 24-bit color, luminance, + 2 color channels */
|
/* 24-bit color, luminance, + 2 color channels */
|
||||||
/* L is uint8, a,b are int8 */
|
/* L is uint8, a,b are int8 */
|
||||||
im->bands = 3;
|
|
||||||
im->pixelsize = 4;
|
|
||||||
im->linesize = xsize * 4;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
free(im);
|
free(im);
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user