Giter VIP home page Giter VIP logo

twelvemonkeys's Introduction

CI CodeQL OpenSSF Scorecard OpenSSF Best Practices

Maven Central Maven Snapshot StackOverflow Donate

Logo

About

TwelveMonkeys ImageIO provides extended image file format support for the Java platform, through plugins for the javax.imageio.* package.

The main goal of this project is to provide support for formats not covered by the JRE itself. Support for these formats is important, to be able to read data found "in the wild", as well as to maintain access to data in legacy formats. As there is lots of legacy data out there, we see the need for open implementations of readers for popular formats.


File formats supported

Plugin Format Description R W Metadata Notes
Batik SVG Scalable Vector Graphics - - Requires Batik
WMF MS Windows Metafile - - Requires Batik
BMP BMP MS Windows and IBM OS/2 Device Independent Bitmap Native, Standard
CUR MS Windows Cursor Format - -
ICO MS Windows Icon Format -
HDR HDR Radiance High Dynamic Range RGBE Format - Standard
ICNS ICNS Apple Icon Image -
IFF IFF Commodore Amiga/Electronic Arts Interchange File Format Standard
JPEG JPEG Joint Photographers Expert Group Native, Standard
JPEG Lossless - Native, Standard
PCX PCX ZSoft Paintbrush Format - Standard
DCX Multi-page PCX fax document - Standard
PICT PICT Apple QuickTime Picture Format Standard
PNTG Apple MacPaint Picture Format - Standard
PNM PAM NetPBM Portable Any Map Standard
PBM NetPBM Portable Bit Map - Standard
PGM NetPBM Portable Grey Map - Standard
PPM NetPBM Portable Pix Map Standard
PFM Portable Float Map - Standard
PSD PSD Adobe Photoshop Document (✔) Native, Standard
PSB Adobe Photoshop Large Document - Native, Standard
SGI SGI Silicon Graphics Image Format - Standard
TGA TGA Truevision TGA Image Format Standard
ThumbsDB Thumbs.db MS Windows Thumbs DB - - OLE2 Compound Document based format only
TIFF TIFF Aldus/Adobe Tagged Image File Format Native, Standard
BigTIFF Native, Standard
WebP WebP Google WebP Format - Standard
XWD XWD X11 Window Dump Format - Standard

Important note on using Batik: Please read The Apache™ XML Graphics Project - Security, and make sure you use an updated and secure version.

Note that GIF, PNG and WBMP formats are already supported through the ImageIO API, using the JDK standard plugins. For BMP, JPEG, and TIFF formats the TwelveMonkeys plugins provides extended format support and additional features.

Basic usage

Most of the time, all you need to do is simply include the plugins in your project and write:

BufferedImage image = ImageIO.read(file);

This will load the first image of the file, entirely into memory.

The basic and simplest form of writing is:

if (!ImageIO.write(image, format, file)) {
   // Handle image not written case
}

This will write the entire image into a single file, using the default settings for the given format.

The plugins are discovered automatically at run time. See the FAQ for more info on how this mechanism works.

Advanced usage

If you need more control of read parameters and the reading process, the common idiom for reading is something like:

// Create input stream (in try-with-resource block to avoid leaks)
try (ImageInputStream input = ImageIO.createImageInputStream(file)) {
    // Get the reader
    Iterator<ImageReader> readers = ImageIO.getImageReaders(input);

    if (!readers.hasNext()) {
        throw new IllegalArgumentException("No reader for: " + file);
    }

    ImageReader reader = readers.next();

    try {
        reader.setInput(input);

        // Optionally, listen for read warnings, progress, etc.
        reader.addIIOReadWarningListener(...);
        reader.addIIOReadProgressListener(...);

        ImageReadParam param = reader.getDefaultReadParam();

        // Optionally, control read settings like sub sampling, source region or destination etc.
        param.setSourceSubsampling(...);
        param.setSourceRegion(...);
        param.setDestination(...);
        // ...

        // Finally read the image, using settings from param
        BufferedImage image = reader.read(0, param);

        // Optionally, read thumbnails, meta data, etc...
        int numThumbs = reader.getNumThumbnails(0);
        // ...
    }
    finally {
        // Dispose reader in finally block to avoid memory leaks
        reader.dispose();
    }
}

Query the reader for source image dimensions using reader.getWidth(n) and reader.getHeight(n) without reading the entire image into memory first.

It's also possible to read multiple images from the same file in a loop, using reader.getNumImages().

If you need more control of write parameters and the writing process, the common idiom for writing is something like:

// Get the writer
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(format);

if (!writers.hasNext()) {
    throw new IllegalArgumentException("No writer for: " + format);
}

ImageWriter writer = writers.next();

try {
    // Create output stream (in try-with-resource block to avoid leaks)
    try (ImageOutputStream output = ImageIO.createImageOutputStream(file)) {
        writer.setOutput(output);

        // Optionally, listen to progress, warnings, etc.

        ImageWriteParam param = writer.getDefaultWriteParam();

        // Optionally, control format specific settings of param (requires casting), or
        // control generic write settings like sub sampling, source region, output type etc.

        // Optionally, provide thumbnails and image/stream metadata
        writer.write(..., new IIOImage(..., image, ...), param);
    }
}
finally {
    // Dispose writer in finally block to avoid memory leaks
    writer.dispose();
}

For more advanced usage, and information on how to use the ImageIO API, I suggest you read the Java Image I/O API Guide from Oracle.

Adobe Clipping Path support

import com.twelvemonkeys.imageio.path.Paths;

...

try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
    BufferedImage image = Paths.readClipped(stream);

    // Do something with the clipped image...
}

See Adobe Clipping Path support on the Wiki for more details and example code.

Using the ResampleOp

The library comes with a resampling (image resizing) operation, that contains many different algorithms to provide excellent results at reasonable speed.

import com.twelvemonkeys.image.ResampleOp;

...

BufferedImage input = ...; // Image to resample
int width, height = ...; // new width/height

BufferedImageOp resampler = new ResampleOp(width, height, ResampleOp.FILTER_LANCZOS); // A good default filter, see class documentation for more info
BufferedImage output = resampler.filter(input, null);

Using the DiffusionDither

