Recreate card thumbnails wrongly encoded as CMYK JPEG from PNG. Fixes

#1589.
This commit is contained in:
rkfg 2016-03-04 14:59:19 +03:00
parent 0c12998405
commit 63ca80fc86

View file

@ -113,15 +113,15 @@ public class ImageCache {
} }
if (exists) { if (exists) {
LOGGER.debug("loading thumbnail for " + key + ", path=" + thumbnailPath); LOGGER.debug("loading thumbnail for " + key + ", path=" + thumbnailPath);
return loadImage(thumbnailFile); BufferedImage thumbnailImage = loadImage(thumbnailFile);
} else { if (thumbnailImage == null) { // thumbnail exists but broken for some reason
BufferedImage image = loadImage(file); LOGGER.warn("failed loading thumbnail for " + key + ", path=" + thumbnailPath
image = getWizardsCard(image); + ", thumbnail file is probably broken, attempting to recreate it...");
if (image == null) { thumbnailImage = makeThumbnailByFile(key, file, thumbnailPath);
return null;
} }
LOGGER.debug("creating thumbnail for " + key); return thumbnailImage;
return makeThumbnail(image, thumbnailPath); } else {
return makeThumbnailByFile(key, file, thumbnailPath);
} }
} else { } else {
return getWizardsCard(loadImage(file)); return getWizardsCard(loadImage(file));
@ -138,6 +138,16 @@ public class ImageCache {
} }
} }
} }
public BufferedImage makeThumbnailByFile(String key, TFile file, String thumbnailPath) {
BufferedImage image = loadImage(file);
image = getWizardsCard(image);
if (image == null) {
return null;
}
LOGGER.debug("creating thumbnail for " + key);
return makeThumbnail(image, thumbnailPath);
}
}); });
} }
@ -271,7 +281,8 @@ public class ImageCache {
} }
try { try {
try (TFileOutputStream outputStream = new TFileOutputStream(imageFile)) { try (TFileOutputStream outputStream = new TFileOutputStream(imageFile)) {
ImageIO.write(image, "jpg", outputStream); String format = image.getColorModel().getNumComponents() > 3 ? "png" : "jpg";
ImageIO.write(image, format, outputStream);
} }
} catch (IOException e) { } catch (IOException e) {
LOGGER.error(e, e); LOGGER.error(e, e);