WebP initial commit
@@ -0,0 +1,317 @@
|
||||
package com.twelvemonkeys.imageio.plugins.webp;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import javax.imageio.metadata.IIOMetadataFormatImpl;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* WebPImageMetadataTest.
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: WebPImageMetadataTest.java,v 1.0 21/11/2020 haraldk Exp$
|
||||
*/
|
||||
public class WebPImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardFeatures() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
final WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
// Standard metadata format
|
||||
assertTrue(metadata.isStandardMetadataFormatSupported());
|
||||
Node root = metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
|
||||
assertNotNull(root);
|
||||
assertTrue(root instanceof IIOMetadataNode);
|
||||
|
||||
// Other formats
|
||||
assertNull(metadata.getNativeMetadataFormatName());
|
||||
assertNull(metadata.getExtraMetadataFormatNames());
|
||||
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
metadata.getAsTree("com_foo_bar_1.0");
|
||||
}
|
||||
});
|
||||
|
||||
// Read-only
|
||||
assertTrue(metadata.isReadOnly());
|
||||
assertThrows(IllegalStateException.class, new ThrowingRunnable() {
|
||||
@Override
|
||||
public void run() throws Throwable {
|
||||
metadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardChromaRGB() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode chroma = metadata.getStandardChromaNode();
|
||||
assertNotNull(chroma);
|
||||
assertEquals("Chroma", chroma.getNodeName());
|
||||
assertEquals(3, chroma.getLength());
|
||||
|
||||
IIOMetadataNode colorSpaceType = (IIOMetadataNode) chroma.getFirstChild();
|
||||
assertEquals("ColorSpaceType", colorSpaceType.getNodeName());
|
||||
assertEquals("RGB", colorSpaceType.getAttribute("name"));
|
||||
|
||||
IIOMetadataNode numChannels = (IIOMetadataNode) colorSpaceType.getNextSibling();
|
||||
assertEquals("NumChannels", numChannels.getNodeName());
|
||||
assertEquals("3", numChannels.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode blackIsZero = (IIOMetadataNode) numChannels.getNextSibling();
|
||||
assertEquals("BlackIsZero", blackIsZero.getNodeName());
|
||||
assertEquals("TRUE", blackIsZero.getAttribute("value"));
|
||||
|
||||
assertNull(blackIsZero.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardChromaRGBA() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.containsALPH = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode chroma = metadata.getStandardChromaNode();
|
||||
assertNotNull(chroma);
|
||||
assertEquals("Chroma", chroma.getNodeName());
|
||||
assertEquals(3, chroma.getLength());
|
||||
|
||||
IIOMetadataNode colorSpaceType = (IIOMetadataNode) chroma.getFirstChild();
|
||||
assertEquals("ColorSpaceType", colorSpaceType.getNodeName());
|
||||
assertEquals("RGB", colorSpaceType.getAttribute("name"));
|
||||
|
||||
IIOMetadataNode numChannels = (IIOMetadataNode) colorSpaceType.getNextSibling();
|
||||
assertEquals("NumChannels", numChannels.getNodeName());
|
||||
assertEquals("4", numChannels.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode blackIsZero = (IIOMetadataNode) numChannels.getNextSibling();
|
||||
assertEquals("BlackIsZero", blackIsZero.getNodeName());
|
||||
assertEquals("TRUE", blackIsZero.getAttribute("value"));
|
||||
|
||||
assertNull(blackIsZero.getNextSibling());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardCompressionVP8() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
|
||||
IIOMetadataNode compressionTypeName = (IIOMetadataNode) compression.getFirstChild();
|
||||
assertEquals("CompressionTypeName", compressionTypeName.getNodeName());
|
||||
assertEquals("VP8", compressionTypeName.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode lossless = (IIOMetadataNode) compressionTypeName.getNextSibling();
|
||||
assertEquals("Lossless", lossless.getNodeName());
|
||||
assertEquals("FALSE", lossless.getAttribute("value"));
|
||||
|
||||
assertNull(lossless.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardCompressionVP8L() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8L, 27, 33);
|
||||
header.isLossless = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
|
||||
IIOMetadataNode compressionTypeName = (IIOMetadataNode) compression.getFirstChild();
|
||||
assertEquals("CompressionTypeName", compressionTypeName.getNodeName());
|
||||
assertEquals("VP8L", compressionTypeName.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode lossless = (IIOMetadataNode) compressionTypeName.getNextSibling();
|
||||
assertEquals("Lossless", lossless.getNodeName());
|
||||
assertEquals("TRUE", lossless.getAttribute("value"));
|
||||
|
||||
assertNull(lossless.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardCompressionVP8X() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
|
||||
IIOMetadataNode compressionTypeName = (IIOMetadataNode) compression.getFirstChild();
|
||||
assertEquals("CompressionTypeName", compressionTypeName.getNodeName());
|
||||
assertEquals("VP8", compressionTypeName.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode lossless = (IIOMetadataNode) compressionTypeName.getNextSibling();
|
||||
assertEquals("Lossless", lossless.getNodeName());
|
||||
assertEquals("FALSE", lossless.getAttribute("value"));
|
||||
|
||||
assertNull(lossless.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardCompressionVP8XLossless() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.isLossless = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
|
||||
IIOMetadataNode compressionTypeName = (IIOMetadataNode) compression.getFirstChild();
|
||||
assertEquals("CompressionTypeName", compressionTypeName.getNodeName());
|
||||
assertEquals("VP8L", compressionTypeName.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode lossless = (IIOMetadataNode) compressionTypeName.getNextSibling();
|
||||
assertEquals("Lossless", lossless.getNodeName());
|
||||
assertEquals("TRUE", lossless.getAttribute("value"));
|
||||
|
||||
assertNull(lossless.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardDataRGB() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode data = metadata.getStandardDataNode();
|
||||
assertNotNull(data);
|
||||
assertEquals("Data", data.getNodeName());
|
||||
assertEquals(3, data.getLength());
|
||||
|
||||
IIOMetadataNode planarConfiguration = (IIOMetadataNode) data.getFirstChild();
|
||||
assertEquals("PlanarConfiguration", planarConfiguration.getNodeName());
|
||||
assertEquals("PixelInterleaved", planarConfiguration.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode sampleFomat = (IIOMetadataNode) planarConfiguration.getNextSibling();
|
||||
assertEquals("SampleFormat", sampleFomat.getNodeName());
|
||||
assertEquals("UnsignedIntegral", sampleFomat.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode bitsPerSample = (IIOMetadataNode) sampleFomat.getNextSibling();
|
||||
assertEquals("BitsPerSample", bitsPerSample.getNodeName());
|
||||
assertEquals("8 8 8", bitsPerSample.getAttribute("value"));
|
||||
|
||||
assertNull(bitsPerSample.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardDataRGBA() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.containsALPH = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode data = metadata.getStandardDataNode();
|
||||
assertNotNull(data);
|
||||
assertEquals("Data", data.getNodeName());
|
||||
assertEquals(3, data.getLength());
|
||||
|
||||
IIOMetadataNode planarConfiguration = (IIOMetadataNode) data.getFirstChild();
|
||||
assertEquals("PlanarConfiguration", planarConfiguration.getNodeName());
|
||||
assertEquals("PixelInterleaved", planarConfiguration.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode sampleFomat = (IIOMetadataNode) planarConfiguration.getNextSibling();
|
||||
assertEquals("SampleFormat", sampleFomat.getNodeName());
|
||||
assertEquals("UnsignedIntegral", sampleFomat.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode bitsPerSample = (IIOMetadataNode) sampleFomat.getNextSibling();
|
||||
assertEquals("BitsPerSample", bitsPerSample.getNodeName());
|
||||
assertEquals("8 8 8 8", bitsPerSample.getAttribute("value"));
|
||||
|
||||
assertNull(bitsPerSample.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardDimensionNormal() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode dimension = metadata.getStandardDimensionNode();
|
||||
assertNotNull(dimension);
|
||||
assertEquals("Dimension", dimension.getNodeName());
|
||||
assertEquals(2, dimension.getLength());
|
||||
|
||||
IIOMetadataNode imageOrientation = (IIOMetadataNode) dimension.getFirstChild();
|
||||
assertEquals("ImageOrientation", imageOrientation.getNodeName());
|
||||
assertEquals("Normal", imageOrientation.getAttribute("value"));
|
||||
|
||||
IIOMetadataNode pixelAspectRatio = (IIOMetadataNode) imageOrientation.getNextSibling();
|
||||
assertEquals("PixelAspectRatio", pixelAspectRatio.getNodeName());
|
||||
assertEquals("1.0", pixelAspectRatio.getAttribute("value"));
|
||||
|
||||
assertNull(pixelAspectRatio.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardDocument() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode document = metadata.getStandardDocumentNode();
|
||||
assertNotNull(document);
|
||||
assertEquals("Document", document.getNodeName());
|
||||
assertEquals(1, document.getLength());
|
||||
|
||||
IIOMetadataNode pixelAspectRatio = (IIOMetadataNode) document.getFirstChild();
|
||||
assertEquals("FormatVersion", pixelAspectRatio.getNodeName());
|
||||
assertEquals("1.0", pixelAspectRatio.getAttribute("value"));
|
||||
|
||||
assertNull(pixelAspectRatio.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardText() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTransparencyVP8() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode transparency = metadata.getStandardTransparencyNode();
|
||||
assertNull(transparency); // No transparency, just defaults
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTransparencyVP8L() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode transparency = metadata.getStandardTransparencyNode();
|
||||
assertNull(transparency); // No transparency, just defaults
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTransparencyVP8X() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.containsALPH = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
|
||||
IIOMetadataNode transparency = metadata.getStandardTransparencyNode();
|
||||
assertNotNull(transparency);
|
||||
assertEquals("Transparency", transparency.getNodeName());
|
||||
assertEquals(1, transparency.getLength());
|
||||
|
||||
IIOMetadataNode pixelAspectRatio = (IIOMetadataNode) transparency.getFirstChild();
|
||||
assertEquals("Alpha", pixelAspectRatio.getNodeName());
|
||||
assertEquals("nonpremultiplied", pixelAspectRatio.getAttribute("value"));
|
||||
|
||||
assertNull(pixelAspectRatio.getNextSibling()); // No more children
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.twelvemonkeys.imageio.plugins.webp;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* WebPImageReaderTest
|
||||
*/
|
||||
public class WebPImageReaderTest extends ImageReaderAbstractTest<WebPImageReader> {
|
||||
|
||||
@Override
|
||||
protected List<TestData> getTestData() {
|
||||
return asList(
|
||||
// Original Google WebP sample files
|
||||
new TestData(getClassLoaderResource("/webp/1.webp"), new Dimension(550, 368)),
|
||||
new TestData(getClassLoaderResource("/webp/5.webp"), new Dimension(1024, 752)),
|
||||
// Various samples from javavp8codec project
|
||||
new TestData(getClassLoaderResource("/webp/bug3.webp"), new Dimension(95, 95)),
|
||||
new TestData(getClassLoaderResource("/webp/segment01.webp"), new Dimension(160, 160)),
|
||||
new TestData(getClassLoaderResource("/webp/segment02.webp"), new Dimension(160, 160)),
|
||||
new TestData(getClassLoaderResource("/webp/segment03.webp"), new Dimension(160, 160)),
|
||||
new TestData(getClassLoaderResource("/webp/small_1x1.webp"), new Dimension(1, 1)),
|
||||
new TestData(getClassLoaderResource("/webp/small_1x13.webp"), new Dimension(1, 13)),
|
||||
new TestData(getClassLoaderResource("/webp/small_13x1.webp"), new Dimension(13, 1)),
|
||||
new TestData(getClassLoaderResource("/webp/small_31x13.webp"), new Dimension(31, 13)),
|
||||
new TestData(getClassLoaderResource("/webp/test.webp"), new Dimension(128, 128)),
|
||||
new TestData(getClassLoaderResource("/webp/very_short.webp"), new Dimension(63, 66)),
|
||||
// Lossless
|
||||
new TestData(getClassLoaderResource("/webp/1_webp_ll.webp"), new Dimension(400, 301)),
|
||||
// Extended format: Alpha + VP8
|
||||
new TestData(getClassLoaderResource("/webp/1_webp_a.webp"), new Dimension(400, 301)),
|
||||
// Extendad format: Anim
|
||||
new TestData(getClassLoaderResource("/webp/animated-webp-supported.webp"), new Dimension(400, 400))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageReaderSpi createProvider() {
|
||||
return new WebPImageReaderSpi();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFormatNames() {
|
||||
return asList("webp", "WEBP");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getSuffixes() {
|
||||
return asList("wbp", "webp");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getMIMETypes() {
|
||||
return asList("image/webp", "image/x-webp");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.twelvemonkeys.imageio.plugins.webp;
|
||||
|
||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfoTest;
|
||||
|
||||
/**
|
||||
* WebPProviderInfoTest.
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: WebPProviderInfoTest.java,v 1.0 21/11/2020 haraldk Exp$
|
||||
*/
|
||||
public class WebPProviderInfoTest extends ReaderWriterProviderInfoTest {
|
||||
@Override
|
||||
protected ReaderWriterProviderInfo createProviderInfo() {
|
||||
return new WebPProviderInfo();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 954 B |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 106 B |
|
After Width: | Height: | Size: 94 B |
|
After Width: | Height: | Size: 106 B |
|
After Width: | Height: | Size: 262 B |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 86 B |