mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-16 04:16:35 +03:00
add function isModeI16() to check if a mode is an I;16 mode
This commit is contained in:
parent
e598741876
commit
cf4a42f1a0
|
@ -580,11 +580,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
memcpy(ink, &ftmp, sizeof(ftmp));
|
memcpy(ink, &ftmp, sizeof(ftmp));
|
||||||
return ink;
|
return ink;
|
||||||
case IMAGING_TYPE_SPECIAL:
|
case IMAGING_TYPE_SPECIAL:
|
||||||
if (im->mode == IMAGING_MODE_I_16
|
if (isModeI16(im->mode)) {
|
||||||
|| im->mode == IMAGING_MODE_I_16L
|
|
||||||
|| im->mode == IMAGING_MODE_I_16B
|
|
||||||
|| im->mode == IMAGING_MODE_I_16N
|
|
||||||
) {
|
|
||||||
ink[0] = (UINT8)r;
|
ink[0] = (UINT8)r;
|
||||||
ink[1] = (UINT8)(r >> 8);
|
ink[1] = (UINT8)(r >> 8);
|
||||||
ink[2] = ink[3] = 0;
|
ink[2] = ink[3] = 0;
|
||||||
|
|
|
@ -68,7 +68,7 @@ typedef void (*hline_handler)(Imaging, int, int, int, int);
|
||||||
static inline void
|
static inline void
|
||||||
point8(Imaging im, int x, int y, int ink) {
|
point8(Imaging im, int x, int y, int ink) {
|
||||||
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
|
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
|
||||||
if (strncmp(im->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(im->mode)) {
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
im->image8[y][x * 2] = (UINT8)(ink >> 8);
|
im->image8[y][x * 2] = (UINT8)(ink >> 8);
|
||||||
im->image8[y][x * 2 + 1] = (UINT8)ink;
|
im->image8[y][x * 2 + 1] = (UINT8)ink;
|
||||||
|
@ -118,7 +118,7 @@ hline8(Imaging im, int x0, int y0, int x1, int ink) {
|
||||||
x1 = im->xsize - 1;
|
x1 = im->xsize - 1;
|
||||||
}
|
}
|
||||||
if (x0 <= x1) {
|
if (x0 <= x1) {
|
||||||
pixelwidth = strncmp(im->mode->name, "I;16", 4) == 0 ? 2 : 1;
|
pixelwidth = isModeI16(im->mode) ? 2 : 1;
|
||||||
memset(
|
memset(
|
||||||
im->image8[y0] + x0 * pixelwidth, (UINT8)ink, (x1 - x0 + 1) * pixelwidth
|
im->image8[y0] + x0 * pixelwidth, (UINT8)ink, (x1 - x0 + 1) * pixelwidth
|
||||||
);
|
);
|
||||||
|
@ -659,17 +659,17 @@ DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
|
||||||
/* Interface */
|
/* Interface */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define DRAWINIT() \
|
#define DRAWINIT() \
|
||||||
if (im->image8) { \
|
if (im->image8) { \
|
||||||
draw = &draw8; \
|
draw = &draw8; \
|
||||||
if (strncmp(im->mode->name, "I;16", 4) == 0) { \
|
if (isModeI16(im->mode)) { \
|
||||||
ink = INK16(ink_); \
|
ink = INK16(ink_); \
|
||||||
} else { \
|
} else { \
|
||||||
ink = INK8(ink_); \
|
ink = INK8(ink_); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
draw = (op) ? &draw32rgba : &draw32; \
|
draw = (op) ? &draw32rgba : &draw32; \
|
||||||
memcpy(&ink, ink_, sizeof(ink)); \
|
memcpy(&ink, ink_, sizeof(ink)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -41,7 +41,7 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(imIn->mode)) {
|
||||||
FLIP_LEFT_RIGHT(UINT16, image8)
|
FLIP_LEFT_RIGHT(UINT16, image8)
|
||||||
} else {
|
} else {
|
||||||
FLIP_LEFT_RIGHT(UINT8, image8)
|
FLIP_LEFT_RIGHT(UINT8, image8)
|
||||||
|
@ -127,7 +127,7 @@ ImagingRotate90(Imaging imOut, Imaging imIn) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(imIn->mode)) {
|
||||||
ROTATE_90(UINT16, image8);
|
ROTATE_90(UINT16, image8);
|
||||||
} else {
|
} else {
|
||||||
ROTATE_90(UINT8, image8);
|
ROTATE_90(UINT8, image8);
|
||||||
|
@ -186,7 +186,7 @@ ImagingTranspose(Imaging imOut, Imaging imIn) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(imIn->mode)) {
|
||||||
TRANSPOSE(UINT16, image8);
|
TRANSPOSE(UINT16, image8);
|
||||||
} else {
|
} else {
|
||||||
TRANSPOSE(UINT8, image8);
|
TRANSPOSE(UINT8, image8);
|
||||||
|
@ -247,7 +247,7 @@ ImagingTransverse(Imaging imOut, Imaging imIn) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(imIn->mode)) {
|
||||||
TRANSVERSE(UINT16, image8);
|
TRANSVERSE(UINT16, image8);
|
||||||
} else {
|
} else {
|
||||||
TRANSVERSE(UINT8, image8);
|
TRANSVERSE(UINT8, image8);
|
||||||
|
@ -291,7 +291,7 @@ ImagingRotate180(Imaging imOut, Imaging imIn) {
|
||||||
|
|
||||||
yr = imIn->ysize - 1;
|
yr = imIn->ysize - 1;
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(imIn->mode)) {
|
||||||
ROTATE_180(UINT16, image8)
|
ROTATE_180(UINT16, image8)
|
||||||
} else {
|
} else {
|
||||||
ROTATE_180(UINT8, image8)
|
ROTATE_180(UINT8, image8)
|
||||||
|
@ -351,7 +351,7 @@ ImagingRotate270(Imaging imOut, Imaging imIn) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
if (isModeI16(imIn->mode)) {
|
||||||
ROTATE_270(UINT16, image8);
|
ROTATE_270(UINT16, image8);
|
||||||
} else {
|
} else {
|
||||||
ROTATE_270(UINT8, image8);
|
ROTATE_270(UINT8, image8);
|
||||||
|
|
|
@ -152,3 +152,10 @@ const RawMode * findRawMode(const char * const name) {
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int isModeI16(const Mode * const mode) {
|
||||||
|
return mode == IMAGING_MODE_I_16
|
||||||
|
|| mode == IMAGING_MODE_I_16L
|
||||||
|
|| mode == IMAGING_MODE_I_16B
|
||||||
|
|| mode == IMAGING_MODE_I_16N;
|
||||||
|
}
|
||||||
|
|
|
@ -86,4 +86,6 @@ extern const RawMode * const IMAGING_RAWMODE_YCbCrK;
|
||||||
const RawMode * findRawMode(const char * const name);
|
const RawMode * findRawMode(const char * const name);
|
||||||
|
|
||||||
|
|
||||||
|
int isModeI16(const Mode * const mode);
|
||||||
|
|
||||||
#endif // __MODE_H__
|
#endif // __MODE_H__
|
||||||
|
|
|
@ -67,8 +67,8 @@ paste_mask_1(
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (imOut->image8) {
|
if (imOut->image8) {
|
||||||
int in_i16 = strncmp(imIn->mode, "I;16", 4) == 0;
|
int in_i16 = isModeI16(imIn->mode);
|
||||||
int out_i16 = strncmp(imOut->mode, "I;16", 4) == 0;
|
int out_i16 = isModeI16(imOut->mode);
|
||||||
for (y = 0; y < ysize; y++) {
|
for (y = 0; y < ysize; y++) {
|
||||||
UINT8 *out = imOut->image8[y + dy] + dx;
|
UINT8 *out = imOut->image8[y + dy] + dx;
|
||||||
if (out_i16) {
|
if (out_i16) {
|
||||||
|
@ -437,7 +437,7 @@ fill_mask_L(
|
||||||
unsigned int tmp1;
|
unsigned int tmp1;
|
||||||
|
|
||||||
if (imOut->image8) {
|
if (imOut->image8) {
|
||||||
int i16 = strncmp(imOut->mode, "I;16", 4) == 0;
|
int i16 = isModeI16(imOut->mode);
|
||||||
for (y = 0; y < ysize; y++) {
|
for (y = 0; y < ysize; y++) {
|
||||||
UINT8 *out = imOut->image8[y + dy] + dx;
|
UINT8 *out = imOut->image8[y + dy] + dx;
|
||||||
if (i16) {
|
if (i16) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
|
||||||
if (stride <= 0) {
|
if (stride <= 0) {
|
||||||
if (!strcmp(mode, "L") || !strcmp(mode, "P")) {
|
if (!strcmp(mode, "L") || !strcmp(mode, "P")) {
|
||||||
stride = xsize;
|
stride = xsize;
|
||||||
} else if (!strncmp(mode, "I;16", 4)) {
|
} else if (isModeI16(mode)) {
|
||||||
stride = xsize * 2;
|
stride = xsize * 2;
|
||||||
} else {
|
} else {
|
||||||
stride = xsize * 4;
|
stride = xsize * 4;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user