The library comes with a dithering operation, that can be used to convert BufferedImages to IndexColorModel using Floyd-Steinberg error-diffusion dither.

import com.twelvemonkeys.image.DiffusionDither;

...

BufferedImage input = ...; // Image to dither

BufferedImageOp ditherer = new DiffusionDither();
BufferedImage output = ditherer.filter(input, null);

Building

Download the project (using Git):

$ git clone [email protected]:haraldk/TwelveMonkeys.git

This should create a folder named TwelveMonkeys in your current directory. Change directory to the TwelveMonkeys folder, and issue the command below to build.

Build the project (using Maven):

$ mvn package

Currently, the recommended JDK for making a build is Oracle JDK 8.x.

It's possible to build using OpenJDK, but some tests might fail due to some minor differences between the color management systems used. You will need to either disable the tests in question, or build without tests altogether.

Because the unit tests needs quite a bit of memory to run, you might have to set the environment variable MAVEN_OPTS to give the Java process that runs Maven more memory. I suggest something like -Xmx512m -XX:MaxPermSize=256m.

Optionally, you can install the project in your local Maven repository using:

$ mvn install

Installing

To install the plug-ins, either use Maven and add the necessary dependencies to your project, or manually add the needed JARs along with required dependencies in class-path.

The ImageIO registry and service lookup mechanism will make sure the plugins are available for use.

To verify that the JPEG plugin is installed and used at run-time, you could use the following code:

Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
while (readers.hasNext()) {
    System.out.println("reader: " + readers.next());
}

The first line should print:

reader: com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader@somehash

Maven dependency example

To depend on the JPEG and TIFF plugin using Maven, add the following to your POM:

...
<dependencies>
    ...
    <dependency>
        <groupId>com.twelvemonkeys.imageio</groupId>
        <artifactId>imageio-jpeg</artifactId>
        <version>3.10.1</version>
    </dependency>
    <dependency>
        <groupId>com.twelvemonkeys.imageio</groupId>
        <artifactId>imageio-tiff</artifactId>
        <version>3.10.1</version>
    </dependency>

    <!--
    Optional dependency. Needed only if you deploy ImageIO plugins as part of a web app.
    Make sure you add the IIOProviderContextListener to your web.xml, see above.
    -->
    <dependency>
        <groupId>com.twelvemonkeys.servlet</groupId>
        <artifactId>servlet</artifactId>
        <version>3.10.1</version>
    </dependency>

    <!--
    Or Jakarta version, for Servlet API 5.0
    -->
    <dependency>
        <groupId>com.twelvemonkeys.servlet</groupId>
        <artifactId>servlet</artifactId>
        <version>3.10.1</version>
        <classifier>jakarta</classifier>
    </dependency>
</dependencies>

Manual dependency example

To depend on the JPEG and TIFF plugin in your IDE or program, add all of the following JARs to your class path:

twelvemonkeys-common-lang-3.10.1.jar
twelvemonkeys-common-io-3.10.1.jar
twelvemonkeys-common-image-3.10.1.jar
twelvemonkeys-imageio-core-3.10.1.jar
twelvemonkeys-imageio-metadata-3.10.1.jar
twelvemonkeys-imageio-jpeg-3.10.1.jar
twelvemonkeys-imageio-tiff-3.10.1.jar

Deploying the plugins in a web app

Because the ImageIO plugin registry (the IIORegistry) is "VM global", it does not work well with servlet contexts as-is. This is especially evident if you load plugins from the WEB-INF/lib or classes folder. Unless you add ImageIO.scanForPlugins() somewhere in your code, the plugins might never be available at all.

