[MGNLIMG-142] Replace removed JPEG classes in Java 7 Created: 04/Dec/14  Updated: 25/Aug/15  Resolved: 19/Jun/15

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

Type: Task Priority: Neutral
Reporter: Federico Grilli Assignee: Espen Jervidalo
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to MGNLIMG-120 Imaging does not compile with Java 7 Closed
relates to MGNLIMG-106 Imaging does not work with JPEG image... Closed
causality
caused by MGNLIMG-61 some images have inverted colors when... Closed
duplicate
duplicates MGNLIMG-66 Re-implement MGNLIMG-61 without com.s... Closed
relation
is related to MGNLIMG-146 Deprecate SunJPEGCodecImageDecoder an... Closed
supersession
supersedes MGNLIMG-66 Re-implement MGNLIMG-61 without com.s... Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Release notes required:
Yes
Date of First Response:
Epic Link: Housekeeping 5.4 CMS

 Description   

Package com.sun.image.codec.jpeg was removed in Java7 but is used by info.magnolia.imaging.operations.load.SunJPEGCodecImageDecoder and info.magnolia.imaging.operations.load.SunJPEGCodecImageDecoderAlt.
The compiled classes in that package are however still provided by the Java JRE in rt.jar (so at runtime one can still use them). In theory one should replace them with Java's ImageIO but as mentioned in a comment at info.magnolia.imaging.util.ImageUtilTest.testDecodingHuffmanImage() that doesn't seem to work very well with some jpegs (also verified personally by running that test and comparing the outputs with the expected result [used java version "1.8.0_25" on a Mac OS X 10.10.1])

not exactly sure what differentiates this jpeg yet - but com.sun.image.codec.jpeg.JPEGImageDecoder handles it correctly for us
while the imageio's built-in jpeg support will only "work" if we pass the image's metadata back to the write (which is not practical since we might want to overlay another image on top for instance)

See also https://blog.idrsolutions.com/2012/05/replacing-the-deprecated-java-jpeg-classes-for-java-7/



 Comments   
Comment by Magnolia International [ 05/Dec/14 ]

In fact, I couldn't reproduce the issue with 1.6.0_37 on my mac either. Nevermind, my test was broken; the problem still exists with 1.8. Committed a patch for the test which now outputs both images (with com.sun decoder and with our imageio default one) to show the difference.

Comment by Magnolia International [ 05/Dec/14 ]

MGNLIMG-61 is the issue where we originally recorded the decoding problems.

Comment by Magnolia International [ 05/Dec/14 ]

... and this has in fact been reported as MGNLIMG-66 already !

Comment by Federico Grilli [ 09/Dec/14 ]

After some research and some unsuccessful attempts at fixing the problem, I found further confirmations about the huffman.jpg issue likely being caused by ImageIO.read(..) returning a BufferedImage without or missing some image metadata (http://stackoverflow.com/questions/9340569/jpeg-image-with-wrong-colors).
It might also be due to some long-standing bugs in Java's ImageIO (which Oracle however claims to have fixed) http://stackoverflow.com/questions/13072312/jpeg-image-color-gets-drastically-changed-after-just-imageio-read-and-imageio?rq=1

At any rate, writing back the metadata is a bit cumbersome given that our API uses BufferedImage (see info.magnolia.imaging.DefaultImageStreamer.write(..)) and one cannot get IIOMetadata from it. Also, as explained in the test comment quoted above in description that "is not practical since we might want to overlay another image on top for instance"

IMO, we have these options
#1 Use http://commons.apache.org/proper/commons-imaging/index.html

  • PRO:
    • its Imaging.getBufferedImage(..) method solves the problem
  • CONTRA:
    • it's still at version 1.0-SNAPSHOT (since 2012) even though the most recent commit is two weeks old

#2 keep the solution using the deprecated com.sun classes relying on the fact that the Oracle Java runtime still provides them
#3 use a ImageIO plugin such as TwelveMonkeys even though it looks like it has some issues in a webapp https://github.com/haraldk/TwelveMonkeys#deploying-the-plugins-in-a-web-app
#4 try to fix it ourselves

Comment by Federico Grilli [ 10/Dec/14 ]

I went for the apache commons-imaging http://commons.apache.org/proper/commons-imaging/ solution even though this means we need to cut our own final release from trunk (e.g. from https://apache.googlesource.com/commons-imaging/) as long as Apache doesn't do that.

1.0-SNAPSHOT appears to be stable and used in production by many people anyway (http://mail-archives.apache.org/mod_mbox/commons-dev/201311.mbox/%3CCACZkXPxuQcLrTBnLpP36OfT-FGRBigUFjPZyE+_HfVWxyRAgcA@mail.gmail.com%3E)

As a side note Apache Imaging was previously known as Apache Sanselan whose latest stable release is 0.97 (in 2012 I believe). Unfortunately we cannot use it as it doesn't support JPEG format.

Comment by Federico Grilli [ 10/Dec/14 ]

For the release notes: info.magnolia.imaging.operations.load.SunJPEGCodecImageDecoder and info.magnolia.imaging.operations.load.SunJPEGCodecImageDecoderAlt are removed in 3.2 and replaced with info.magnolia.imaging.operations.load.CommonsImagingImageDecoder

Comment by Christoph Meier [ 21/Jan/15 ]

Since we recommend running the Magnolia 5.3.x versions on Java 6, backporting this replacement to MGNLIMG 3.1.3 is not necessary.
That's why i removed the 3.1.3 fix-version

Comment by Magnolia International [ 09/Mar/15 ]

The fixes for this are on master, but there is still a comment in the pom that says "Until http://jira.magnolia-cms.com/browse/MGNLIMG-142 is integrated we have to [...]"; either the comment needs to go, be updated, or what it comments on needs to go

Comment by Federico Grilli [ 10/Mar/15 ]

Hmm, afaics the fixes I did and which should allow us to get rid of those Sun proprietary class are on the MGNLIMG-142 branch, so I guess that comment is valid until we actually integrate it

Comment by Magnolia International [ 10/Mar/15 ]

Agh, my bad, I thought it had been reviewed and merged already ! So if I read history correctly, this is still pending review, right ?

Comment by Federico Grilli [ 10/Mar/15 ]

Yup

Comment by Espen Jervidalo [ 12/Mar/15 ]

via http://stackoverflow.com/a/16149142 I found this:
https://github.com/haraldk/TwelveMonkeys

"TwelveMonkeys ImageIO is a collection of plug-ins for Java's ImageIO.

These plugins extends the number of image file formats supported in Java, using the javax.imageio.* package. The main purpose of this project is to provide support for formats not covered by the JDK itself. [...]"

Before starting to maintain our own releases of apache-imaging, I would really like to consider using these plugins.

Stable and up-to-date releases is one big plus, compared to that more or less dead apache project.

EDIT: Sorry, missed Federico's comment from 9. November.
Here's a suggestion from Greg: "Make it a module. Then do whatever that listnr does in module lifecycle. If it's just scan for plugins then do it in main imging module"

Comment by Philip Mundt [ 19/Jun/15 ]
  • Please deprecate info.magnolia.imaging.operations.load.SunJPEGCodecImageDecoder (*Alt) or provide MVH for update.
  • Also get rid of additional compiler flag -XDignore.symbol.file in pom of magnolia-module-imaging if possible
Generated at Mon Feb 12 02:12:42 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.