@@ -35,6 +35,7 @@ ZopfliPNGOptions::ZopfliPNGOptions()
3535 , lossy_transparent(false )
3636 , lossy_8bit(false )
3737 , auto_filter_strategy(true )
38+ , keep_colortype(false )
3839 , use_zopfli(true )
3940 , num_iterations(15 )
4041 , num_iterations_large(5 )
@@ -379,7 +380,7 @@ int ZopfliPNGOptimize(const std::vector<unsigned char>& origpng,
379380 lodepng::State inputstate;
380381 error = lodepng::decode (image, w, h, inputstate, origpng);
381382
382- bool keep_colortype = false ;
383+ bool keep_colortype = png_options. keep_colortype ;
383384
384385 if (!png_options.keepchunks .empty ()) {
385386 // If the user wants to keep the non-essential chunks bKGD or sBIT, the
@@ -391,10 +392,12 @@ int ZopfliPNGOptimize(const std::vector<unsigned char>& origpng,
391392 // possible.
392393 std::set<std::string> keepchunks;
393394 ChunksToKeep (origpng, png_options.keepchunks , &keepchunks);
394- keep_colortype = keepchunks.count (" bKGD" ) || keepchunks.count (" sBIT" );
395- if (keep_colortype && verbose) {
396- printf (" Forced to keep original color type due to keeping bKGD or sBIT"
397- " chunk.\n " );
395+ if (keepchunks.count (" bKGD" ) || keepchunks.count (" sBIT" )) {
396+ if (!keep_colortype && verbose) {
397+ printf (" Forced to keep original color type due to keeping bKGD or sBIT"
398+ " chunk.\n " );
399+ }
400+ keep_colortype = true ;
398401 }
399402 }
400403
0 commit comments