This repository was archived by the owner on Apr 12, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -118,23 +118,15 @@ class PNGImage {
118118
119119 let i = p = a = 0 ;
120120 const len = pixels . length ;
121- if ( this . image . bits === 8 ) {
122- while ( i < len ) {
123- for ( let colorIndex = 0 ; colorIndex < colorCount ; colorIndex ++ ) {
124- imgData [ p ++ ] = pixels [ i ++ ] ;
125- }
126- alphaChannel [ a ++ ] = pixels [ i ++ ] ;
127- }
128- } else {
129- // copy only most significant byte (MSB) - PNG data is always stored in network byte order (MSB first)
130- while ( i < len ) {
131- for ( let colorIndex = 0 ; colorIndex < colorCount ; colorIndex ++ ) {
132- imgData [ p ++ ] = pixels [ i ++ ] ;
133- i ++ ;
134- }
135- alphaChannel [ a ++ ] = pixels [ i ++ ] ;
136- i ++ ;
121+ // For 16bit images copy only most significant byte (MSB) - PNG data is always stored in network byte order (MSB first)
122+ const skipByteCount = this . image . bits === 16 ? 1 : 0 ;
123+ while ( i < len ) {
124+ for ( let colorIndex = 0 ; colorIndex < colorCount ; colorIndex ++ ) {
125+ imgData [ p ++ ] = pixels [ i ++ ] ;
126+ i += skipByteCount ;
137127 }
128+ alphaChannel [ a ++ ] = pixels [ i ++ ] ;
129+ i += skipByteCount ;
138130 }
139131
140132 this . imgData = zlib . deflateSync ( imgData ) ;
You can’t perform that action at this time.
0 commit comments