In addition, servlet contexts dynamically loads and unloads classes (using a new class loader per context). If you restart your application, old classes will by default remain in memory forever (because the next time scanForPlugins is called, it's another ClassLoader that scans/loads classes, and thus they will be new instances in the registry). If a read is attempted using one of the remaining "old" readers, weird exceptions (like NullPointerExceptions when accessing static final initialized fields or NoClassDefFoundErrors for uninitialized inner classes) may occur.

To work around both the discovery problem and the resource leak, it is strongly recommended to use the IIOProviderContextListener that implements dynamic loading and unloading of ImageIO plugins for web applications.

<web-app ...>

...

    <listener>
        <display-name>ImageIO service provider loader/unloader</display-name>
        <listener-class>com.twelvemonkeys.servlet.image.IIOProviderContextListener</listener-class>
    </listener>

...

</web-app>

Loading plugins from WEB-INF/lib without the context listener installed is unsupported and will not work correctly.

The context listener has no dependencies to the TwelveMonkeys ImageIO plugins, and may be used with JAI ImageIO or other ImageIO plugins as well.

Another safe option, is to place the JAR files in the application server's shared or common lib folder.

Jakarta Servlet Support

For those transitioning from the old javax.servlet to the new jakarta.servlet package, there is a separate dependency available. It contains exactly the same servlet classes as mentioned above, but built against the new Jakarta EE packages. The dependency has the same group name and identifier as before, but a jakarta classifier appended, to distinguish it from the non-Jakarta package.

See the Maven dependency example for how to enable it with Maven. Gradle or other build tools will have similar options.

Including the plugins in a "fat" JAR

The recommended way to use the plugins, is just to include the JARs as-is in your project, through a Maven dependency or similar. Re-packaging is not necessary to use the library, and not recommended.

However, if you like to create a "fat" JAR, or otherwise like to re-package the JARs for some reason, it's important to remember that automatic discovery of the plugins by ImageIO depends on the Service Provider Interface (SPI) mechanism. In short, each JAR contains a special folder, named META-INF/services containing one or more files, typically javax.imageio.spi.ImageReaderSpi and javax.imageio.spi.ImageWriterSpi. These files exist with the same name in every JAR, so if you simply unpack everything to a single folder or create a JAR, files will be overwritten and behavior be unspecified (most likely you will end up with a single plugin being installed).

The solution is to make sure all files with the same name, are merged to a single file, containing all the SPI information of each type. If using the Maven Shade plugin, you should use the ServicesResourceTransformer to properly merge these files. You may also want to use the ManifestResourceTransforme to get the correct vendor name, version info etc. Other "fat" JAR bundlers will probably have similar mechanisms to merge entries with the same name.

Links to prebuilt binaries

Latest version (3.10.1)

The latest version that will run on Java 7 is 3.9.4. Later versions will require Java 8 or later.

Common dependencies

ImageIO dependencies

ImageIO plugins

ImageIO plugins requiring 3rd party libs

Photoshop Path support for ImageIO

Servlet support

License

This project is provided under the OSI approved BSD license:

Copyright (c) 2008-2022, Harald Kuhr
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

o Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

o Neither the name of the copyright holder nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

FAQ

q: How do I use it?

a: The easiest way is to build your own project using Maven, Gradle or other build tool with dependency management, and just add dependencies to the specific plug-ins you need. If you don't use such a build tool, make sure you have all the necessary JARs in classpath. See the Install section above.

q: What changes do I have to make to my code in order to use the plug-ins?

a: The short answer is: None. For basic usage, like ImageIO.read(...) or ImageIO.getImageReaders(...), there is no need to change your code. Most of the functionality is available through standard ImageIO APIs, and great care has been taken not to introduce extra API where none is necessary.

Should you want to use very specific/advanced features of some of the formats, you might have to use specific APIs, like setting base URL for an SVG image that consists of multiple files, or controlling the output compression of a TIFF file.

q: How does it work?

a: The TwelveMonkeys ImageIO project contains plug-ins for ImageIO. ImageIO uses a service lookup mechanism, to discover plug-ins at runtime.

All you have to do, is to make sure you have the TwelveMonkeys ImageIO JARs in your classpath.

You can read more about the registry and the lookup mechanism in the IIORegistry API doc.

The fine print: The TwelveMonkeys service providers for JPEG, BMP and TIFF, overrides the onRegistration method, and utilizes the pairwise partial ordering mechanism of the IIOServiceRegistry to make sure it is installed before the Sun/Oracle provided JPEGImageReader, BMPImageReader TIFFImageReader, and the Apple provided TIFFImageReader on OS X, respectively. Using the pairwise ordering will not remove any functionality form these implementations, but in most cases you'll end up using the TwelveMonkeys plug-ins instead.

q: Why is there no support for common formats like GIF or PNG?

a: The short answer is simply that the built-in support in ImageIO for these formats are considered good enough as-is. If you are looking for better PNG write performance on Java 7 and 8, see JDK9 PNG Writer Backport.

q: When is the next release? What is the current release schedule?

a: The goal is to make monthly releases, containing bug fixes and minor new features. And quarterly releases with more "major" features.

q: I love this project! How can I help?

a: Have a look at the open issues, and see if there are any issues you can help fix, or provide sample file or create test cases for. It is also possible for you or your organization to become a sponsor, through GitHub Sponsors. Providing funding will allow us to spend more time on fixing bugs and implementing new features.

q: What about JAI? Several of the formats are already supported by JAI.

a: While JAI (and jai-imageio in particular) have support for some of the same formats, JAI has some major issues. The most obvious being:

  • It's not actively developed. No issue has been fixed for years.
  • To get full format support, you need native libs. Native libs does not exist for several popular platforms/architectures, and further the native libs are not open source. Some environments may also prevent deployment of native libs, which brings us back to square one.

q: What about JMagick or IM4Java? Can't you just use what's already available?

a: While great libraries with a wide range of formats support, the ImageMagick-based libraries has some disadvantages compared to ImageIO.

  • No real stream support, these libraries only work with files.
  • No easy access to pixel data through standard Java2D/BufferedImage API.
  • Not a pure Java solution, requires system specific native libs.

We did it

twelvemonkeys's People

Contributors

actinium15 avatar ankon avatar astappiev avatar bchapuis avatar bernhardf-ro avatar ckovorodkin avatar daaaaa avatar dependabot[bot] avatar gotson avatar guinotphil avatar hamnis avatar haraldk avatar joycebrum avatar justwrote avatar koendg avatar lokling avatar paulvi avatar pvorb avatar runebr avatar schmidor avatar seafraf avatar shihabuddin avatar simon04090 avatar snyk-bot avatar steinarb avatar trygvis avatar wladimirleite avatar younseunghyun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twelvemonkeys's Issues

Maven RC artifacts

Is there any reason some artifacts like imageio-icns are still "RC" after a few months?

I want to use some of them in a project, but we are not allowed to use any artifact with a version different than "X.Y.Z" (to avoid SNAPSHOTs and other strange names)

Can those be re-released as final already?

imageio-jpeg does not handle IIOMetaData

I'm currently trying to convert a CMYK jpeg to an RGB one while preserving its meta data. Then i recognized that JPEGImageReader.getImageMetadata(...) method always returns null.

Null Pointer Exception when JPEG has got two SOI markers.

First I want to thanks TwelveMonkeys to provide such library.
Recently, I am facing following Null Pointer Exception while reading them. Attaching the images

StackTrace with twelvemonkey jpeg plugin:
java.lang.NullPointerException
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.getSourceCSType(Unknown Source)
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
at javax.imageio.ImageIO.read(ImageIO.java:1448)
at javax.imageio.ImageIO.read(ImageIO.java:1308)

StackTrace without twelvemonkey jpeg plugin:
javax.imageio.IIOException: Invalid JPEG file structure: two SOI markers
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:604)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:342)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:476)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:597)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1054)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1034)
at javax.imageio.ImageIO.read(ImageIO.java:1448)
at javax.imageio.ImageIO.read(ImageIO.java:1308)

05
11 1

Release 3.0

As far as I understood, support for CMYK-Jpegs will come with 3.0. This is the main reason I would really like to see a releas soon ;)
Since I could not find a maven repo containing 3.0-SNAPSHOT, I will now have to build my own and deploy to our internal nexus...

Improvement: Move CompoundDirectory from imageio-tiff to imageio-metadata

Hi all,
First time working with TwelveMonkeys (a non-sun ImageIO impl, awesome!).

I'm working only on Metadata extraction, and I found that compounddirectory was only in the imageio-tiff jar -- would it be possible to move that to imageio-metadata?

usecase: When working with only the metadata of the images, to be able to use only the imageio-metadata jar package (and core) without needing all the image manipulation support that is in the image-specific libraries.

