mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 11:35:29 -04:00
- Added reference module with test cases for JDK-provided readers
- Fixed ThumbsDBImageReader to pass test cases (got rid of some errouneous caching) - Added TODO to remove caching in ICOImageReader (will need a test case for that) - Minor changes in test cases to allow the reference test cases to pass
This commit is contained in:
parent
1221a8bebc
commit
359659dc36
@ -1206,12 +1206,18 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
catch (IIOException expected) {
|
||||
// TODO: This is thrown by ImageReader.getDestination. But are we happy with that?
|
||||
// The problem is that the checkReadParamBandSettings throws IllegalArgumentException, which seems more appropriate...
|
||||
String message = expected.getMessage();
|
||||
assertTrue("Wrong message: " + message, message.toLowerCase().contains("destination"));
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue(
|
||||
"Wrong message: " + message + " for type " + destination.getType(),
|
||||
message.contains("destination") ||
|
||||
((destination.getType() == BufferedImage.TYPE_BYTE_BINARY ||
|
||||
destination.getType() == BufferedImage.TYPE_BYTE_INDEXED)
|
||||
&& message.contains("indexcolormodel"))
|
||||
);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
String message = expected.getMessage();
|
||||
assertTrue("Wrong message: " + message, message.toLowerCase().contains("dest"));
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue("Wrong message: " + message, message.contains("dest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1233,14 +1239,14 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
}
|
||||
catch (IIOException expected) {
|
||||
// TODO: This is thrown by ImageReader.getDestination. But are we happy with that?
|
||||
String message = expected.getMessage();
|
||||
assertTrue(message.toLowerCase().contains("destination"));
|
||||
assertTrue(message.toLowerCase().contains("type"));
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue(message.contains("destination"));
|
||||
assertTrue(message.contains("type"));
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
String message = expected.getMessage();
|
||||
assertTrue(message.toLowerCase().contains("destination"));
|
||||
assertTrue(message.toLowerCase().contains("type"));
|
||||
String message = expected.getMessage().toLowerCase();
|
||||
assertTrue(message.contains("destination"));
|
||||
assertTrue(message.contains("type"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1272,13 +1278,14 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
}
|
||||
|
||||
// TODO: Test dest offset + destination set?
|
||||
// TODO: Test that destination offset is used for image data, not just image dimensions...
|
||||
public void testSetDestinationOffset() throws IOException {
|
||||
final ImageReader reader = createReader();
|
||||
TestData data = getTestData().get(0);
|
||||
reader.setInput(data.getInputStream());
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
Point point = new Point(10, 10);
|
||||
Point point = new Point(37, 42);
|
||||
param.setDestinationOffset(point);
|
||||
|
||||
BufferedImage image = reader.read(0, param);
|
||||
|
@ -292,6 +292,7 @@ public class ICOImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
private BufferedImage readBitmap(final DirectoryEntry pEntry) throws IOException {
|
||||
// TODO: Get rid of the caching, as the images are mutable
|
||||
BitmapDescriptor descriptor = mDescriptors.get(pEntry);
|
||||
|
||||
if (descriptor == null || !mDescriptors.containsKey(pEntry)) {
|
||||
|
@ -41,6 +41,8 @@
|
||||
<!-- Wrappers for 3rd party libs -->
|
||||
<module>batik</module>
|
||||
<module>jmagick</module>
|
||||
|
||||
<module>reference</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
25
twelvemonkeys-imageio/reference/license.txt
Normal file
25
twelvemonkeys-imageio/reference/license.txt
Normal file
@ -0,0 +1,25 @@
|
||||
Copyright (c) 2009, 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.
|
31
twelvemonkeys-imageio/reference/pom.xml
Normal file
31
twelvemonkeys-imageio/reference/pom.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?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>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>twelvemonkeys-imageio-reference</artifactId>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
<name>TwelveMonkeys ImageIO reference test cases</name>
|
||||
<description>
|
||||
Test cases for the JDK provided ImageReader implementations for reference.
|
||||
</description>
|
||||
|
||||
<parent>
|
||||
<artifactId>twelvemonkeys-imageio</artifactId>
|
||||
<groupId>com.twelvemonkeys</groupId>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>twelvemonkeys-imageio-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>twelvemonkeys-imageio-core</artifactId>
|
||||
<classifier>tests</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,91 @@
|
||||
package com.twelvemonkeys.imageio.reference;
|
||||
|
||||
import com.sun.imageio.plugins.jpeg.JPEGImageReader;
|
||||
import com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||
import com.twelvemonkeys.lang.SystemUtil;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* JPEGImageReaderTestCase
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: JPEGImageReaderTestCase.java,v 1.0 Oct 9, 2009 3:37:25 PM haraldk Exp$
|
||||
*/
|
||||
public class JPEGImageReaderTestCase extends ImageReaderAbstractTestCase<JPEGImageReader> {
|
||||
private static final boolean IS_JAVA_6 = SystemUtil.isClassAvailable("java.util.Deque");
|
||||
|
||||
protected JPEGImageReaderSpi mProvider = new JPEGImageReaderSpi();
|
||||
|
||||
@Override
|
||||
protected List<TestData> getTestData() {
|
||||
return Arrays.asList(
|
||||
new TestData(getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"), new Dimension(386, 396))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageReaderSpi createProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<JPEGImageReader> getReaderClass() {
|
||||
return JPEGImageReader.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JPEGImageReader createReader() {
|
||||
try {
|
||||
return (JPEGImageReader) mProvider.createReaderInstance();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// These are NOT correct implementations, but I don't really care here
|
||||
@Override
|
||||
protected List<String> getFormatNames() {
|
||||
return Arrays.asList(mProvider.getFormatNames());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getSuffixes() {
|
||||
return Arrays.asList(mProvider.getFileSuffixes());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getMIMETypes() {
|
||||
return Arrays.asList(mProvider.getMIMETypes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetDestination() throws IOException {
|
||||
// Known bug in Sun JPEGImageReader before Java 6
|
||||
if (IS_JAVA_6) {
|
||||
super.testSetDestination();
|
||||
}
|
||||
else {
|
||||
System.err.println("WARNING: Test skipped due to known bug in Java 1.5, please test again with Java 6 or later");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetDestinationType() throws IOException {
|
||||
// Known bug in Sun JPEGImageReader before Java 6
|
||||
if (IS_JAVA_6) {
|
||||
super.testSetDestinationType();
|
||||
}
|
||||
else {
|
||||
System.err.println("WARNING: Test skipped due to known bug in Java 1.5, please test again with Java 6 or later");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.twelvemonkeys.imageio.reference;
|
||||
|
||||
import com.sun.imageio.plugins.png.PNGImageReader;
|
||||
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PNGImageReaderTestCase
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: PNGImageReaderTestCase.java,v 1.0 Oct 9, 2009 3:37:25 PM haraldk Exp$
|
||||
*/
|
||||
public class PNGImageReaderTestCase extends ImageReaderAbstractTestCase<PNGImageReader> {
|
||||
protected PNGImageReaderSpi mProvider = new PNGImageReaderSpi();
|
||||
|
||||
@Override
|
||||
protected List<TestData> getTestData() {
|
||||
return Arrays.asList(
|
||||
new TestData(getClassLoaderResource("/png/12monkeys-splash.png"), new Dimension(300, 410))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageReaderSpi createProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<PNGImageReader> getReaderClass() {
|
||||
return PNGImageReader.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PNGImageReader createReader() {
|
||||
try {
|
||||
return (PNGImageReader) mProvider.createReaderInstance();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// These are NOT correct implementations, but I don't really care here
|
||||
@Override
|
||||
protected List<String> getFormatNames() {
|
||||
return Arrays.asList(mProvider.getFormatNames());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getSuffixes() {
|
||||
return Arrays.asList(mProvider.getFileSuffixes());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getMIMETypes() {
|
||||
return Arrays.asList(mProvider.getMIMETypes());
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
twelvemonkeys-imageio/reference/src/test/resources/png/12monkeys-splash.png
Executable file
BIN
twelvemonkeys-imageio/reference/src/test/resources/png/12monkeys-splash.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
36
twelvemonkeys-imageio/thumbsdb/src/main/java/com/twelvemonkeys/imageio/plugins/thumbsdb/ThumbsDBImageReader.java
Executable file → Normal file
36
twelvemonkeys-imageio/thumbsdb/src/main/java/com/twelvemonkeys/imageio/plugins/thumbsdb/ThumbsDBImageReader.java
Executable file → Normal file
@ -80,6 +80,7 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
protected ThumbsDBImageReader(final ThumbsDBImageReaderSpi pProvider) {
|
||||
super(pProvider);
|
||||
mReader = createJPEGReader(pProvider);
|
||||
initReaderListeners();
|
||||
}
|
||||
|
||||
protected void resetMembers() {
|
||||
@ -128,11 +129,11 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
* @throws java.io.IOException if an error occurs during reading
|
||||
*/
|
||||
@Override
|
||||
public BufferedImage read(int pIndex, ImageReadParam pParam) throws IOException {
|
||||
public BufferedImage read(final int pIndex, final ImageReadParam pParam) throws IOException {
|
||||
init();
|
||||
checkBounds(pIndex);
|
||||
|
||||
// Quick lookup
|
||||
// Quick look-up
|
||||
BufferedImage image = null;
|
||||
if (pIndex < mThumbnails.length) {
|
||||
image = mThumbnails[pIndex];
|
||||
@ -145,7 +146,9 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
image = mReader.read(0, pParam);
|
||||
mReader.reset();
|
||||
|
||||
mThumbnails[pIndex] = image;
|
||||
if (pParam == null) {
|
||||
mThumbnails[pIndex] = image; // TODO: Caching is not kosher, as images are mutable!!
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Keep progress listeners happy
|
||||
@ -154,6 +157,23 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
processImageComplete();
|
||||
}
|
||||
|
||||
// Fake destination support
|
||||
if (pParam != null && (pParam.getDestination() != null && pParam.getDestination() != image ||
|
||||
pParam.getDestinationType() != null && pParam.getDestinationType().getBufferedImageType() != image.getType())) {
|
||||
BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), getWidth(pIndex), getHeight(pIndex));
|
||||
|
||||
Graphics2D g = destination.createGraphics();
|
||||
try {
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.drawImage(image, 0, 0, null);
|
||||
}
|
||||
finally {
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
image = destination;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -195,7 +215,7 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
private void init(final int pIndex) throws IOException {
|
||||
if (mCurrentImage == -1 || pIndex != mCurrentImage) {
|
||||
if (mCurrentImage == -1 || pIndex != mCurrentImage || mReader.getInput() == null) {
|
||||
init();
|
||||
checkBounds(pIndex);
|
||||
mCurrentImage = pIndex;
|
||||
@ -212,11 +232,9 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
ImageInputStream input = new MemoryCacheImageInputStream(entry.getInputStream());
|
||||
input.skipBytes(THUMBNAIL_OFFSET);
|
||||
mReader.setInput(input);
|
||||
initReaderListeners();
|
||||
}
|
||||
|
||||
private void initReaderListeners() {
|
||||
if (progressListeners != null) {
|
||||
mReader.addIIOReadProgressListener(new ProgressListenerBase() {
|
||||
@Override
|
||||
public void imageComplete(ImageReader pSource) {
|
||||
@ -238,14 +256,9 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
processReadAborted();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (updateListeners != null) {
|
||||
// TODO: Update listeners
|
||||
}
|
||||
if (warningListeners != null) {
|
||||
// TODO: Warning listeners
|
||||
}
|
||||
}
|
||||
|
||||
private void init() throws IOException {
|
||||
assertInput();
|
||||
@ -307,6 +320,7 @@ public class ThumbsDBImageReader extends ImageReaderBase {
|
||||
|
||||
public Iterator<ImageTypeSpecifier> getImageTypes(int pIndex) throws IOException {
|
||||
init(pIndex);
|
||||
initReader(pIndex);
|
||||
return mReader.getImageTypes(0);
|
||||
}
|
||||
|
||||
|
25
twelvemonkeys-imageio/thumbsdb/src/test/java/com/twelvemonkeys/imageio/plugins/thumbsdb/ThumbsDBImageReaderTestCase.java
Executable file → Normal file
25
twelvemonkeys-imageio/thumbsdb/src/test/java/com/twelvemonkeys/imageio/plugins/thumbsdb/ThumbsDBImageReaderTestCase.java
Executable file → Normal file
@ -32,6 +32,7 @@ import com.twelvemonkeys.imageio.stream.BufferedImageInputStream;
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||
import com.twelvemonkeys.io.ole2.CompoundDocument;
|
||||
import com.twelvemonkeys.io.ole2.Entry;
|
||||
import com.twelvemonkeys.lang.SystemUtil;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
@ -50,6 +51,8 @@ import java.util.List;
|
||||
* @version $Id: ICOImageReaderTestCase.java,v 1.0 Apr 1, 2008 10:39:17 PM haraldk Exp$
|
||||
*/
|
||||
public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<ThumbsDBImageReader> {
|
||||
private static final boolean IS_JAVA_6 = SystemUtil.isClassAvailable("java.util.Deque");
|
||||
|
||||
private ThumbsDBImageReaderSpi mProvider = new ThumbsDBImageReaderSpi();
|
||||
|
||||
protected List<TestData> getTestData() {
|
||||
@ -111,4 +114,26 @@ public class ThumbsDBImageReaderTestCase extends ImageReaderAbstractTestCase<Thu
|
||||
Entry child = root.getChildEntry("Catalog");
|
||||
child.getInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetDestination() throws IOException {
|
||||
// Known bug in Sun JPEGImageReader before Java 6
|
||||
if (IS_JAVA_6) {
|
||||
super.testSetDestination();
|
||||
}
|
||||
else {
|
||||
System.err.println("WARNING: Test skipped due to known bug in Java 1.5, please test again with Java 6 or later");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetDestinationType() throws IOException {
|
||||
// Known bug in Sun JPEGImageReader before Java 6
|
||||
if (IS_JAVA_6) {
|
||||
super.testSetDestinationType();
|
||||
}
|
||||
else {
|
||||
System.err.println("WARNING: Test skipped due to known bug in Java 1.5, please test again with Java 6 or later");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user