File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -824,7 +824,7 @@ class PipelineWorker : public Napi::AsyncWorker {
824824 ->set (" filter" , baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
825825 ->set (" palette" , baton->pngPalette )
826826 ->set (" Q" , baton->pngQuality )
827- ->set (" bitdepth" , baton->pngBitdepth )
827+ ->set (" bitdepth" , sharp::Is16Bit (image. interpretation ()) ? 16 : baton->pngBitdepth )
828828 ->set (" dither" , baton->pngDither )));
829829 baton->bufferOut = static_cast <char *>(area->data );
830830 baton->bufferOutLength = area->length ;
@@ -993,7 +993,7 @@ class PipelineWorker : public Napi::AsyncWorker {
993993 ->set (" filter" , baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
994994 ->set (" palette" , baton->pngPalette )
995995 ->set (" Q" , baton->pngQuality )
996- ->set (" bitdepth" , baton->pngBitdepth )
996+ ->set (" bitdepth" , sharp::Is16Bit (image. interpretation ()) ? 16 : baton->pngBitdepth )
997997 ->set (" dither" , baton->pngDither ));
998998 baton->formatOut = " png" ;
999999 } else if (baton->formatOut == " webp" || (mightMatchInput && isWebp) ||
Original file line number Diff line number Diff line change @@ -112,6 +112,18 @@ describe('PNG', function () {
112112 } ) ;
113113 } ) ;
114114
115+ it ( '16-bit grey+alpha PNG roundtrip' , async ( ) => {
116+ const after = await sharp ( fixtures . inputPng16BitGreyAlpha )
117+ . toColourspace ( 'grey16' )
118+ . toBuffer ( ) ;
119+
120+ const [ statsBefore , statsAfter ] = await Promise . all ( [
121+ sharp ( fixtures . inputPng16BitGreyAlpha ) . stats ( ) ,
122+ sharp ( after ) . stats ( )
123+ ] ) ;
124+ assert . deepStrictEqual ( statsAfter . channels [ 1 ] , statsBefore . channels [ 1 ] ) ;
125+ } ) ;
126+
115127 it ( 'Valid PNG libimagequant palette value does not throw error' , function ( ) {
116128 assert . doesNotThrow ( function ( ) {
117129 sharp ( ) . png ( { palette : false } ) ;
You can’t perform that action at this time.
0 commit comments