Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e96a2ca

Browse files
committed
Only byte-swap 16-bit PNGs on little-endian (#7792)
_png has some code that unconditionally byte-swaps 16-bit PNG data (which is, per the spec, stored in big-endian order). This isn't appropriate on a big-endian platform, though: this swap being done unconditionally breaks the handling of 16-bit PNGs on big-endian platforms (e.g. Fedora ppc64) (#7792). So, let's use some macros numpy kindly defines for us to decide whether to do this swap or not.
1 parent 109251f commit e96a2ca

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/_png.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,12 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
532532
png_set_shift(png_ptr, sig_bit);
533533
}
534534

535+
#if NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
535536
// Convert big endian to little
536537
if (bit_depth == 16) {
537538
png_set_swap(png_ptr);
538539
}
540+
#endif
539541

540542
// Convert palletes to full RGB
541543
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {

0 commit comments

Comments
 (0)