use mode structs in Convert.c

This commit is contained in:
Yay295 2024-04-21 18:00:42 -05:00
parent 5197ad775c
commit da808ce436
4 changed files with 245 additions and 193 deletions

View File

@ -4373,6 +4373,7 @@ setup_module(PyObject *m) {
} }
ImagingAccessInit(); ImagingAccessInit();
ImagingConvertInit();
#ifdef HAVE_LIBJPEG #ifdef HAVE_LIBJPEG
{ {
@ -4477,6 +4478,12 @@ setup_module(PyObject *m) {
return 0; return 0;
} }
static void
free_module(void *m) {
ImagingAccessFree();
ImagingConvertFree();
}
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__imaging(void) { PyInit__imaging(void) {
PyObject *m; PyObject *m;
@ -4487,6 +4494,10 @@ PyInit__imaging(void) {
NULL, /* m_doc */ NULL, /* m_doc */
-1, /* m_size */ -1, /* m_size */
functions, /* m_methods */ functions, /* m_methods */
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
free_module /* m_free */
}; };
m = PyModule_Create(&module_def); m = PyModule_Create(&module_def);

View File

@ -224,3 +224,6 @@ ImagingAccessNew(const Imaging im) {
void void
_ImagingAccessDelete(Imaging im, ImagingAccess access) {} _ImagingAccessDelete(Imaging im, ImagingAccess access) {}
void
ImagingAccessFree() {}

View File

@ -909,150 +909,12 @@ I16_RGB(UINT8 *out, const UINT8 *in, int xsize) {
} }
} }
static struct {
const char *from;
const char *to;
ImagingShuffler convert;
} converters[] = {
{"1", "L", bit2l},
{"1", "I", bit2i},
{"1", "F", bit2f},
{"1", "RGB", bit2rgb},
{"1", "RGBA", bit2rgb},
{"1", "RGBX", bit2rgb},
{"1", "CMYK", bit2cmyk},
{"1", "YCbCr", bit2ycbcr},
{"1", "HSV", bit2hsv},
{"L", "1", l2bit},
{"L", "LA", l2la},
{"L", "I", l2i},
{"L", "F", l2f},
{"L", "RGB", l2rgb},
{"L", "RGBA", l2rgb},
{"L", "RGBX", l2rgb},
{"L", "CMYK", l2cmyk},
{"L", "YCbCr", l2ycbcr},
{"L", "HSV", l2hsv},
{"LA", "L", la2l},
{"LA", "La", lA2la},
{"LA", "RGB", la2rgb},
{"LA", "RGBA", la2rgb},
{"LA", "RGBX", la2rgb},
{"LA", "CMYK", la2cmyk},
{"LA", "YCbCr", la2ycbcr},
{"LA", "HSV", la2hsv},
{"La", "LA", la2lA},
{"I", "L", i2l},
{"I", "F", i2f},
{"I", "RGB", i2rgb},
{"I", "RGBA", i2rgb},
{"I", "RGBX", i2rgb},
{"I", "HSV", i2hsv},
{"F", "L", f2l},
{"F", "I", f2i},
{"RGB", "1", rgb2bit},
{"RGB", "L", rgb2l},
{"RGB", "LA", rgb2la},
{"RGB", "La", rgb2la},
{"RGB", "I", rgb2i},
{"RGB", "I;16", rgb2i16l},
{"RGB", "I;16L", rgb2i16l},
{"RGB", "I;16B", rgb2i16b},
#ifdef WORDS_BIGENDIAN
{"RGB", "I;16N", rgb2i16b},
#else
{"RGB", "I;16N", rgb2i16l},
#endif
{"RGB", "F", rgb2f},
{"RGB", "BGR;15", rgb2bgr15},
{"RGB", "BGR;16", rgb2bgr16},
{"RGB", "BGR;24", rgb2bgr24},
{"RGB", "RGBA", rgb2rgba},
{"RGB", "RGBa", rgb2rgba},
{"RGB", "RGBX", rgb2rgba},
{"RGB", "CMYK", rgb2cmyk},
{"RGB", "YCbCr", ImagingConvertRGB2YCbCr},
{"RGB", "HSV", rgb2hsv},
{"RGBA", "1", rgb2bit},
{"RGBA", "L", rgb2l},
{"RGBA", "LA", rgba2la},
{"RGBA", "I", rgb2i},
{"RGBA", "F", rgb2f},
{"RGBA", "RGB", rgba2rgb},
{"RGBA", "RGBa", rgbA2rgba},
{"RGBA", "RGBX", rgb2rgba},
{"RGBA", "CMYK", rgb2cmyk},
{"RGBA", "YCbCr", ImagingConvertRGB2YCbCr},
{"RGBA", "HSV", rgb2hsv},
{"RGBa", "RGBA", rgba2rgbA},
{"RGBa", "RGB", rgba2rgb_},
{"RGBX", "1", rgb2bit},
{"RGBX", "L", rgb2l},
{"RGBX", "LA", rgb2la},
{"RGBX", "I", rgb2i},
{"RGBX", "F", rgb2f},
{"RGBX", "RGB", rgba2rgb},
{"RGBX", "CMYK", rgb2cmyk},
{"RGBX", "YCbCr", ImagingConvertRGB2YCbCr},
{"RGBX", "HSV", rgb2hsv},
{"CMYK", "RGB", cmyk2rgb},
{"CMYK", "RGBA", cmyk2rgb},
{"CMYK", "RGBX", cmyk2rgb},
{"CMYK", "HSV", cmyk2hsv},
{"YCbCr", "L", ycbcr2l},
{"YCbCr", "LA", ycbcr2la},
{"YCbCr", "RGB", ImagingConvertYCbCr2RGB},
{"HSV", "RGB", hsv2rgb},
{"I", "I;16", I_I16L},
{"I;16", "I", I16L_I},
{"I;16", "RGB", I16_RGB},
{"L", "I;16", L_I16L},
{"I;16", "L", I16L_L},
{"I", "I;16L", I_I16L},
{"I;16L", "I", I16L_I},
{"I", "I;16B", I_I16B},
{"I;16B", "I", I16B_I},
{"L", "I;16L", L_I16L},
{"I;16L", "L", I16L_L},
{"L", "I;16B", L_I16B},
{"I;16B", "L", I16B_L},
#ifdef WORDS_BIGENDIAN
{"L", "I;16N", L_I16B},
{"I;16N", "L", I16B_L},
#else
{"L", "I;16N", L_I16L},
{"I;16N", "L", I16L_L},
#endif
{"I;16", "F", I16L_F},
{"I;16L", "F", I16L_F},
{"I;16B", "F", I16B_F},
{NULL}
};
/* FIXME: translate indexed versions to pointer versions below this line */
/* ------------------- */ /* ------------------- */
/* Palette conversions */ /* Palette conversions */
/* ------------------- */ /* ------------------- */
/* FIXME: translate indexed versions to pointer versions below this line */
static void static void
p2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
int x; int x;
@ -1100,13 +962,13 @@ pa2p(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
static void static void
p2pa(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2pa(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
int x; int x;
int rgb = strcmp(palette->mode, "RGB"); const int rgb = palette->mode == IMAGING_MODE_RGB;
for (x = 0; x < xsize; x++, in++) { for (x = 0; x < xsize; x++, in++) {
const UINT8 *rgba = &palette->palette[in[0] * 4]; const UINT8 *rgba = &palette->palette[in[0] * 4];
*out++ = in[0]; *out++ = in[0];
*out++ = in[0]; *out++ = in[0];
*out++ = in[0]; *out++ = in[0];
*out++ = rgb == 0 ? 255 : rgba[3]; *out++ = rgb ? 255 : rgba[3];
} }
} }
@ -1260,7 +1122,7 @@ pa2ycbcr(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static Imaging static Imaging
frompalette(Imaging imOut, Imaging imIn, const char *mode) { frompalette(Imaging imOut, Imaging imIn, const Mode *mode) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int alpha; int alpha;
int y; int y;
@ -1272,31 +1134,31 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
return (Imaging)ImagingError_ValueError("no palette"); return (Imaging)ImagingError_ValueError("no palette");
} }
alpha = !strcmp(imIn->mode, "PA"); alpha = imIn->mode == IMAGING_MODE_PA;
if (strcmp(mode, "1") == 0) { if (mode == IMAGING_MODE_1) {
convert = alpha ? pa2bit : p2bit; convert = alpha ? pa2bit : p2bit;
} else if (strcmp(mode, "L") == 0) { } else if (mode == IMAGING_MODE_L) {
convert = alpha ? pa2l : p2l; convert = alpha ? pa2l : p2l;
} else if (strcmp(mode, "LA") == 0) { } else if (mode == IMAGING_MODE_LA) {
convert = alpha ? pa2la : p2la; convert = alpha ? pa2la : p2la;
} else if (strcmp(mode, "P") == 0) { } else if (mode == IMAGING_MODE_P) {
convert = pa2p; convert = pa2p;
} else if (strcmp(mode, "PA") == 0) { } else if (mode == IMAGING_MODE_PA) {
convert = p2pa; convert = p2pa;
} else if (strcmp(mode, "I") == 0) { } else if (mode == IMAGING_MODE_I) {
convert = alpha ? pa2i : p2i; convert = alpha ? pa2i : p2i;
} else if (strcmp(mode, "F") == 0) { } else if (mode == IMAGING_MODE_F) {
convert = alpha ? pa2f : p2f; convert = alpha ? pa2f : p2f;
} else if (strcmp(mode, "RGB") == 0) { } else if (mode == IMAGING_MODE_RGB) {
convert = alpha ? pa2rgb : p2rgb; convert = alpha ? pa2rgb : p2rgb;
} else if (strcmp(mode, "RGBA") == 0 || strcmp(mode, "RGBX") == 0) { } else if (mode == IMAGING_MODE_RGBA || mode == IMAGING_MODE_RGBX) {
convert = alpha ? pa2rgba : p2rgba; convert = alpha ? pa2rgba : p2rgba;
} else if (strcmp(mode, "CMYK") == 0) { } else if (mode == IMAGING_MODE_CMYK) {
convert = alpha ? pa2cmyk : p2cmyk; convert = alpha ? pa2cmyk : p2cmyk;
} else if (strcmp(mode, "YCbCr") == 0) { } else if (mode == IMAGING_MODE_YCbCr) {
convert = alpha ? pa2ycbcr : p2ycbcr; convert = alpha ? pa2ycbcr : p2ycbcr;
} else if (strcmp(mode, "HSV") == 0) { } else if (mode == IMAGING_MODE_HSV) {
convert = alpha ? pa2hsv : p2hsv; convert = alpha ? pa2hsv : p2hsv;
} else { } else {
return (Imaging)ImagingError_ValueError("conversion not supported"); return (Imaging)ImagingError_ValueError("conversion not supported");
@ -1306,7 +1168,7 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
if (!imOut) { if (!imOut) {
return NULL; return NULL;
} }
if (strcmp(mode, "P") == 0 || strcmp(mode, "PA") == 0) { if (mode == IMAGING_MODE_P || mode == IMAGING_MODE_PA) {
ImagingPaletteDelete(imOut->palette); ImagingPaletteDelete(imOut->palette);
imOut->palette = ImagingPaletteDuplicate(imIn->palette); imOut->palette = ImagingPaletteDuplicate(imIn->palette);
} }
@ -1330,24 +1192,26 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
#endif #endif
static Imaging static Imaging
topalette( topalette(
Imaging imOut, Imaging imIn, const char *mode, ImagingPalette inpalette, int dither Imaging imOut, Imaging imIn, const Mode *mode, ImagingPalette inpalette, int dither
) { ) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int alpha; int alpha;
int x, y; int x, y;
ImagingPalette palette = inpalette; ImagingPalette palette = inpalette;
/* Map L or RGB/RGBX/RGBA to palette image */ /* Map L or RGB/RGBX/RGBA/RGBa to palette image */
if (strcmp(imIn->mode, "L") != 0 && strncmp(imIn->mode, "RGB", 3) != 0) { if (imIn->mode != IMAGING_MODE_L && imIn->mode != IMAGING_MODE_RGB &&
imIn->mode != IMAGING_MODE_RGBX && imIn->mode != IMAGING_MODE_RGBA &&
imIn->mode != IMAGING_MODE_RGBa) {
return (Imaging)ImagingError_ValueError("conversion not supported"); return (Imaging)ImagingError_ValueError("conversion not supported");
} }
alpha = !strcmp(mode, "PA"); alpha = mode == IMAGING_MODE_PA;
if (palette == NULL) { if (palette == NULL) {
/* FIXME: make user configurable */ /* FIXME: make user configurable */
if (imIn->bands == 1) { if (imIn->bands == 1) {
palette = ImagingPaletteNew("RGB"); palette = ImagingPaletteNew(IMAGING_MODE_RGB);
palette->size = 256; palette->size = 256;
int i; int i;
@ -1534,11 +1398,11 @@ tobilevel(Imaging imOut, Imaging imIn) {
int *errors; int *errors;
/* Map L or RGB to dithered 1 image */ /* Map L or RGB to dithered 1 image */
if (strcmp(imIn->mode, "L") != 0 && strcmp(imIn->mode, "RGB") != 0) { if (imIn->mode != IMAGING_MODE_L && imIn->mode != IMAGING_MODE_RGB) {
return (Imaging)ImagingError_ValueError("conversion not supported"); return (Imaging)ImagingError_ValueError("conversion not supported");
} }
imOut = ImagingNew2Dirty("1", imOut, imIn); imOut = ImagingNew2Dirty(IMAGING_MODE_1, imOut, imIn);
if (!imOut) { if (!imOut) {
return NULL; return NULL;
} }
@ -1620,9 +1484,19 @@ tobilevel(Imaging imOut, Imaging imIn) {
#pragma optimize("", on) #pragma optimize("", on)
#endif #endif
/* ------------------- */
/* Conversion handlers */
/* ------------------- */
static struct Converter {
const Mode *from;
const Mode *to;
ImagingShuffler convert;
} *converters = NULL;
static Imaging static Imaging
convert( convert(
Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither Imaging imOut, Imaging imIn, const Mode *mode, ImagingPalette palette, int dither
) { ) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
ImagingShuffler convert; ImagingShuffler convert;
@ -1640,22 +1514,22 @@ convert(
mode = imIn->palette->mode; mode = imIn->palette->mode;
} else { } else {
/* Same mode? */ /* Same mode? */
if (!strcmp(imIn->mode, mode)) { if (imIn->mode == mode) {
return ImagingCopy2(imOut, imIn); return ImagingCopy2(imOut, imIn);
} }
} }
/* test for special conversions */ /* test for special conversions */
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "PA") == 0) { if (imIn->mode == IMAGING_MODE_P || imIn->mode == IMAGING_MODE_PA) {
return frompalette(imOut, imIn, mode); return frompalette(imOut, imIn, mode);
} }
if (strcmp(mode, "P") == 0 || strcmp(mode, "PA") == 0) { if (mode == IMAGING_MODE_P || mode == IMAGING_MODE_PA) {
return topalette(imOut, imIn, mode, palette, dither); return topalette(imOut, imIn, mode, palette, dither);
} }
if (dither && strcmp(mode, "1") == 0) { if (dither && mode == IMAGING_MODE_1) {
return tobilevel(imOut, imIn); return tobilevel(imOut, imIn);
} }
@ -1664,8 +1538,7 @@ convert(
convert = NULL; convert = NULL;
for (y = 0; converters[y].from; y++) { for (y = 0; converters[y].from; y++) {
if (!strcmp(imIn->mode, converters[y].from) && if (imIn->mode == converters[y].from && mode == converters[y].to) {
!strcmp(mode, converters[y].to)) {
convert = converters[y].convert; convert = converters[y].convert;
break; break;
} }
@ -1677,7 +1550,7 @@ convert(
#else #else
static char buf[100]; static char buf[100];
snprintf( snprintf(
buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode->name, mode->name
); );
return (Imaging)ImagingError_ValueError(buf); return (Imaging)ImagingError_ValueError(buf);
#endif #endif
@ -1698,7 +1571,7 @@ convert(
} }
Imaging Imaging
ImagingConvert(Imaging imIn, const char *mode, ImagingPalette palette, int dither) { ImagingConvert(Imaging imIn, const Mode *mode, ImagingPalette palette, int dither) {
return convert(NULL, imIn, mode, palette, dither); return convert(NULL, imIn, mode, palette, dither);
} }
@ -1708,7 +1581,7 @@ ImagingConvert2(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) { ImagingConvertTransparent(Imaging imIn, const Mode *mode, int r, int g, int b) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
ImagingShuffler convert; ImagingShuffler convert;
Imaging imOut = NULL; Imaging imOut = NULL;
@ -1722,27 +1595,30 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
return (Imaging)ImagingError_ModeError(); return (Imaging)ImagingError_ModeError();
} }
if (strcmp(imIn->mode, "RGB") == 0 && if (imIn->mode == IMAGING_MODE_RGB && (mode == IMAGING_MODE_RGBA || mode == IMAGING_MODE_RGBa)) {
(strcmp(mode, "RGBA") == 0 || strcmp(mode, "RGBa") == 0)) {
convert = rgb2rgba; convert = rgb2rgba;
if (strcmp(mode, "RGBa") == 0) { if (mode == IMAGING_MODE_RGBa) {
premultiplied = 1; premultiplied = 1;
} }
} else if (strcmp(imIn->mode, "RGB") == 0 && } else if (imIn->mode == IMAGING_MODE_RGB && (mode == IMAGING_MODE_LA || mode == IMAGING_MODE_La)) {
(strcmp(mode, "LA") == 0 || strcmp(mode, "La") == 0)) {
convert = rgb2la; convert = rgb2la;
source_transparency = 1; source_transparency = 1;
if (strcmp(mode, "La") == 0) { if (mode == IMAGING_MODE_La) {
premultiplied = 1; premultiplied = 1;
} }
} else if ((strcmp(imIn->mode, "1") == 0 || strcmp(imIn->mode, "I") == 0 || } else if ((imIn->mode == IMAGING_MODE_1 ||
strcmp(imIn->mode, "I;16") == 0 || strcmp(imIn->mode, "L") == 0) && imIn->mode == IMAGING_MODE_I ||
(strcmp(mode, "RGBA") == 0 || strcmp(mode, "LA") == 0)) { imIn->mode == IMAGING_MODE_I_16 ||
if (strcmp(imIn->mode, "1") == 0) { imIn->mode == IMAGING_MODE_L
) && (
mode == IMAGING_MODE_RGBA ||
mode == IMAGING_MODE_LA
)) {
if (imIn->mode == IMAGING_MODE_1) {
convert = bit2rgb; convert = bit2rgb;
} else if (strcmp(imIn->mode, "I") == 0) { } else if (imIn->mode == IMAGING_MODE_I) {
convert = i2rgb; convert = i2rgb;
} else if (strcmp(imIn->mode, "I;16") == 0) { } else if (imIn->mode == IMAGING_MODE_I_16) {
convert = I16_RGB; convert = I16_RGB;
} else { } else {
convert = l2rgb; convert = l2rgb;
@ -1754,8 +1630,8 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
buf, buf,
100, 100,
"conversion from %.10s to %.10s not supported in convert_transparent", "conversion from %.10s to %.10s not supported in convert_transparent",
imIn->mode, imIn->mode->name,
mode mode->name
); );
return (Imaging)ImagingError_ValueError(buf); return (Imaging)ImagingError_ValueError(buf);
} }
@ -1778,15 +1654,15 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
} }
Imaging Imaging
ImagingConvertInPlace(Imaging imIn, const char *mode) { ImagingConvertInPlace(Imaging imIn, const Mode *mode) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
ImagingShuffler convert; ImagingShuffler convert;
int y; int y;
/* limited support for inplace conversion */ /* limited support for inplace conversion */
if (strcmp(imIn->mode, "L") == 0 && strcmp(mode, "1") == 0) { if (imIn->mode == IMAGING_MODE_L && mode == IMAGING_MODE_1) {
convert = l2bit; convert = l2bit;
} else if (strcmp(imIn->mode, "1") == 0 && strcmp(mode, "L") == 0) { } else if (imIn->mode == IMAGING_MODE_1 && mode == IMAGING_MODE_L) {
convert = bit2l; convert = bit2l;
} else { } else {
return ImagingError_ModeError(); return ImagingError_ModeError();
@ -1800,3 +1676,154 @@ ImagingConvertInPlace(Imaging imIn, const char *mode) {
return imIn; return imIn;
} }
/* ------------------ */
/* Converter mappings */
/* ------------------ */
void
ImagingConvertInit() {
const struct Converter temp[] = {
{IMAGING_MODE_1, IMAGING_MODE_L, bit2l},
{IMAGING_MODE_1, IMAGING_MODE_I, bit2i},
{IMAGING_MODE_1, IMAGING_MODE_F, bit2f},
{IMAGING_MODE_1, IMAGING_MODE_RGB, bit2rgb},
{IMAGING_MODE_1, IMAGING_MODE_RGBA, bit2rgb},
{IMAGING_MODE_1, IMAGING_MODE_RGBX, bit2rgb},
{IMAGING_MODE_1, IMAGING_MODE_CMYK, bit2cmyk},
{IMAGING_MODE_1, IMAGING_MODE_YCbCr, bit2ycbcr},
{IMAGING_MODE_1, IMAGING_MODE_HSV, bit2hsv},
{IMAGING_MODE_L, IMAGING_MODE_1, l2bit},
{IMAGING_MODE_L, IMAGING_MODE_LA, l2la},
{IMAGING_MODE_L, IMAGING_MODE_I, l2i},
{IMAGING_MODE_L, IMAGING_MODE_F, l2f},
{IMAGING_MODE_L, IMAGING_MODE_RGB, l2rgb},
{IMAGING_MODE_L, IMAGING_MODE_RGBA, l2rgb},
{IMAGING_MODE_L, IMAGING_MODE_RGBX, l2rgb},
{IMAGING_MODE_L, IMAGING_MODE_CMYK, l2cmyk},
{IMAGING_MODE_L, IMAGING_MODE_YCbCr, l2ycbcr},
{IMAGING_MODE_L, IMAGING_MODE_HSV, l2hsv},
{IMAGING_MODE_LA, IMAGING_MODE_L, la2l},
{IMAGING_MODE_LA, IMAGING_MODE_La, lA2la},
{IMAGING_MODE_LA, IMAGING_MODE_RGB, la2rgb},
{IMAGING_MODE_LA, IMAGING_MODE_RGBA, la2rgb},
{IMAGING_MODE_LA, IMAGING_MODE_RGBX, la2rgb},
{IMAGING_MODE_LA, IMAGING_MODE_CMYK, la2cmyk},
{IMAGING_MODE_LA, IMAGING_MODE_YCbCr, la2ycbcr},
{IMAGING_MODE_LA, IMAGING_MODE_HSV, la2hsv},
{IMAGING_MODE_La, IMAGING_MODE_LA, la2lA},
{IMAGING_MODE_I, IMAGING_MODE_L, i2l},
{IMAGING_MODE_I, IMAGING_MODE_F, i2f},
{IMAGING_MODE_I, IMAGING_MODE_RGB, i2rgb},
{IMAGING_MODE_I, IMAGING_MODE_RGBA, i2rgb},
{IMAGING_MODE_I, IMAGING_MODE_RGBX, i2rgb},
{IMAGING_MODE_I, IMAGING_MODE_HSV, i2hsv},
{IMAGING_MODE_F, IMAGING_MODE_L, f2l},
{IMAGING_MODE_F, IMAGING_MODE_I, f2i},
{IMAGING_MODE_RGB, IMAGING_MODE_1, rgb2bit},
{IMAGING_MODE_RGB, IMAGING_MODE_L, rgb2l},
{IMAGING_MODE_RGB, IMAGING_MODE_LA, rgb2la},
{IMAGING_MODE_RGB, IMAGING_MODE_La, rgb2la},
{IMAGING_MODE_RGB, IMAGING_MODE_I, rgb2i},
{IMAGING_MODE_RGB, IMAGING_MODE_I_16, rgb2i16l},
{IMAGING_MODE_RGB, IMAGING_MODE_I_16L, rgb2i16l},
{IMAGING_MODE_RGB, IMAGING_MODE_I_16B, rgb2i16b},
#ifdef WORDS_BIGENDIAN
{IMAGING_MODE_RGB, IMAGING_MODE_I_16N, rgb2i16b},
#else
{IMAGING_MODE_RGB, IMAGING_MODE_I_16N, rgb2i16l},
#endif
{IMAGING_MODE_RGB, IMAGING_MODE_F, rgb2f},
{IMAGING_MODE_RGB, IMAGING_MODE_BGR_15, rgb2bgr15},
{IMAGING_MODE_RGB, IMAGING_MODE_BGR_16, rgb2bgr16},
{IMAGING_MODE_RGB, IMAGING_MODE_BGR_24, rgb2bgr24},
{IMAGING_MODE_RGB, IMAGING_MODE_RGBA, rgb2rgba},
{IMAGING_MODE_RGB, IMAGING_MODE_RGBa, rgb2rgba},
{IMAGING_MODE_RGB, IMAGING_MODE_RGBX, rgb2rgba},
{IMAGING_MODE_RGB, IMAGING_MODE_CMYK, rgb2cmyk},
{IMAGING_MODE_RGB, IMAGING_MODE_YCbCr, ImagingConvertRGB2YCbCr},
{IMAGING_MODE_RGB, IMAGING_MODE_HSV, rgb2hsv},
{IMAGING_MODE_RGBA, IMAGING_MODE_1, rgb2bit},
{IMAGING_MODE_RGBA, IMAGING_MODE_L, rgb2l},
{IMAGING_MODE_RGBA, IMAGING_MODE_LA, rgba2la},
{IMAGING_MODE_RGBA, IMAGING_MODE_I, rgb2i},
{IMAGING_MODE_RGBA, IMAGING_MODE_F, rgb2f},
{IMAGING_MODE_RGBA, IMAGING_MODE_RGB, rgba2rgb},
{IMAGING_MODE_RGBA, IMAGING_MODE_RGBa, rgbA2rgba},
{IMAGING_MODE_RGBA, IMAGING_MODE_RGBX, rgb2rgba},
{IMAGING_MODE_RGBA, IMAGING_MODE_CMYK, rgb2cmyk},
{IMAGING_MODE_RGBA, IMAGING_MODE_YCbCr, ImagingConvertRGB2YCbCr},
{IMAGING_MODE_RGBA, IMAGING_MODE_HSV, rgb2hsv},
{IMAGING_MODE_RGBa, IMAGING_MODE_RGBA, rgba2rgbA},
{IMAGING_MODE_RGBa, IMAGING_MODE_RGB, rgba2rgb_},
{IMAGING_MODE_RGBX, IMAGING_MODE_1, rgb2bit},
{IMAGING_MODE_RGBX, IMAGING_MODE_L, rgb2l},
{IMAGING_MODE_RGBX, IMAGING_MODE_LA, rgb2la},
{IMAGING_MODE_RGBX, IMAGING_MODE_I, rgb2i},
{IMAGING_MODE_RGBX, IMAGING_MODE_F, rgb2f},
{IMAGING_MODE_RGBX, IMAGING_MODE_RGB, rgba2rgb},
{IMAGING_MODE_RGBX, IMAGING_MODE_CMYK, rgb2cmyk},
{IMAGING_MODE_RGBX, IMAGING_MODE_YCbCr, ImagingConvertRGB2YCbCr},
{IMAGING_MODE_RGBX, IMAGING_MODE_HSV, rgb2hsv},
{IMAGING_MODE_CMYK, IMAGING_MODE_RGB, cmyk2rgb},
{IMAGING_MODE_CMYK, IMAGING_MODE_RGBA, cmyk2rgb},
{IMAGING_MODE_CMYK, IMAGING_MODE_RGBX, cmyk2rgb},
{IMAGING_MODE_CMYK, IMAGING_MODE_HSV, cmyk2hsv},
{IMAGING_MODE_YCbCr, IMAGING_MODE_L, ycbcr2l},
{IMAGING_MODE_YCbCr, IMAGING_MODE_LA, ycbcr2la},
{IMAGING_MODE_YCbCr, IMAGING_MODE_RGB, ImagingConvertYCbCr2RGB},
{IMAGING_MODE_HSV, IMAGING_MODE_RGB, hsv2rgb},
{IMAGING_MODE_I, IMAGING_MODE_I_16, I_I16L},
{IMAGING_MODE_I_16, IMAGING_MODE_I, I16L_I},
{IMAGING_MODE_I_16, IMAGING_MODE_RGB, I16_RGB},
{IMAGING_MODE_L, IMAGING_MODE_I_16, L_I16L},
{IMAGING_MODE_I_16, IMAGING_MODE_L, I16L_L},
{IMAGING_MODE_I, IMAGING_MODE_I_16L, I_I16L},
{IMAGING_MODE_I_16L, IMAGING_MODE_I, I16L_I},
{IMAGING_MODE_I, IMAGING_MODE_I_16B, I_I16B},
{IMAGING_MODE_I_16B, IMAGING_MODE_I, I16B_I},
{IMAGING_MODE_L, IMAGING_MODE_I_16L, L_I16L},
{IMAGING_MODE_I_16L, IMAGING_MODE_L, I16L_L},
{IMAGING_MODE_L, IMAGING_MODE_I_16B, L_I16B},
{IMAGING_MODE_I_16B, IMAGING_MODE_L, I16B_L},
#ifdef WORDS_BIGENDIAN
{IMAGING_MODE_L, IMAGING_MODE_I_16N, L_I16B},
{IMAGING_MODE_I_16N, IMAGING_MODE_L, I16B_L},
#else
{IMAGING_MODE_L, IMAGING_MODE_I_16N, L_I16L},
{IMAGING_MODE_I_16N, IMAGING_MODE_L, I16L_L},
#endif
{IMAGING_MODE_I_16, IMAGING_MODE_F, I16L_F},
{IMAGING_MODE_I_16L, IMAGING_MODE_F, I16L_F},
{IMAGING_MODE_I_16B, IMAGING_MODE_F, I16B_F},
{NULL}
};
converters = malloc(sizeof(temp));
if (converters == NULL) {
fprintf(stderr, "ConvertInit: failed to allocate memory for converter table\n");
exit(1);
}
memcpy(converters, temp, sizeof(temp));
}
void
ImagingConvertFree() {
free(converters);
}

View File

@ -163,6 +163,19 @@ typedef struct ImagingMemoryArena {
#endif #endif
} *ImagingMemoryArena; } *ImagingMemoryArena;
/* Memory Management */
/* ----------------- */
extern void
ImagingAccessInit(void);
extern void
ImagingAccessFree(void);
extern void
ImagingConvertInit(void);
extern void
ImagingConvertFree(void);
/* Objects */ /* Objects */
/* ------- */ /* ------- */
@ -195,8 +208,6 @@ ImagingCopyPalette(Imaging destination, Imaging source);
extern void extern void
ImagingHistogramDelete(ImagingHistogram histogram); ImagingHistogramDelete(ImagingHistogram histogram);
extern void
ImagingAccessInit(void);
extern ImagingAccess extern ImagingAccess
ImagingAccessNew(Imaging im); ImagingAccessNew(Imaging im);
extern void extern void