mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-15 01:34:45 +03:00
update ImagingGetColors() for up to 4-byte pixels
This commit is contained in:
parent
49099beb3d
commit
eba429c9a3
|
@ -240,22 +240,12 @@ ImagingGetExtrema(Imaging im, void *extrema) {
|
||||||
return 1; /* ok */
|
return 1; /* ok */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static ImagingColorItem* getcolors8(Imaging im, int maxcolors, int* size);*/
|
|
||||||
static ImagingColorItem *
|
|
||||||
getcolors32(Imaging im, int maxcolors, int *size);
|
|
||||||
|
|
||||||
ImagingColorItem *
|
ImagingColorItem *
|
||||||
ImagingGetColors(Imaging im, int maxcolors, int *size) {
|
ImagingGetColors(Imaging im, int maxcolors, int *size) {
|
||||||
/* FIXME: add support for 8-bit images */
|
|
||||||
return getcolors32(im, maxcolors, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImagingColorItem *
|
|
||||||
getcolors32(Imaging im, int maxcolors, int *size) {
|
|
||||||
unsigned int h;
|
unsigned int h;
|
||||||
unsigned int i, incr;
|
unsigned int i, incr;
|
||||||
int colors;
|
int colors;
|
||||||
INT32 pixel_mask;
|
INT32 pixel;
|
||||||
int x, y;
|
int x, y;
|
||||||
ImagingColorItem *table;
|
ImagingColorItem *table;
|
||||||
ImagingColorItem *v;
|
ImagingColorItem *v;
|
||||||
|
@ -287,36 +277,27 @@ getcolors32(Imaging im, int maxcolors, int *size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* printf("code_size=%d\n", code_size); */
|
|
||||||
/* printf("code_poly=%d\n", code_poly); */
|
|
||||||
|
|
||||||
if (!code_size) {
|
if (!code_size) {
|
||||||
return ImagingError_MemoryError(); /* just give up */
|
return ImagingError_MemoryError(); /* just give up */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!im->image32) {
|
|
||||||
return ImagingError_ModeError();
|
|
||||||
}
|
|
||||||
|
|
||||||
table = calloc(code_size + 1, sizeof(ImagingColorItem));
|
table = calloc(code_size + 1, sizeof(ImagingColorItem));
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return ImagingError_MemoryError();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_mask = 0xffffffff;
|
|
||||||
if (im->bands == 3) {
|
|
||||||
((UINT8 *)&pixel_mask)[3] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
colors = 0;
|
colors = 0;
|
||||||
|
|
||||||
for (y = 0; y < im->ysize; y++) {
|
for (y = 0; y < im->ysize; y++) {
|
||||||
INT32 *p = im->image32[y];
|
UINT8 *in = (UINT8 *)im->image[y];
|
||||||
for (x = 0; x < im->xsize; x++) {
|
for (x = 0; x < im->xsize; x++, in += im->pixelsize) {
|
||||||
INT32 pixel = p[x] & pixel_mask;
|
pixel = 0;
|
||||||
|
memcpy(&pixel, in, im->pixelsize);
|
||||||
|
|
||||||
h = (pixel); /* null hashing */
|
h = (pixel); /* null hashing */
|
||||||
i = (~h) & code_mask;
|
i = (~h) & code_mask;
|
||||||
v = &table[i];
|
v = &table[i];
|
||||||
|
|
||||||
if (!v->count) {
|
if (!v->count) {
|
||||||
/* add to table */
|
/* add to table */
|
||||||
if (colors++ == maxcolors) {
|
if (colors++ == maxcolors) {
|
||||||
|
@ -363,13 +344,14 @@ getcolors32(Imaging im, int maxcolors, int *size) {
|
||||||
overflow:
|
overflow:
|
||||||
|
|
||||||
/* pack the table */
|
/* pack the table */
|
||||||
for (x = y = 0; x < (int)code_size; x++)
|
for (x = y = 0; x < (int)code_size; x++) {
|
||||||
if (table[x].count) {
|
if (table[x].count) {
|
||||||
if (x != y) {
|
if (x != y) {
|
||||||
table[y] = table[x];
|
table[y] = table[x];
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
table[y].count = 0; /* mark end of table */
|
table[y].count = 0; /* mark end of table */
|
||||||
|
|
||||||
*size = colors;
|
*size = colors;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user