mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 11:05:29 -04:00
Work in progress: Brand new JPEGImageReader capable of reading CMYK JPEG and images with "broken" color profiles.
This commit is contained in:
parent
47ab16457a
commit
df0d3f90e8
32
imageio/imageio-jpeg/pom.xml
Normal file
32
imageio/imageio-jpeg/pom.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>imageio-jpeg</artifactId>
|
||||
<name>TwelveMonkeys :: ImageIO :: JPEG plugin</name>
|
||||
<description>
|
||||
ImageIO plugin for Joint Photographer Expert Group images (JPEG/JFIF).
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-core</artifactId>
|
||||
<classifier>tests</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-metadata</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 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:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* Neither the name "TwelveMonkeys" 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 OWNER 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.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.jpeg;
|
||||
|
||||
import com.twelvemonkeys.imageio.spi.ProviderInfo;
|
||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.metadata.IIOMetadataFormat;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ServiceRegistry;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* JPEGImageReaderSpi
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: JPEGImageReaderSpi.java,v 1.0 24.01.11 22.12 haraldk Exp$
|
||||
*/
|
||||
public class JPEGImageReaderSpi extends ImageReaderSpi {
|
||||
private ImageReaderSpi delegateProvider;
|
||||
|
||||
/**
|
||||
* Constructor for use by {@link javax.imageio.spi.IIORegistry} only.
|
||||
* The instance created will not work without being properly registered.
|
||||
*/
|
||||
public JPEGImageReaderSpi() {
|
||||
this(IIOUtil.getProviderInfo(JPEGImageReaderSpi.class));
|
||||
}
|
||||
|
||||
private JPEGImageReaderSpi(final ProviderInfo providerInfo) {
|
||||
super(
|
||||
providerInfo.getVendorName(),
|
||||
providerInfo.getVersion(),
|
||||
new String[]{"JPEG", "jpeg", "JPG", "jpg"},
|
||||
new String[]{"jpg", "jpeg"},
|
||||
new String[]{"image/jpeg"},
|
||||
JPEGImageReader.class.getName(),
|
||||
STANDARD_INPUT_TYPE,
|
||||
null,
|
||||
true, null, null, null, null,
|
||||
true, null, null, null, null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code JPEGImageReaderSpi} with the given delegate.
|
||||
*
|
||||
* @param delegateProvider a {@code ImageReaderSpi} that can read JPEG.
|
||||
*/
|
||||
protected JPEGImageReaderSpi(final ImageReaderSpi delegateProvider) {
|
||||
this(IIOUtil.getProviderInfo(JPEGImageReaderSpi.class));
|
||||
|
||||
this.delegateProvider = Validate.notNull(delegateProvider);
|
||||
}
|
||||
|
||||
ImageReaderSpi lookupDelegate(final ServiceRegistry registry) {
|
||||
// Should be safe to lookup now, as the bundled providers are hardcoded usually
|
||||
try {
|
||||
return (ImageReaderSpi) registry.getServiceProviderByClass(Class.forName("com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"));
|
||||
}
|
||||
catch (ClassNotFoundException ignore) {
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public void onRegistration(final ServiceRegistry registry, final Class<?> category) {
|
||||
if (delegateProvider == null) {
|
||||
// Install delegate now
|
||||
delegateProvider = lookupDelegate(registry);
|
||||
}
|
||||
|
||||
if (delegateProvider == null) {
|
||||
IIOUtil.deregisterProvider(registry, this, category);
|
||||
}
|
||||
else {
|
||||
// Order before com.sun provider, to aid ImageIO in selecting our reader
|
||||
registry.setOrdering((Class<ImageReaderSpi>) category, this, delegateProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVendorName() {
|
||||
return String.format("%s/%s", super.getVendorName(), delegateProvider.getVendorName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return String.format("%s/%s", super.getVersion(), delegateProvider.getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageReader createReaderInstance(Object extension) throws IOException {
|
||||
return new JPEGImageReader(this, delegateProvider.createReaderInstance(extension));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDecodeInput(Object source) throws IOException {
|
||||
return delegateProvider.canDecodeInput(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getImageWriterSpiNames() {
|
||||
// TODO: The WriterSpi will have a similar method, and it should return the name of this class...
|
||||
return delegateProvider.getImageWriterSpiNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getFormatNames() {
|
||||
return delegateProvider.getFormatNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getFileSuffixes() {
|
||||
return delegateProvider.getFileSuffixes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMIMETypes() {
|
||||
return delegateProvider.getMIMETypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginClassName() {
|
||||
return "com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader";
|
||||
// return delegateProvider.getPluginClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStandardStreamMetadataFormatSupported() {
|
||||
return delegateProvider.isStandardStreamMetadataFormatSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNativeStreamMetadataFormatName() {
|
||||
return delegateProvider.getNativeStreamMetadataFormatName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getExtraStreamMetadataFormatNames() {
|
||||
return delegateProvider.getExtraStreamMetadataFormatNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStandardImageMetadataFormatSupported() {
|
||||
return delegateProvider.isStandardImageMetadataFormatSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNativeImageMetadataFormatName() {
|
||||
return delegateProvider.getNativeImageMetadataFormatName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getExtraImageMetadataFormatNames() {
|
||||
return delegateProvider.getExtraImageMetadataFormatNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIOMetadataFormat getStreamMetadataFormat(String formatName) {
|
||||
return delegateProvider.getStreamMetadataFormat(formatName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIOMetadataFormat getImageMetadataFormat(String formatName) {
|
||||
return delegateProvider.getImageMetadataFormat(formatName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(Locale locale) {
|
||||
return delegateProvider.getDescription(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getInputTypes() {
|
||||
return delegateProvider.getInputTypes();
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 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:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* Neither the name "TwelveMonkeys" 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 OWNER 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.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.jpeg;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* JPEGImageReaderTest
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: JPEGImageReaderTest.java,v 1.0 24.01.11 22.04 haraldk Exp$
|
||||
*/
|
||||
public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageReader> {
|
||||
|
||||
private static final JPEGImageReaderSpi SPI = new JPEGImageReaderSpi();
|
||||
|
||||
static {
|
||||
IIORegistry.getDefaultInstance().registerServiceProvider(SPI);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TestData> getTestData() {
|
||||
return Arrays.asList(
|
||||
// TODO: Create JPEG with broken profile from Anders' photos..
|
||||
new TestData(getClassLoaderResource("/jpeg/cmm-exception-adobe-rgb.jpg"), new Dimension(626, 76)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmm-exception-srgb.jpg"), new Dimension(1800, 1200)),
|
||||
new TestData(getClassLoaderResource("/jpeg/gray-sample.jpg"), new Dimension(386, 396)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmyk-sample.jpg"), new Dimension(160, 227)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmyk-sample-multiple-chunk-icc.jpg"), new Dimension(2707, 3804))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageReaderSpi createProvider() {
|
||||
return SPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JPEGImageReader createReader() {
|
||||
try {
|
||||
return (JPEGImageReader) SPI.createReaderInstance();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
protected Class<JPEGImageReader> getReaderClass() {
|
||||
return JPEGImageReader.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean allowsNullRawImageType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFormatNames() {
|
||||
return Arrays.asList("JPEG", "jpeg", "JPG", "jpg");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getSuffixes() {
|
||||
return Arrays.asList("jpeg", "jpg");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getMIMETypes() {
|
||||
return Arrays.asList("image/jpeg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetDestinationType() throws IOException {
|
||||
// TODO: This method currently fails, fix it
|
||||
super.testSetDestinationType();
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 633 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.9 MiB |
BIN
imageio/imageio-jpeg/src/test/resources/jpeg/cmyk-sample.jpg
Normal file
BIN
imageio/imageio-jpeg/src/test/resources/jpeg/cmyk-sample.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
BIN
imageio/imageio-jpeg/src/test/resources/jpeg/gray-sample.jpg
Normal file
BIN
imageio/imageio-jpeg/src/test/resources/jpeg/gray-sample.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
@ -14,7 +14,6 @@
|
||||
<packaging>pom</packaging>
|
||||
<name>TwelveMonkeys :: ImageIO</name>
|
||||
|
||||
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Harald Kuhr</name>
|
||||
@ -34,7 +33,8 @@
|
||||
<!-- Stand-alone readers/writers -->
|
||||
<module>imageio-ico</module>
|
||||
<module>imageio-iff</module>
|
||||
<module>imageio-pdf</module>
|
||||
<module>imageio-jpeg</module>
|
||||
<module>imageio-pdf</module>
|
||||
<module>imageio-pict</module>
|
||||
<module>imageio-psd</module>
|
||||
<module>imageio-thumbsdb</module>
|
||||
@ -100,7 +100,8 @@
|
||||
<artifactId>imageio-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>imageio-metadata</artifactId>
|
||||
<version>${project.version}</version>
|
||||
|
Loading…
x
Reference in New Issue
Block a user