I'm raising this as an issue in case there are other considerations, as this is only at first-blush it seems like a reasonable idea.

Extract Clipping Path from TIFF Image

It would be very useful if your TIFF ImageIO plugin could also extract Clipping Paths that are embedded in the TIFF Header and return a Shape object or even the raw SVG. This Shape or SVG Markup could then be used to add an Alpha Channel when converting TIFFs to other formats that support an Alpha Channel - like PNGs.

package build fails becouse of imageio-iff test failure

Hello there,

I'm trying to build the 3.0-SNAPSHOT using just "mvn" package but the packaging fails becouse of tests.

Here the stack trace:

testEHBColors(com.twelvemonkeys.imageio.plugins.iff.IFFImageReaderTest) Time elapsed: 0.076 sec <<< FAILURE!
java.lang.AssertionError: expected:<13> but was:<0>
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.failNotEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:126)
at org.junit.Assert.assertEquals(Assert.java:470)
at org.junit.Assert.assertEquals(Assert.java:454)
at com.twelvemonkeys.imageio.plugins.iff.IFFImageReaderTest.testEHBColors(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

Is some native library missing?

Thanks,

Daniele.

Netbeans versus without Netbeans

Hello,
I use the Netbeans IDE with JDK 7.1.60, added the jar to the library and the program works perfectly in NetBeans environment, but when I run outside the IDE does not work.

Iterator readers = ImageIO.getImageReadersByFormatName ("PSD");
while (readers.hasNext ()) {
System.out.println ("reader:" + readers.next ());
}
Returns nothing.

Can you help me?

Thank you

Sergio

Using the JPEGImageReader

Hi,
sorry for the stupid question, but I'm currently trying to read some Images that throw the java.awt.color.CMMException in the normal ImageIO.
But I just don't know what to import/use, I build the project via maven and added the imageio.plugins.jpeg jar to my classpath. I read in a Stackowerflow post that I can use it like the normal ImageIO but it doesnt't really work that way.
I hope I haven't overseen some doc files but I didn't find anything expect the readme saying "we did it"
greets

Remove deprecation warnings from build (direct use of Oracle/Sun JPEGImageReader)

Currently the build creates a few of these warnings:

/.../twelvemonkeys/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReader.java:31: warning: JPEGImageReader is internal proprietary API and may be removed in a future release
import com.sun.imageio.plugins.jpeg.JPEGImageReader;
^

We should rewrite to use the service lookup mechanism to instantiate these in readers that delegate to the com.sun...JPEGImageReader.

For the tests, perhaps just annotate with @Deprecated as we really mean to use these classes, alternatively use some reflection.

TIFF write support

Write support for Baseline TIFF.

Popular extensions:

  • LZW
  • JPEG ("new style" only)
  • 16 bit signed data?

JPEGImageReaderTest#testReadSubsamplingBounds{1024,1026,1027} failing

On revision e3bab84 I have these tests failing:

-------------------------------------------------------------------------------
Test set: com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest
-------------------------------------------------------------------------------
Tests run: 104, Failures: 3, Errors: 0, Skipped: 5, Time elapsed: 2.124 sec <<< FAILURE!
testReadSubsamplingBounds1027(com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest)  Time elapsed: 0.041 sec  <<< FAILURE!
java.lang.AssertionError: expected:<16711421> but was:<16711677>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:470)
    at org.junit.Assert.assertEquals(Assert.java:454)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest.testReadSubsamplingBounds1027(Unknown Source)
...
testReadSubsamplingBounds1026(com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest)  Time elapsed: 0.034 sec  <<< FAILURE!
java.lang.AssertionError: expected:<16711421> but was:<16711677>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:470)
    at org.junit.Assert.assertEquals(Assert.java:454)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest.testReadSubsamplingBounds1026(Unknown Source)
...
testReadSubsamplingBounds1024(com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest)  Time elapsed: 0.022 sec  <<< FAILURE!
java.lang.AssertionError: expected:<16711421> but was:<16711677>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:470)
    at org.junit.Assert.assertEquals(Assert.java:454)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest.testReadSubsamplingBounds1024(Unknown Source)
...

Java is

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

(same failures also with 1.7.0_45, and with 1.8.0-b129 under KCMS, see #41 )

The machine in question is a Fedora 20 x86_64 system.

Creation of *source.jar in phase "package"

I was missing the *source.jar files.

mvn.bat source:jar package

did the right thing, but the comment
<!-- THIS DOES NOT WORK..?! -->
in pom.xml suggests that

mvn.bat package

should do it automatically.

http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement

gave the answer: Moved

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                 <inherited>true</inherited>
                 <executions>
                     <execution>
                         <phase>package</phase>
                         <id>attach-sources</id>
                         <goals>
                             <goal>jar</goal>
                             <goal>test-jar</goal>
                         </goals>
                     </execution>
                 </executions>
             </plugin>

from <build><pluginManagement><plugins> to <build><plugins> .

Many thanks to you Harald, TwelveMonkeys saved my day.

imageio-jpeg convert CMYK to RGB: color is off

Hi,

I'm using latest snapshot of imageio-jpeg to convert CMYK jpg to RGB, but the resulting jpg's color is off, it's darker than the original, what is the best way to debug this? I added warning listener to reader and writer, but didn't receive any warnings.

Thanks

ConcurrentModificationException in IIOProviderContextListener#contextDestroyed()

Dec 30, 2013 4:39:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Unregistered locally installed provider class: class com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi
Dec 30, 2013 4:39:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Unregistered locally installed provider class: class com.twelvemonkeys.imageio.plugins.psd.PSDImageReaderSpi
Dec 30, 2013 4:39:01 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class com.twelvemonkeys.servlet.image.IIOProviderContextListener
java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
    at java.util.HashMap$ValueIterator.next(HashMap.java:835)
    at javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:809)
    at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:828)
    at com.twelvemonkeys.servlet.image.IIOProviderContextListener.contextDestroyed(Unknown Source)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4763)
    at org.apache.catalina.core.StandardContext$4.run(StandardContext.java:5472)
    at java.lang.Thread.run(Thread.java:722)

Seen when hot-deploying a war file in tomcat 7.0.47, didn't yet check out the specific place in the code.

