mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -04:00
Major ImageMetadata refactor for more consistent standard metadata support.
Fixes a few related bugs as a bonus.
This commit is contained in:
@@ -1,184 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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 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.
|
||||
*/
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.webp;
|
||||
|
||||
import com.twelvemonkeys.imageio.AbstractMetadata;
|
||||
import com.twelvemonkeys.imageio.StandardImageMetadataSupport;
|
||||
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
|
||||
import static com.twelvemonkeys.lang.Validate.notNull;
|
||||
|
||||
/**
|
||||
* WebPMetadata
|
||||
*/
|
||||
final class WebPImageMetadata extends AbstractMetadata {
|
||||
private final VP8xChunk header;
|
||||
|
||||
WebPImageMetadata(final VP8xChunk header) {
|
||||
this.header = notNull(header, "header");
|
||||
final class WebPImageMetadata extends StandardImageMetadataSupport {
|
||||
WebPImageMetadata(ImageTypeSpecifier type, VP8xChunk header) {
|
||||
super(builder(type)
|
||||
.withCompressionName(notNull(header, "header").isLossless ? "VP8L" : "VP8")
|
||||
.withCompressionLossless(header.isLossless)
|
||||
.withPixelAspectRatio(1.0)
|
||||
.withFormatVersion("1.0")
|
||||
// TODO: Get useful text nodes from EXIF or XMP
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardChromaNode() {
|
||||
IIOMetadataNode chroma = new IIOMetadataNode("Chroma");
|
||||
|
||||
IIOMetadataNode csType = new IIOMetadataNode("ColorSpaceType");
|
||||
chroma.appendChild(csType);
|
||||
csType.setAttribute("name", "RGB");
|
||||
|
||||
// NOTE: Channels in chroma node reflects channels in color model (see data node, for channels in data)
|
||||
IIOMetadataNode numChannels = new IIOMetadataNode("NumChannels");
|
||||
chroma.appendChild(numChannels);
|
||||
numChannels.setAttribute("value", Integer.toString(header.containsALPH ? 4 : 3));
|
||||
|
||||
IIOMetadataNode blackIsZero = new IIOMetadataNode("BlackIsZero");
|
||||
chroma.appendChild(blackIsZero);
|
||||
blackIsZero.setAttribute("value", "TRUE");
|
||||
|
||||
return chroma;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardCompressionNode() {
|
||||
IIOMetadataNode node = new IIOMetadataNode("Compression");
|
||||
|
||||
IIOMetadataNode compressionTypeName = new IIOMetadataNode("CompressionTypeName");
|
||||
node.appendChild(compressionTypeName);
|
||||
|
||||
String value = header.isLossless ? "VP8L" : "VP8"; // TODO: Naming: VP8L and VP8 or WebP and WebP Lossless?
|
||||
compressionTypeName.setAttribute("value", value);
|
||||
|
||||
// TODO: VP8 + lossless alpha!
|
||||
IIOMetadataNode lossless = new IIOMetadataNode("Lossless");
|
||||
node.appendChild(lossless);
|
||||
lossless.setAttribute("value", header.isLossless ? "TRUE" : "FALSE");
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardDataNode() {
|
||||
IIOMetadataNode node = new IIOMetadataNode("Data");
|
||||
|
||||
// TODO: WebP seems to support planar as well?
|
||||
IIOMetadataNode planarConfiguration = new IIOMetadataNode("PlanarConfiguration");
|
||||
node.appendChild(planarConfiguration);
|
||||
planarConfiguration.setAttribute("value", "PixelInterleaved");
|
||||
|
||||
IIOMetadataNode sampleFormat = new IIOMetadataNode("SampleFormat");
|
||||
node.appendChild(sampleFormat);
|
||||
sampleFormat.setAttribute("value", "UnsignedIntegral");
|
||||
|
||||
IIOMetadataNode bitsPerSample = new IIOMetadataNode("BitsPerSample");
|
||||
node.appendChild(bitsPerSample);
|
||||
|
||||
bitsPerSample.setAttribute("value", createListValue(header.containsALPH ? 4 : 3, Integer.toString(8)));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
private String createListValue(final int itemCount, final String... values) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
if (buffer.length() > 0) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
|
||||
buffer.append(values[i % values.length]);
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardDimensionNode() {
|
||||
IIOMetadataNode dimension = new IIOMetadataNode("Dimension");
|
||||
|
||||
IIOMetadataNode imageOrientation = new IIOMetadataNode("ImageOrientation");
|
||||
dimension.appendChild(imageOrientation);
|
||||
imageOrientation.setAttribute("value", "Normal");
|
||||
|
||||
IIOMetadataNode pixelAspectRatio = new IIOMetadataNode("PixelAspectRatio");
|
||||
dimension.appendChild(pixelAspectRatio);
|
||||
pixelAspectRatio.setAttribute("value", "1.0");
|
||||
|
||||
return dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardDocumentNode() {
|
||||
IIOMetadataNode document = new IIOMetadataNode("Document");
|
||||
|
||||
IIOMetadataNode formatVersion = new IIOMetadataNode("FormatVersion");
|
||||
document.appendChild(formatVersion);
|
||||
formatVersion.setAttribute("value", "1.0");
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardTextNode() {
|
||||
IIOMetadataNode text = new IIOMetadataNode("Text");
|
||||
|
||||
// TODO: Get useful text nodes from EXIF or XMP
|
||||
// NOTE: Names corresponds to equivalent fields in TIFF
|
||||
|
||||
return text.hasChildNodes() ? text : null;
|
||||
}
|
||||
|
||||
// private void appendTextEntry(final IIOMetadataNode parent, final String keyword, final String value) {
|
||||
// if (value != null) {
|
||||
// IIOMetadataNode textEntry = new IIOMetadataNode("TextEntry");
|
||||
// parent.appendChild(textEntry);
|
||||
// textEntry.setAttribute("keyword", keyword);
|
||||
// textEntry.setAttribute("value", value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// No tiling
|
||||
|
||||
@Override
|
||||
protected IIOMetadataNode getStandardTransparencyNode() {
|
||||
if (header.containsALPH) {
|
||||
IIOMetadataNode transparency = new IIOMetadataNode("Transparency");
|
||||
IIOMetadataNode alpha = new IIOMetadataNode("Alpha");
|
||||
transparency.appendChild(alpha);
|
||||
alpha.setAttribute("value", "nonpremultiplied");
|
||||
return transparency;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: Define native WebP metadata format (probably use RIFF structure)
|
||||
}
|
||||
|
@@ -661,10 +661,7 @@ final class WebPImageReader extends ImageReaderBase {
|
||||
|
||||
@Override
|
||||
public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
|
||||
readHeader(imageIndex);
|
||||
readMeta();
|
||||
|
||||
return new WebPImageMetadata(header);
|
||||
return new WebPImageMetadata(getRawImageType(imageIndex), header);
|
||||
}
|
||||
|
||||
private void readMeta() throws IOException {
|
||||
|
@@ -1,11 +1,17 @@
|
||||
package com.twelvemonkeys.imageio.plugins.webp;
|
||||
|
||||
import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.function.ThrowingRunnable;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.metadata.IIOMetadataFormatImpl;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import java.awt.image.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -17,10 +23,14 @@ import static org.junit.Assert.*;
|
||||
* @version $Id: WebPImageMetadataTest.java,v 1.0 21/11/2020 haraldk Exp$
|
||||
*/
|
||||
public class WebPImageMetadataTest {
|
||||
|
||||
private static final ImageTypeSpecifier TYPE_3BYTE_BGR = ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_3BYTE_BGR);
|
||||
private static final ImageTypeSpecifier TYPE_4BYTE_ABGR = ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_4BYTE_ABGR);
|
||||
|
||||
@Test
|
||||
public void testStandardFeatures() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
final WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
final WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
// Standard metadata format
|
||||
assertTrue(metadata.isStandardMetadataFormatSupported());
|
||||
@@ -51,9 +61,9 @@ public class WebPImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardChromaRGB() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode chroma = metadata.getStandardChromaNode();
|
||||
IIOMetadataNode chroma = getStandardNode(metadata, "Chroma");
|
||||
assertNotNull(chroma);
|
||||
assertEquals("Chroma", chroma.getNodeName());
|
||||
assertEquals(3, chroma.getLength());
|
||||
@@ -77,9 +87,9 @@ public class WebPImageMetadataTest {
|
||||
public void testStandardChromaRGBA() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.containsALPH = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_4BYTE_ABGR, header);
|
||||
|
||||
IIOMetadataNode chroma = metadata.getStandardChromaNode();
|
||||
IIOMetadataNode chroma = getStandardNode(metadata, "Chroma");
|
||||
assertNotNull(chroma);
|
||||
assertEquals("Chroma", chroma.getNodeName());
|
||||
assertEquals(3, chroma.getLength());
|
||||
@@ -103,9 +113,9 @@ public class WebPImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardCompressionVP8() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
IIOMetadataNode compression = getStandardNode(metadata, "Compression");
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
@@ -125,9 +135,9 @@ public class WebPImageMetadataTest {
|
||||
public void testStandardCompressionVP8L() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8L, 27, 33);
|
||||
header.isLossless = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
IIOMetadataNode compression = getStandardNode(metadata, "Compression");
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
@@ -146,9 +156,9 @@ public class WebPImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardCompressionVP8X() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
IIOMetadataNode compression = getStandardNode(metadata, "Compression");
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
@@ -168,9 +178,9 @@ public class WebPImageMetadataTest {
|
||||
public void testStandardCompressionVP8XLossless() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.isLossless = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode compression = metadata.getStandardCompressionNode();
|
||||
IIOMetadataNode compression = getStandardNode(metadata, "Compression");
|
||||
assertNotNull(compression);
|
||||
assertEquals("Compression", compression.getNodeName());
|
||||
assertEquals(2, compression.getLength());
|
||||
@@ -189,9 +199,9 @@ public class WebPImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardDataRGB() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8_, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode data = metadata.getStandardDataNode();
|
||||
IIOMetadataNode data = getStandardNode(metadata, "Data");
|
||||
assertNotNull(data);
|
||||
assertEquals("Data", data.getNodeName());
|
||||
assertEquals(3, data.getLength());
|
||||
@@ -215,9 +225,9 @@ public class WebPImageMetadataTest {
|
||||
public void testStandardDataRGBA() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
header.containsALPH = true;
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_4BYTE_ABGR, header);
|
||||
|
||||
IIOMetadataNode data = metadata.getStandardDataNode();
|
||||
IIOMetadataNode data = getStandardNode(metadata, "Data");
|
||||
assertNotNull(data);
|
||||
assertEquals("Data", data.getNodeName());
|
||||
assertEquals(3, data.getLength());
|
||||
@@ -240,78 +250,109 @@ public class WebPImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardDimensionNormal() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode dimension = metadata.getStandardDimensionNode();
|
||||
IIOMetadataNode dimension = getStandardNode(metadata, "Dimension");
|
||||
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();
|
||||
IIOMetadataNode pixelAspectRatio = (IIOMetadataNode) dimension.getFirstChild();
|
||||
assertEquals("PixelAspectRatio", pixelAspectRatio.getNodeName());
|
||||
assertEquals("1.0", pixelAspectRatio.getAttribute("value"));
|
||||
|
||||
assertNull(pixelAspectRatio.getNextSibling()); // No more children
|
||||
IIOMetadataNode imageOrientation = (IIOMetadataNode) pixelAspectRatio.getNextSibling();
|
||||
assertEquals("ImageOrientation", imageOrientation.getNodeName());
|
||||
assertEquals("Normal", imageOrientation.getAttribute("value"));
|
||||
|
||||
assertNull(imageOrientation.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardDocument() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode document = metadata.getStandardDocumentNode();
|
||||
IIOMetadataNode document = getStandardNode(metadata, "Document");
|
||||
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"));
|
||||
IIOMetadataNode formatVersion = (IIOMetadataNode) document.getFirstChild();
|
||||
assertEquals("FormatVersion", formatVersion.getNodeName());
|
||||
assertEquals("1.0", formatVersion.getAttribute("value"));
|
||||
|
||||
assertNull(pixelAspectRatio.getNextSibling()); // No more children
|
||||
assertNull(formatVersion.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardText() {
|
||||
// No text node yet...
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTransparencyVP8() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode transparency = metadata.getStandardTransparencyNode();
|
||||
assertNull(transparency); // No transparency, just defaults
|
||||
IIOMetadataNode transparency = getStandardNode(metadata, "Transparency");
|
||||
|
||||
if (transparency != null) {
|
||||
assertNotNull(transparency);
|
||||
assertEquals("Transparency", transparency.getNodeName());
|
||||
assertEquals(1, transparency.getLength());
|
||||
|
||||
IIOMetadataNode alpha = (IIOMetadataNode) transparency.getFirstChild();
|
||||
assertEquals("Alpha", alpha.getNodeName());
|
||||
assertEquals("none", alpha.getAttribute("value"));
|
||||
|
||||
assertNull(alpha.getNextSibling()); // No more children
|
||||
}
|
||||
// Else no transparency, just defaults
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardTransparencyVP8L() {
|
||||
VP8xChunk header = new VP8xChunk(WebP.CHUNK_VP8X, 27, 33);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(header);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_3BYTE_BGR, header);
|
||||
|
||||
IIOMetadataNode transparency = metadata.getStandardTransparencyNode();
|
||||
assertNull(transparency); // No transparency, just defaults
|
||||
IIOMetadataNode transparency = getStandardNode(metadata, "Transparency");
|
||||
if (transparency != null) {
|
||||
assertNotNull(transparency);
|
||||
assertEquals("Transparency", transparency.getNodeName());
|
||||
assertEquals(1, transparency.getLength());
|
||||
|
||||
IIOMetadataNode alpha = (IIOMetadataNode) transparency.getFirstChild();
|
||||
assertEquals("Alpha", alpha.getNodeName());
|
||||
assertEquals("none", alpha.getAttribute("value"));
|
||||
|
||||
assertNull(alpha.getNextSibling()); // No more children
|
||||
}
|
||||
// Else 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);
|
||||
WebPImageMetadata metadata = new WebPImageMetadata(TYPE_4BYTE_ABGR, header);
|
||||
|
||||
IIOMetadataNode transparency = metadata.getStandardTransparencyNode();
|
||||
IIOMetadataNode transparency = getStandardNode(metadata, "Transparency");
|
||||
assertNotNull(transparency);
|
||||
assertEquals("Transparency", transparency.getNodeName());
|
||||
assertEquals(1, transparency.getLength());
|
||||
|
||||
IIOMetadataNode pixelAspectRatio = (IIOMetadataNode) transparency.getFirstChild();
|
||||
assertEquals("Alpha", pixelAspectRatio.getNodeName());
|
||||
assertEquals("nonpremultiplied", pixelAspectRatio.getAttribute("value"));
|
||||
IIOMetadataNode alpha = (IIOMetadataNode) transparency.getFirstChild();
|
||||
assertEquals("Alpha", alpha.getNodeName());
|
||||
assertEquals("nonpremultiplied", alpha.getAttribute("value"));
|
||||
|
||||
assertNull(pixelAspectRatio.getNextSibling()); // No more children
|
||||
assertNull(alpha.getNextSibling()); // No more children
|
||||
}
|
||||
|
||||
private IIOMetadataNode getStandardNode(IIOMetadata metadata, String nodeName) {
|
||||
IIOMetadataNode asTree = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
|
||||
NodeList nodes = asTree.getElementsByTagName(nodeName);
|
||||
|
||||
return nodes.getLength() > 0 ? (IIOMetadataNode) nodes.item(0) : null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user