Skip to content

Commit 838a442

Browse files
committed
handle I;16 native endianness on big-endian machine
1 parent 7317e58 commit 838a442

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/_imaging.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,22 @@ if (PySequence_Check(op)) { \
15711571
PyErr_SetString(PyExc_TypeError, must_be_sequence);
15721572
return NULL;
15731573
}
1574-
int endian = strncmp(image->mode, "I;16", 4) == 0 ? (strcmp(image->mode, "I;16B") == 0 ? 2 : 1) : 0;
1574+
// 0 = none, 1 = little, 2 = big
1575+
int endian = 0;
1576+
if (strncmp(image->mode, "I;16", 4) == 0) {
1577+
if (strcmp(image->mode, "I;16") == 0 || strcmp(image->mode, "I;16L") == 0) {
1578+
endian = 1;
1579+
} else if (strcmp(image->mode, "I;16B") == 0) {
1580+
endian = 2;
1581+
} else {
1582+
// native endianness
1583+
#ifdef WORDS_BIGENDIAN
1584+
endian = 2;
1585+
#else
1586+
endian = 1;
1587+
#endif
1588+
}
1589+
}
15751590
double value;
15761591
for (i = x = y = 0; i < n; i++) {
15771592
set_value_to_item(seq, i);

0 commit comments

Comments
 (0)