mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-16 04:16:35 +03:00
initialize accessors similar to converters/packers/unpackers
This commit is contained in:
parent
1b1f250b74
commit
d46284368a
|
@ -11,10 +11,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#define ACCESS_TABLE_SIZE 24
|
|
||||||
static struct ImagingAccessInstance ACCESS_TABLE[ACCESS_TABLE_SIZE];
|
|
||||||
|
|
||||||
|
|
||||||
/* fetch individual pixel */
|
/* fetch individual pixel */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -155,68 +151,56 @@ put_pixel_32(Imaging im, int x, int y, const void *color) {
|
||||||
memcpy(&im->image32[y][x], color, sizeof(INT32));
|
memcpy(&im->image32[y][x], color, sizeof(INT32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct ImagingAccessInstance *accessors = NULL;
|
||||||
static void
|
|
||||||
set_access_table_item(
|
|
||||||
const int index,
|
|
||||||
const Mode * const mode,
|
|
||||||
void (*get_pixel)(Imaging im, int x, int y, void *pixel),
|
|
||||||
void (*put_pixel)(Imaging im, int x, int y, const void *pixel)
|
|
||||||
) {
|
|
||||||
ACCESS_TABLE[index].mode = mode;
|
|
||||||
ACCESS_TABLE[index].get_pixel = get_pixel;
|
|
||||||
ACCESS_TABLE[index].put_pixel = put_pixel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ImagingAccessInit(void) {
|
ImagingAccessInit(void) {
|
||||||
int i = 0;
|
const struct ImagingAccessInstance temp[] = {
|
||||||
set_access_table_item(i++, IMAGING_MODE_1, get_pixel_8, put_pixel_8);
|
{IMAGING_MODE_1, get_pixel_8, put_pixel_8},
|
||||||
set_access_table_item(i++, IMAGING_MODE_L, get_pixel_8, put_pixel_8);
|
{IMAGING_MODE_L, get_pixel_8, put_pixel_8},
|
||||||
set_access_table_item(i++, IMAGING_MODE_LA, get_pixel_32_2bands, put_pixel_32);
|
{IMAGING_MODE_LA, get_pixel_32_2bands, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_La, get_pixel_32_2bands, put_pixel_32);
|
{IMAGING_MODE_La, get_pixel_32_2bands, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_I, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_I, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_16, get_pixel_16L, put_pixel_16L);
|
{IMAGING_MODE_I_16, get_pixel_16L, put_pixel_16L},
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_16L, get_pixel_16L, put_pixel_16L);
|
{IMAGING_MODE_I_16L, get_pixel_16L, put_pixel_16L},
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_16B, get_pixel_16B, put_pixel_16B);
|
{IMAGING_MODE_I_16B, get_pixel_16B, put_pixel_16B},
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_16N, get_pixel_16B, put_pixel_16B);
|
{IMAGING_MODE_I_16N, get_pixel_16B, put_pixel_16B},
|
||||||
#else
|
#else
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_16N, get_pixel_16L, put_pixel_16L);
|
{IMAGING_MODE_I_16N, get_pixel_16L, put_pixel_16L},
|
||||||
#endif
|
#endif
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_32L, get_pixel_32L, put_pixel_32L);
|
{IMAGING_MODE_I_32L, get_pixel_32L, put_pixel_32L},
|
||||||
set_access_table_item(i++, IMAGING_MODE_I_32B, get_pixel_32B, put_pixel_32B);
|
{IMAGING_MODE_I_32B, get_pixel_32B, put_pixel_32B},
|
||||||
set_access_table_item(i++, IMAGING_MODE_F, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_F, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_P, get_pixel_8, put_pixel_8);
|
{IMAGING_MODE_P, get_pixel_8, put_pixel_8},
|
||||||
set_access_table_item(i++, IMAGING_MODE_PA, get_pixel_32_2bands, put_pixel_32);
|
{IMAGING_MODE_PA, get_pixel_32_2bands, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_BGR_15, get_pixel_BGR15, put_pixel_BGR1516);
|
{IMAGING_MODE_BGR_15, get_pixel_BGR15, put_pixel_BGR1516},
|
||||||
set_access_table_item(i++, IMAGING_MODE_BGR_16, get_pixel_BGR16, put_pixel_BGR1516);
|
{IMAGING_MODE_BGR_16, get_pixel_BGR16, put_pixel_BGR1516},
|
||||||
set_access_table_item(i++, IMAGING_MODE_BGR_24, get_pixel_BGR24, put_pixel_BGR24);
|
{IMAGING_MODE_BGR_24, get_pixel_BGR24, put_pixel_BGR24},
|
||||||
set_access_table_item(i++, IMAGING_MODE_RGB, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_RGB, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_RGBA, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_RGBA, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_RGBa, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_RGBa, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_RGBX, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_RGBX, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_CMYK, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_CMYK, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_YCbCr, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_YCbCr, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_LAB, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_LAB, get_pixel_32, put_pixel_32},
|
||||||
set_access_table_item(i++, IMAGING_MODE_HSV, get_pixel_32, put_pixel_32);
|
{IMAGING_MODE_HSV, get_pixel_32, put_pixel_32},
|
||||||
|
{NULL}
|
||||||
if (i != ACCESS_TABLE_SIZE) {
|
};
|
||||||
fprintf(
|
accessors = malloc(sizeof(temp));
|
||||||
stderr,
|
if (accessors == NULL) {
|
||||||
"AccessInit: incorrect number of items added to ACCESS_TABLE; expected %i but got %i\n",
|
fprintf(stderr, "AccessInit: failed to allocate memory for accessors table\n");
|
||||||
ACCESS_TABLE_SIZE,
|
|
||||||
i);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
memcpy(accessors, temp, sizeof(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagingAccess
|
ImagingAccess
|
||||||
ImagingAccessNew(const Imaging im) {
|
ImagingAccessNew(const Imaging im) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < ACCESS_TABLE_SIZE; i++) {
|
for (i = 0; accessors[i].mode; i++) {
|
||||||
if (im->mode == ACCESS_TABLE[i].mode) {
|
if (im->mode == accessors[i].mode) {
|
||||||
return &ACCESS_TABLE[i];
|
return &accessors[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -226,4 +210,7 @@ void
|
||||||
_ImagingAccessDelete(Imaging im, ImagingAccess access) {}
|
_ImagingAccessDelete(Imaging im, ImagingAccess access) {}
|
||||||
|
|
||||||
void
|
void
|
||||||
ImagingAccessFree(void) {}
|
ImagingAccessFree(void) {
|
||||||
|
free(accessors);
|
||||||
|
accessors = NULL;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user