NPE in JPEGImageReader.getImageMetadata()

I get this NPE with a particular image with CMYK and an embedded ICC profile. It happens in jpegVariety.getFirstChild().appendChild(app2ICC). The firstChild in the jpegVariety is null. Could this be an issue with the image? Is there a way to attach the image?

TIFF reading of short and integer rasters unreasonably slow

Reading byte rasters are fast, short and int rasters are (very) slow.

Known reason:
Byte rasters are read using DataInput.readFully(byte[]...).
Short and Integer rasters are currently read in loop, reading one short/int at a time, respectively.

QuickFIx:
Cast to ImageInputStream if possible, and use the overloaded readFully that takes short[]/int[] parameters.

Full fix:
Implement util functions that can read short/int arrays fast from a DataInput, probably using ByteBuffer or similar code to the one in ImageInputStream.

Subsampling in JPEGImageReader may result in black last line

Fixing #39 revealed another issue:

The last line of subsampled images may turn out black. The issue can be shown by running the tests:

JPEGImageReaderTest.testReadSubsamplingNotSkippingLines1025()

and

JPEGImageReaderTest.testReadSubsamplingNotSkippingLines1028()

(currently @Ignoreed).

NullPointerException while reading image

I get the following exception while try to read the attached, some may say odd ;-) image:

java.lang.NullPointerException
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.getAppSegments(JPEGImageReader.java:619)
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.getEmbeddedICCProfile(JPEGImageReader.java:724)
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:270)
at javax.imageio.ImageReader.read(ImageReader.java:923)

icc_problem2

Unable to load JPG images due to "Unsupported JPEG process: SOF type 0xcb"

Before starting the bug report - you also save my day :-)

For a few images I get the error message

Unsupported JPEG process: SOF type 0xcb

[ERROR] [2014.03.26 09:53:49]  Loading the image failed  : /iad/styria/prod/htdocs/uploads/20140301_123857_2363439246058001517.jpg [Environment: Host: "www.willhaben.at" Action: "swfuploadimage" Action Class name: "null" Sequence #: "135192664" Referer: "null" URL: "/swfuploadimage" RemoteIP: "212.152.181.235" User-Agent: "Shockwave Flash" jsessionid=3AD5B5AC
CAC4F054C1F1EEA4FE891D51&[email protected]]  at no.finntech.base.modules.scale.ScaleJavaOnly.createImageFromImageFile(ScaleJavaOnly.java:282)
javax.imageio.IIOException: Unsupported JPEG process: SOF type 0xcb
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1231)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1034)
        at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
        at javax.imageio.ImageIO.read(ImageIO.java:1448)
        at javax.imageio.ImageIO.read(ImageIO.java:1308)

Not an expert but

  • it might stem from an unsupported compression type "Lossless (sequential arith)"
  • it might not stem at all from your library

I attached the offending image

Cheers,

Siegfried Goeschl

test-image-broken-01

missing icc_profiles_lnx files

I am getting this error when running mvn package:
java.io.FileNotFoundException: com/twelvemonkeys/imageio/color/icc_profiles_lnx.properties or com/twelvemonkeys/imageio/color/icc_profiles_lnx.xml

I cannot find these files in the source... How can I get them?

PNG Version + Byte Buffer version

Hi

I like your project and I intend on using it in my java 3D game engine which is in its early stages, I was wondering if you were going to produce your own version of the PNG loader? I have my own version and speed wise it is 3-4 times faster than the ImageIO reader that comes with Java

Also do you have any intension of creating a ByteBuffer version of your readers? Ie it loads directly in to a byte buffer and and skips the ImageIO API? This would be for people wanting to load images directly in to a 3D renderer, this might increase speed dramatically.

Thanks

Peter

Wrong JPEG color space

Apparently TwelveMonkeys and JDK have exchanged seats: the com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader confuses JPEG color space while JDK produces adequate result.

The test:

val img = ImageIO.read(new File("/home/andrey/Downloads/tailand.jpg"))
ImageIO.write(img, "JPG", new File("/tmp/thumbnail.jpg"))

Original image (link):
tailand
Result:
thumbnail

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

TwelveMonkeys: 3.0-rc5

ColorSpacesTest#testCorbisRGBSpecialHandling() fails with JDK8/LCMS

When building with JDK 8 (b129) the ColorSpacesTest#testCorbisRGBSpecialHandling() fails:

-------------------------------------------------------------------------------
Test set: com.twelvemonkeys.imageio.color.ColorSpacesTest
-------------------------------------------------------------------------------
Tests run: 18, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.067 sec <<< FAILURE!
testCorbisRGBSpecialHandling(com.twelvemonkeys.imageio.color.ColorSpacesTest)  Time elapsed: 0.007 sec  <<< FAILURE!
java.lang.AssertionError: array lengths differed, expected.length=452 actual.length=420
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.internal.ComparisonCriteria.assertArraysAreSameLength(ComparisonCriteria.java:72)
    at org.junit.internal.ComparisonCriteria.arrayEquals(ComparisonCriteria.java:36)
    at org.junit.Assert.internalArrayEquals(Assert.java:414)
    at org.junit.Assert.assertArrayEquals(Assert.java:200)
    at org.junit.Assert.assertArrayEquals(Assert.java:213)
    at com.twelvemonkeys.imageio.color.ColorSpacesTest.testCorbisRGBSpecialHandling(Unknown Source)

This seems to be caused by the use of LCMS in JDK8, while earlier JDKs use kcms. The test can be made to pass by using the JVM arguments to switch back to kcms:

-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider

Unofrtunately I cannot get my JDK 1.7.0u45 to use LCMS to check in the other direction.

Build problems

Hi, I'm primarily interested in the imageio-jpeg plugin and was trying to build the whole imageio project, 3.0-SNAPSHOT. Maybe I don't know what I'm doing, but when I build the project, I get a failure on the IFF plugin. Skipping tests doesn't seem to help either.
If it helps, here's the maven error:

com.twelvemonkeys.imageio.plugins.iff.IFFImageReaderTest

Failed tests: testWriteReadCompare(com.twelvemonkeys.imageio.plugins.iff.IFFImageWriterTest): Failure writing test data 0 java.io.EOFException

