mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-15 20:06:28 +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));
|
||||
return ink;
|
||||
case IMAGING_TYPE_SPECIAL:
|
||||
if (im->mode == IMAGING_MODE_I_16
|
||||
|| im->mode == IMAGING_MODE_I_16L
|
||||
|| im->mode == IMAGING_MODE_I_16B
|
||||
|| im->mode == IMAGING_MODE_I_16N
|
||||
) {
|
||||
if (isModeI16(im->mode)) {
|
||||
ink[0] = (UINT8)r;
|
||||
ink[1] = (UINT8)(r >> 8);
|
||||
ink[2] = ink[3] = 0;
|
||||
|
|
|
@ -68,7 +68,7 @@ typedef void (*hline_handler)(Imaging, int, int, int, int);
|
|||
static inline void
|
||||
point8(Imaging im, int x, int y, int ink) {
|
||||
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
|
||||
im->image8[y][x * 2] = (UINT8)(ink >> 8);
|
||||
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;
|
||||
}
|
||||
if (x0 <= x1) {
|
||||
pixelwidth = strncmp(im->mode->name, "I;16", 4) == 0 ? 2 : 1;
|
||||
pixelwidth = isModeI16(im->mode) ? 2 : 1;
|
||||
memset(
|
||||
im->image8[y0] + x0 * pixelwidth, (UINT8)ink, (x1 - x0 + 1) * pixelwidth
|
||||
);
|
||||
|
@ -659,17 +659,17 @@ DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
|
|||
/* Interface */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
#define DRAWINIT() \
|
||||
if (im->image8) { \
|
||||
draw = &draw8; \
|
||||
if (strncmp(im->mode->name, "I;16", 4) == 0) { \
|
||||
ink = INK16(ink_); \
|
||||
} else { \
|
||||
ink = INK8(ink_); \
|
||||
} \
|
||||
} else { \
|
||||
draw = (op) ? &draw32rgba : &draw32; \
|
||||
memcpy(&ink, ink_, sizeof(ink)); \
|
||||
#define DRAWINIT() \
|
||||
if (im->image8) { \
|
||||
draw = &draw8; \
|
||||
if (isModeI16(im->mode)) { \
|
||||
ink = INK16(ink_); \
|
||||
} else { \
|
||||
ink = INK8(ink_); \
|
||||
} \
|
||||
} else { \
|
||||
draw = (op) ? &draw32rgba : &draw32; \
|
||||
memcpy(&ink, ink_, sizeof(ink)); \
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -41,7 +41,7 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) {
|
|||
ImagingSectionEnter(&cookie);
|
||||
|
||||
if (imIn->image8) {
|
||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
||||
if (isModeI16(imIn->mode)) {
|
||||
FLIP_LEFT_RIGHT(UINT16, image8)
|
||||
} else {
|
||||
FLIP_LEFT_RIGHT(UINT8, image8)
|
||||
|
@ -127,7 +127,7 @@ ImagingRotate90(Imaging imOut, Imaging imIn) {
|
|||
ImagingSectionEnter(&cookie);
|
||||
|
||||
if (imIn->image8) {
|
||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
||||
if (isModeI16(imIn->mode)) {
|
||||
ROTATE_90(UINT16, image8);
|
||||
} else {
|
||||
ROTATE_90(UINT8, image8);
|
||||
|
@ -186,7 +186,7 @@ ImagingTranspose(Imaging imOut, Imaging imIn) {
|
|||
ImagingSectionEnter(&cookie);
|
||||
|
||||
if (imIn->image8) {
|
||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
||||
if (isModeI16(imIn->mode)) {
|
||||
TRANSPOSE(UINT16, image8);
|
||||
} else {
|
||||
TRANSPOSE(UINT8, image8);
|
||||
|
@ -247,7 +247,7 @@ ImagingTransverse(Imaging imOut, Imaging imIn) {
|
|||
ImagingSectionEnter(&cookie);
|
||||
|
||||
if (imIn->image8) {
|
||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
||||
if (isModeI16(imIn->mode)) {
|
||||
TRANSVERSE(UINT16, image8);
|
||||
} else {
|
||||
TRANSVERSE(UINT8, image8);
|
||||
|
@ -291,7 +291,7 @@ ImagingRotate180(Imaging imOut, Imaging imIn) {
|
|||
|
||||
yr = imIn->ysize - 1;
|
||||
if (imIn->image8) {
|
||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
||||
if (isModeI16(imIn->mode)) {
|
||||
ROTATE_180(UINT16, image8)
|
||||
} else {
|
||||
ROTATE_180(UINT8, image8)
|
||||
|
@ -351,7 +351,7 @@ ImagingRotate270(Imaging imOut, Imaging imIn) {
|
|||
ImagingSectionEnter(&cookie);
|
||||
|
||||
if (imIn->image8) {
|
||||
if (strncmp(imIn->mode->name, "I;16", 4) == 0) {
|
||||
if (isModeI16(imIn->mode)) {
|
||||
ROTATE_270(UINT16, image8);
|
||||
} else {
|
||||
ROTATE_270(UINT8, image8);
|
||||
|
|
|
@ -152,3 +152,10 @@ const RawMode * findRawMode(const char * const name) {
|
|||
}
|
||||
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);
|
||||
|
||||
|
||||
int isModeI16(const Mode * const mode);
|
||||
|
||||
#endif // __MODE_H__
|
||||
|
|
|
@ -67,8 +67,8 @@ paste_mask_1(
|
|||
int x, y;
|
||||
|
||||
if (imOut->image8) {
|
||||
int in_i16 = strncmp(imIn->mode, "I;16", 4) == 0;
|
||||
int out_i16 = strncmp(imOut->mode, "I;16", 4) == 0;
|
||||
int in_i16 = isModeI16(imIn->mode);
|
||||
int out_i16 = isModeI16(imOut->mode);
|
||||
for (y = 0; y < ysize; y++) {
|
||||
UINT8 *out = imOut->image8[y + dy] + dx;
|
||||
if (out_i16) {
|
||||
|
@ -437,7 +437,7 @@ fill_mask_L(
|
|||
unsigned int tmp1;
|
||||
|
||||
if (imOut->image8) {
|
||||
int i16 = strncmp(imOut->mode, "I;16", 4) == 0;
|
||||
int i16 = isModeI16(imOut->mode);
|
||||
for (y = 0; y < ysize; y++) {
|
||||
UINT8 *out = imOut->image8[y + dy] + dx;
|
||||
if (i16) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user