[MGNLDAM-85] Displaying a png image fails in some case Created: 16/Jan/13  Updated: 11/Feb/13  Resolved: 24/Jan/13

Status: Closed
Project: Magnolia DAM Module
Component/s: None
Affects Version/s: 1.0
Fix Version/s: 1.0

Type: Bug Priority: Critical
Reporter: Eric Hechinger Assignee: Christopher Zimmermann
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
causality
caused by MGNLIMG-38 outputting into jpg format fails if p... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

For some png (dam/demo-project/img/logo/magnolia-logo), we have the following exception when displaying an Image.
This is related to the following resolved issue MGNLIMG-38.

From ImageUtil.class

final boolean isOpaque = img.getTransparency() == Transparency.OPAQUE;

if (!isOpaque && !outputFormat.supportsTransparency()) {
final WritableRaster raster = img.getRaster();
final WritableRaster newRaster = raster.createWritableChild(0, 0, img.getWidth(), img.getHeight(), 0, 0, new int[]

{0, 1, 2}

);

// create a ColorModel that represents the one of the ARGB except the alpha channel
final DirectColorModel cm = (DirectColorModel) img.getColorModel();

The image isOpack = false && supportsTransparency = false --> jump in the if statement.
Issue is that this cast is failing: (DirectColorModel) img.getColorModel()
img.getColoredModel() --> type ComponentColorModel
and ComponentColorModel is not a sub class of DirectColorModel.

-------------------------
Caused by: java.lang.ClassCastException: java.awt.image.ComponentColorModel cannot be cast to java.awt.image.DirectColorModel
at info.magnolia.imaging.util.ImageUtil.flattenTransparentImageForOpaqueFormat(ImageUtil.java:68)
at info.magnolia.imaging.DefaultImageStreamer.serveImage(DefaultImageStreamer.java:68)
at info.magnolia.imaging.caching.CachingImageStreamer.generateAndStore(CachingImageStreamer.java:197)
at info.magnolia.imaging.caching.CachingImageStreamer$1.apply(CachingImageStreamer.java:118)
at info.magnolia.imaging.caching.CachingImageStreamer$1.apply(CachingImageStreamer.java:114)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:355)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153)
at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:393)
at info.magnolia.imaging.caching.CachingImageStreamer.serveImage(CachingImageStreamer.java:136)
... 82 more



 Comments   
Comment by Eric Hechinger [ 16/Jan/13 ]

Works fine with 4.5.x.

Comment by Christopher Zimmermann [ 23/Jan/13 ]

Changed ImageUtil.flattenTransparentImageForOpaqueFormat to fallback to fillTransparentPixels if there is a problem with color model conversion.
Outputs a WARN to the log if the slower fillTransparentPixels has to be used.

Added a testcase for the magnolia_logo.png which was causing the problem.

Comment by Daniel Lipp [ 23/Jan/13 ]

We should not rely on exceptions for control flow. Looks like a could easily check the type before doing the cast and hence avoid the ClassCastException.

Comment by Christopher Zimmermann [ 24/Jan/13 ]

ImageUtil.flattenTransparentImageForOpaqueFormat() was failing for images with ComponentColorModel. It has been improved to check for images with ComponentColorModel and to fallback on a slower routine when they are detected.

Comment by Christopher Zimmermann [ 24/Jan/13 ]

Fixed by improving ImageUtil.flattenTransparentImageForOpaqueFormat in MGNLIMG-38.
(Now checks for ComponentColorModel explicitly instead of catching exception.)

Generated at Mon Feb 12 04:56:24 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.