Thanks!

JPEG 3-channel component ID = 0-2 YCbCr (using RGB)

Hi,

First of all thanks for this great library, it helped me overcome already many issues with images.

I'm currently working with one type of image that appears to be YCbCr, but RGB model is used. Example images are:

4ss0332-014
2)
14-0281-054_1

These images seem to be created by Photoshop and have :
startOfFrame.components[0].id == 0
startOfFrame.components[1].id == 1
startOfFrame.components[2].id == 2

Therefore, in JPEGImageReader.java I have changed the if statement on line 569 from
if (startOfFrame.components[0].id == 1 && startOfFrame.components[1].id == 2 && startOfFrame.components[2].id == 3) {

to

if ((startOfFrame.components[0].id == 0 && startOfFrame.components[1].id == 1 && startOfFrame.components[2].id == 2) || (startOfFrame.components[0].id == 1 && startOfFrame.components[1].id == 2 && startOfFrame.components[2].id == 3)) {

in order to select return JPEGColorSpace.YCbCr.

Would you be willing to apply this patch?

Best regards,
Boris

Dependency failed

Good day,
added

com.twelvemonkeys.imageio imageio-jpeg 3.0-SNAPSHOT

when I am trying to run project getting:
[WARNING] The POM for com.twelvemonkeys.imageio:imageio-jpeg:jar:3.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...
[ERROR] Failed to execute goal on project: Could not resolve dependencies for project com.test:war:1.1.2: Failure to find com.twelvemonkeys.imageio:imageio-jpeg:jar:3.0-SNAPSHOT in http://repository.apache.org/content/groups/snapshots-group/ was cached in the local repository, resolution will not be reattempted until the update interval of apache.snapshots has elapsed or updates are forced -> [Help 1]

ImageIO.getImageWriter(reader) not working inside tomcat

Hello Harald,

I wrote a basic test code that does work in a standalone test class:

public class Test
{

public static void main(String[] arg)
{
    try
    {
        ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream(arg[0]));
        Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
        if (!readers.hasNext())
            throw new IOException("can't decode this image inputstream");

        ImageReader reader = readers.next();
        ImageReadParam param = reader.getDefaultReadParam();
        reader.setInput(iis, true, true);
        BufferedImage img = reader.read(0, param);

        ImageWriter writer = ImageIO.getImageWriter(reader);

        if (writer == null)
            throw new IOException("can't find writer, reader provider: " + reader.getOriginatingProvider());

        System.out.println("Writer: " + writer.getClass());
    }
    catch (Throwable t)
    {
        t.printStackTrace();
    }
}

}

The same code doesn't work inside a tomcat webapp, writer is null so an exception is thrown.

I have:

  • added the listener as described in the guide
  • fixed class name typos inside JPEGImageWriterSpi (class names were not starting with "com"

I have verified with a test loop that the ImageWriter is loaded:

static
{
    System.out.println("ImageIO, looking for writers");

    Iterator<ImageWriter> ite = ImageIO.getImageWritersByFormatName("jpeg");

    while (ite.hasNext())
        System.out.println("ImageIO writer: " + ite.next().getClass());
}

And the result:

logs/catalina.out:ImageIO, looking for writers
logs/catalina.out:ImageIO writer: class com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriter
logs/catalina.out:ImageIO writer: class com.sun.imageio.plugins.jpeg.JPEGImageWriter

Any idea about why is not working just inside tomcat? How to debug further?

Thanks,

Daniele.

Twelvemonkeys ImageIO reader not available on Centos but available on windows

Good day,

I have an issue implementing your wonderful solution to my server, and would appreciate if u can help me with it.

  1. I built all the libraries locally. Here are my dependencies:

<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-core</artifactId>
<version>${twelvemonkey.version}</version>
<scope>system</scope>
<systemPath>${repo.local.path}twelvemonkeys-imageio-core-3.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-common</artifactId>
<version>${twelvemonkey.version}</version>
<scope>system</scope>
<systemPath>${repo.local.path}twelvemonkeys-common-lang-3.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-metadata</artifactId>
<version>${twelvemonkey.version}</version>
<scope>system</scope>
<systemPath>${repo.local.path}twelvemonkeys-imageio-metadata-3.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>${twelvemonkey.version}</version>
<scope>system</scope>
<systemPath>${repo.local.path}twelvemonkeys-imageio-jpeg-3.0-SNAPSHOT.jar</systemPath>
</dependency>

  1. Everything seems to be working locally on windows 7, java: 1.7.0_06-b24
    I get in log this list of IOReaders:
    [2013-12-10 19:52:34,996] [INFO ] [http-bio-8080-exec-3] ImageModel [184]: ImageIO reader: com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader@247f1358
    [2013-12-10 19:52:34,997] [INFO ] [http-bio-8080-exec-3] ImageModel [184]: ImageIO reader: com.sun.imageio.plugins.jpeg.JPEGImageReader@2e7ed301
  2. The problem appears to be when I deploy to the server. Which has Centos and same java version. I get just this.
    [2013-12-10 19:36:38,384] [INFO ] [http-bio-8080-exec-6] ImageModel [184]: ImageIO reader: com.sun.imageio.plugins.jpeg.JPEGImageReader@14e8949

Server detailed info:

OS: OS Linux unknown, amd64/64 (8 cores)
Java: Java(TM) SE Runtime Environment, 1.7.0_06-b24
JVM: Java HotSpot(TM) 64-Bit Server VM, 23.2-b09, mixed mode
PID of process: 2469
Nb of opened files 66 / 1,024 ++++++++++++
Server: Server Apache Tomcat/7.0.29
Webapp context:
Start: 12/8/13 11:17 PM
JVM arguments: -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties
-Xms1024M
-Xmx4096M
-XX:MaxPermSize=512M
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.endorsed.dirs=/opt/tomcat/endorsed
-Dcatalina.base=/opt/tomcat
-Dcatalina.home=/opt/tomcat
-Djava.io.tmpdir=/opt/tomcat/temp
Mean age of http sessions (min): 108
Tomcat "http-bio-8080": Busy threads = 6 / 200 ++++++++++++
Bytes received = 1,358,977
Bytes sent = 272,220,893
Request count = 25,095
Error count = 918
Sum of processing times (ms) = 3,589,889
Max processing time (ms) = 923,266
Memory: Non heap memory = 118 Mb (Perm Gen, Code Cache),
Loaded classes = 14,701,
Garbage collection time = 38,065 ms,
Process cpu time = 4,432,390 ms,
Committed virtual memory = 5,530 Mb,
Free physical memory = 306 Mb,
Total physical memory = 32,162 Mb,
Free swap space = 3,914 Mb,
Total swap space = 3,914 Mb
Perm Gen memory: 97 Mb / 512 Mb ++++++++++++

Please let me know if u need more info. Thank you very much for your help.

JMagick not available

Hi,
I wanted to use the packages to improve imageio.
I downloaded all the packages. I can read the images correctly, but I have an error during the initialization:
Could not instantiate SVGImageReader (missing support classes).
java.lang.NoClassDefFoundError: org/apache/batik/transcoder/TranscoderException
at com.twelvemonkeys.imageio.plugins.svg.SVGImageReaderSpi.onRegistration(Unknown Source)
at javax.imageio.spi.SubRegistry.registerServiceProvider(ServiceRegistry.java:715)
at javax.imageio.spi.ServiceRegistry.registerServiceProvider(ServiceRegistry.java:302)
at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(IIORegistry.java:211)
at javax.imageio.spi.IIORegistry.(IIORegistry.java:138)
at javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:159)
at javax.imageio.ImageIO.(ImageIO.java:65)
at imageTiTi.ImageIO.Read(ImageIO.java:174)
at imageTiTi.ImageIO.Read(ImageIO.java:158)
at prototyper.Prototyper.main(Prototyper.java:324)
Caused by: java.lang.ClassNotFoundException: org.apache.batik.transcoder.TranscoderException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 10 more
JMagick not available: java.lang.NoClassDefFoundError: magick/MagickImage
Make sure JMagick libraries are available in java.library.path. Current value:
"/Applications/NetBeans/NetBeans 8.0.app/Contents/Resources/NetBeans/webcommon/bin::/Users/FiReTiTi/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."

But even if there is this error, I can read the images.
But how can I fix this error?
Thank for your help.

Does not build on windows (minor fix in tests)

Did not commit due to time constraints:
In com.twelvemonkeys.util.convert.DefaultConverterTestCase replace line 50:
from (unix specific):
new Conversion("/temp, /usr/local/bin", new File[] {new File("/temp"), new File("/usr/local/bin")}),
to (OS agnostic):
new Conversion("/temp, /usr/local/bin".replace('/',File.separatorChar), new File[] {new File("/temp"), new File("/usr/local/bin")}),

Thanks for a great library!

Resizing of images with ResampleOp.filter slow on WebSphere 8.5.5

I have an performance issue with resizing images in WebSphere 8.5.5. Previously my web app was deployed on Tomcat 7.0.50, and resizing was working just fine. Please check my Q & A on stackoverflow for move info: http://stackoverflow.com/questions/21093470/imageio-read-write-slow-in-websphere-8-5-5/21097980#21097980

Here is the one of test images I've used & a snapshot from JProfiler
testimage

jprofiler cpu data

EDIT:
I've run couple of more profilings, and the problematic methods are following (for Tomcat & WebSpehre on IBM JVM):

ResampleOp.resample:
java.awt.image.Raster.getSample
java.awt.image.WritableRaster.getSample

I must have had some filters turned on on my initial profilings

twelvemonkey not in front

Documentation:
"The TwelveMonkeys service providers for TIFF and JPEG overrides the onRegistration method, and utilizes the pairwise partial ordering mechanism of the IIOServiceRegistry to make sure it is installed before the Sun/Oracle provided JPEGImageReader and the Apple provided TIFFImageReader on OS X, respectively. "

Code:

Iterator jpegReaders = ImageIO.getImageReadersByFormatName("JPEG");
while (jpegReaders.hasNext()) {
System.out.println("jpeg reader: " + jpegReaders.next());
}
Iterator tiffReaders = ImageIO.getImageReadersByFormatName("TIFF");
while (tiffReaders.hasNext()) {
System.out.println("tiff reader: " + tiffReaders.next());
}

result:
jpeg reader: com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader@5dadd1c5
jpeg reader: com.sun.imageio.plugins.jpeg.JPEGImageReader@4929a06b
tiff reader: com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader@247ab39
tiff reader: com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader@5f3f333c

So the tiff reader isn't in front :-( Or does the documentation mean that it only applies to OSX?

CMMException when parsing jpeg

Hi Harald,

I've been using TwelveMonkeys successfully, but I found an image that causes problems (attached and linked):

http://25.media.tumblr.com/77f31c36ea8f46ad1f41d6c6f02c60a8/tumblr_n0ccizPvsK1smx7x5o5_1280.jpg

tumblr_n0ccizpvsk1smx7x5o5_1280

When I try to read in that image, I get the following exception:

java.awt.color.CMMException: General CMM error517
    at sun.java2d.cmm.kcms.CMM.checkStatus(CMM.java:180)
    at sun.java2d.cmm.kcms.CMM.createTransform(CMM.java:134)
    at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:540)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.readImageAsRasterAndReplaceColorProfile(Unknown Source)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
    at javax.imageio.ImageIO.read(ImageIO.java:1448)
    at javax.imageio.ImageIO.read(ImageIO.java:1308)
