Skip to content

Commit

Permalink
codec: continue when compression level cannot be set in ImageIO writer
Browse files Browse the repository at this point in the history
Java 8 does not support setting the compression quality.
  • Loading branch information
carlosame committed Jul 24, 2024
1 parent 97660fb commit eac7e7a
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,17 @@ protected ImageWriteParam getDefaultWriteParam(ImageWriter iiowriter, RenderedIm
*/
String comprMethod = params.getCompressionMethod();
Integer level = params.getCompressionLevel();
if (level != null) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(comprMethod != null ? comprMethod : "Deflate");
int lvl = level.intValue();
if (lvl >= 0 && lvl < 10) {
int lvl;
if (level != null && (lvl = level.intValue()) >= 0 && lvl < 10) {
try {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(comprMethod != null ? comprMethod : "Deflate");
// ImageIO sets the compression level from a quality in the 0-1 range...
float quality = 1f - lvl / 9f;
param.setCompressionQuality(quality);
} catch (UnsupportedOperationException e) {
// The inability to set a compression level isn't a critical failure
e.printStackTrace();
}
} else if (comprMethod != null) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
Expand Down

0 comments on commit eac7e7a

Please sign in to comment.