File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ import {pngSignature, crc} from './common';
5
5
const empty = new Uint8Array ( 0 ) ;
6
6
const NULL = '\0' ;
7
7
8
+ const uint16 = new Uint16Array ( [ 0x00ff ] ) ;
9
+ const uint8 = new Uint8Array ( uint16 . buffer ) ;
10
+ const osIsLittleEndian = uint8 [ 0 ] === 0xff ;
11
+
8
12
export default class PNGDecoder extends IOBuffer {
9
13
constructor ( data , options ) {
10
14
super ( data ) ;
@@ -215,9 +219,11 @@ export default class PNGDecoder extends IOBuffer {
215
219
216
220
if ( this . _png . bitDepth === 16 ) {
217
221
const uint16Data = new Uint16Array ( newData . buffer ) ;
218
- for ( var k = 0 ; k < uint16Data . length ; k ++ ) {
219
- // PNG is in big endian. Return to little endian.
220
- uint16Data [ k ] = swap16 ( uint16Data [ k ] ) ;
222
+ if ( osIsLittleEndian ) {
223
+ for ( var k = 0 ; k < uint16Data . length ; k ++ ) {
224
+ // PNG is always big endian. Swap the bytes.
225
+ uint16Data [ k ] = swap16 ( uint16Data [ k ] ) ;
226
+ }
221
227
}
222
228
this . _png . data = uint16Data ;
223
229
} else {
You can’t perform that action at this time.
0 commit comments