...

This may be related to this java bug:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6444360

And here's another image I found that causes the same problem, in case that helps:
http://lh6.ggpht.com/_zhJGGuLhHrQ/Ro6SIyBE_TI/AAAAAAAAAA4/PWx6LzckCSs/Flower+-+GalleryPlayer.jpg

mvn package - test failure - testGetTypeSpecifiers - OpenJDK/LCMS

I can't seem to get a successful build on Ubuntu 14.04 or Fedora 20, I am getting the same failed tests, if this normal? Am I doing something wrong?

Java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (fedora-2.4.4.1.fc20-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"
mvn -e package

tail of mvn output:


T E S T S

Running com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest
WARNING: Reading reference metadata failed for TestData: file:/home/csyperski88/Downloads/TwelveMonkeys-master/imageio/imageio-jpeg/target/test-classes/jpeg/cmyk-sample.jpg image 0: Inconsistent metadata read from stream
WARNING: Reading reference metadata failed for TestData: file:/home/csyperski88/Downloads/TwelveMonkeys-master/imageio/imageio-jpeg/target/test-classes/jpeg/cmyk-sample-multiple-chunk-icc.jpg image 0: Image format Error
WARNING: Test skipped due to reader.getRawImageType(0) returning null
Tests run: 95, Failures: 2, Errors: 0, Skipped: 3, Time elapsed: 5.806 sec <<< FAILURE!
Running com.twelvemonkeys.imageio.plugins.jpeg.JFIFThumbnailReaderTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec
Running com.twelvemonkeys.imageio.plugins.jpeg.JPEGSegmentImageInputStreamTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.018 sec
Running com.twelvemonkeys.imageio.plugins.jpeg.JFXXThumbnailReaderTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec
Running com.twelvemonkeys.imageio.plugins.jpeg.EXIFThumbnailReaderTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.01 sec
Running com.twelvemonkeys.imageio.plugins.jpeg.FastCMYKToRGBTest
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.061 sec
Running com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterTest
Tests run: 16, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.09 sec <<< FAILURE!

Results :

Failed tests: testGetTypeSpecifiers(com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest): ImageTypeSepcifier from getRawImageType should be in the iterator from getImageTypes
testSetDestinationType(com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderTest): Could not read file:/home/csyperski88/Downloads/TwelveMonkeys-master/imageio/imageio-jpeg/target/test-classes/jpeg/cmm-exception-adobe-rgb.jpg with explicit destination type javax.imageio.ImageTypeSpecifier$Interleaved@2a0e3919
testWrite(com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterTest): Invalid argument to native writeImage

Tests run: 138, Failures: 3, Errors: 0, Skipped: 3

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Twelvemonkeys ..................................... SUCCESS [0.254s]
[INFO] TwelveMonkeys :: Common ........................... SUCCESS [0.007s]
[INFO] TwelveMonkeys :: Common :: Language support ....... SUCCESS [1.937s]
[INFO] TwelveMonkeys :: Common :: IO ..................... SUCCESS [3.161s]
[INFO] TwelveMonkeys :: Common :: Image .................. SUCCESS [1.671s]
[INFO] TwelveMonkeys :: Servlet .......................... SUCCESS [3.851s]
[INFO] TwelveMonkeys :: ImageIO .......................... SUCCESS [0.007s]
[INFO] TwelveMonkeys :: ImageIO :: Core .................. SUCCESS [0.644s]
[INFO] TwelveMonkeys :: ImageIO :: Metadata .............. SUCCESS [0.671s]
[INFO] TwelveMonkeys :: ImageIO :: ICO plugin ............ SUCCESS [1.023s]
[INFO] TwelveMonkeys :: ImageIO :: ICNS plugin ........... SUCCESS [0.730s]
[INFO] TwelveMonkeys :: ImageIO :: IFF plugin ............ SUCCESS [1.522s]
[INFO] TwelveMonkeys :: ImageIO :: JPEG plugin ........... FAILURE [6.178s]
[INFO] TwelveMonkeys :: ImageIO :: PDF plugin ............ SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: PICT plugin ........... SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: PSD plugin ............ SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: Thumbs.db plugin ...... SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: TIFF plugin ........... SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: Batik Plugin .......... SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: JMagick Plugin ........ SKIPPED
[INFO] TwelveMonkeys :: ImageIO :: reference test cases .. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.981s
[INFO] Finished at: Mon Jan 27 08:59:19 CST 2014
[INFO] Final Memory: 29M/303M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project imageio-jpeg: There are test failures.
[ERROR]
[ERROR] Please refer to /home/csyperski88/Downloads/TwelveMonkeys-master/imageio/imageio-jpeg/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project imageio-jpeg: There are test failures.

Please refer to /home/csyperski88/Downloads/TwelveMonkeys-master/imageio/imageio-jpeg/target/surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to /home/csyperski88/Downloads/TwelveMonkeys-master/imageio/imageio-jpeg/target/surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:87)
at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:641)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:615)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:137)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :imageio-jpeg

