[MGNLIMG-183] GIF images generated with poor quality Created: 10/Feb/16  Updated: 04/Jul/16  Resolved: 28/Mar/16

Status: Closed
Project: Imaging
Component/s: None
Affects Version/s: 3.2.4
Fix Version/s: 3.2.6

Type: Bug Priority: Neutral
Reporter: Richard Gange Assignee: Hieu Nguyen Duc
Resolution: Fixed Votes: 0
Labels: support
Remaining Estimate: 0d
Time Spent: 8d 0.75h
Original Estimate: 0.75d

Attachments: GIF File example-proccessed.gif     GIF File example.gif     GIF File pinkHeart.gif     GIF File pinkHeartAfterProcessed.gif    
Issue Links:
relation
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:
Sprint: Saigon 37
Story Points: 8

 Description   

GIF images going through the imaging module come out distorted.

Steps to reproduce

Upload the "example.gif" image using Asset app.

Solution

Handle input images whose size is 1-4 bits per pixel.

info.magnolia.imaging.util.ImageUtil

public static int getImageType(BufferedImage img) {
    int imageType = img.getType();
    switch (imageType) {
        case BufferedImage.TYPE_CUSTOM: // If the source image type is not set...
            imageType = img.getAlphaRaster() != null ? BufferedImage.TYPE_INT_ARGB_PRE : BufferedImage.TYPE_INT_RGB;
            break;
        // Handle both TYPE_BYTE_BINARY (1-4 bit/pixel) and TYPE_BYTE_INDEXED (8 bit/pixel).
        case BufferedImage.TYPE_BYTE_BINARY:
        case BufferedImage.TYPE_BYTE_INDEXED:
            if (img.getColorModel() != null) {
                imageType = img.getColorModel().hasAlpha() ? BufferedImage.TYPE_INT_ARGB_PRE : BufferedImage.TYPE_INT_RGB;
            }
            break;
        default:
            break;
    }
    return imageType;
}


 Comments   
Comment by Ngoc Nguyenthanh [ 07/Mar/16 ]

I believe that the issue come info.magnolia.imaging.operations.load.DefaultImageIOImageDecoder due to ImageIO is not well supported for gif file.

What happened?
  • First the image usually loaded from the JCR by using imaging operation info.magnolia.imaging.operations.load.FromBinaryNode or deprecated API info.magnolia.imaging.operations.load.FromNodeData.
  • When imaging operation load the image, it try to convert the image into appropriate image type.
  • Unfortunately the ImageIO is not well supported for gif and then it return an image with wrong image type from ImageDecoder.
            int imageType = ImageUtil.getImageType(loaded);
            final BufferedImage img = new BufferedImage(loaded.getWidth(), loaded.getHeight(), imageType);
    
Potential solutions
  • Solution 1: check if the image is a gif. Then try to force the imageType to appropriate image type. For example
            if (loaded.getColorModel().hasAlpha()) {
                imageType = BufferedImage.TYPE_INT_ARGB;
            } else {
                imageType = BufferedImage.TYPE_INT_RGB;
            }
    
  • Solution 2: Replace ImageIO with better image processing library. I give a try with commons-imaging which have no stable version and seem like not developed anymore. But it fail in some cases.
Comment by Mikaël Geljić [ 31/Mar/16 ]

Thank you guys for work, regular status and options I didn't react on that earlier, but:

  • In the context of maintenance, option #2 made a lot more sense: minimizing side-effects
  • Apart from that, I would dare to claim that imaging module is considered pretty solid and stable
    • Obviously, it would have taken a lot more effort (time, testing, QA), had we wanted to replace the backing library
    • Good you found those test image suites; manual testing was enough for this issue I would say (maybe a bit unpleasant though);
    • If we were to face such recurring issues in the future, we could eventually invest time into automating that

I agree definition of done was hard to assess for this case; it could vary greatly between the two approaches.

I just inform that we have a bug of ImageIO.read() because it can't read low quality images. This is reported as an API bug of ImageIO and it will be fixed in Java 9.
http://stackoverflow.com/questions/36257318/imageio-read-cant-read-some-images

Thanks for mentioning that related pending ImageIO issue too.

Generated at Mon Feb 12 02:13:06 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.