Unreadable TIFF image

Hello Harald,

I've tried to load some TIFF but for one I get:

javax.imageio.IIOException: Unsupported TIFF Compression value: 4
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.read(Unknown Source)

Is that a known limitation or a bug?

Thanks,

Daniele.

Nullpointer Exception when reading CMYK (Servlet)

Based on the latest version of this github repository (running java 1.6.0_16 and Debian 4.1.2-25). I build the project with maven and then added

twelvemonkeys-common-lang-3.0-SNAPSHOT.jar
twelvemonkeys-common-io-3.0-SNAPSHOT.jar
twelvemonkeys-common-image-3.0-SNAPSHOT.jar
twelvemonkeys-imageio-core-3.0-SNAPSHOT.jar
twelvemonkeys-imageio-metadata-3.0-SNAPSHOT.jar
twelvemonkeys-imageio-jpeg-3.0-SNAPSHOT.jar
twelvemonkeys-imageio-tiff-3.0-SNAPSHOT.jar
twelvemonkeys-servlet-3.0-SNAPSHOT.jar

to my servlet libs. I'm trying to read any CMYK image, for example:

Channel digital image CMYK color

From Wikipedia. The same image is loaded if I just run a test locally.
As a servlet, I get the following NullPointerException:

java.lang.NullPointerException
    at com.twelvemonkeys.imageio.color.ColorSpaces.getColorSpace(ColorSpaces.java:265)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.getImageTypes(JPEGImageReader.java:232)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.readImageAsRasterAndReplaceColorProfile(JPEGImageReader.java:351)
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:337)
    at javax.imageio.ImageIO.read(ImageIO.java:1422)
    ...

It seems really odd, that this line would cause a NPE, as the code in com.twelvemonkeys.imageio.color.ColorSpaces just reads:

profile = genericCMYK.get();

and the genericCMYK is a static variable:

private static WeakReference<ICC_Profile> genericCMYK = new WeakReference<ICC_Profile>(null);

that does not seem to be nulled anywhere.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.