mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 19:15:29 -04:00
Better input validation.
This commit is contained in:
parent
25150b421c
commit
b563f573de
@ -1,13 +1,16 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.iff;
|
package com.twelvemonkeys.imageio.plugins.iff;
|
||||||
|
|
||||||
|
import com.twelvemonkeys.imageio.AbstractMetadata;
|
||||||
|
|
||||||
|
import javax.imageio.metadata.IIOMetadataNode;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.IndexColorModel;
|
import java.awt.image.IndexColorModel;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.imageio.metadata.IIOMetadataNode;
|
import static com.twelvemonkeys.imageio.plugins.iff.IFF.*;
|
||||||
|
import static com.twelvemonkeys.lang.Validate.isTrue;
|
||||||
import com.twelvemonkeys.imageio.AbstractMetadata;
|
import static com.twelvemonkeys.lang.Validate.notNull;
|
||||||
|
|
||||||
final class IFFImageMetadata extends AbstractMetadata {
|
final class IFFImageMetadata extends AbstractMetadata {
|
||||||
private final int formType;
|
private final int formType;
|
||||||
@ -17,13 +20,27 @@ final class IFFImageMetadata extends AbstractMetadata {
|
|||||||
private final List<GenericChunk> meta;
|
private final List<GenericChunk> meta;
|
||||||
|
|
||||||
IFFImageMetadata(int formType, BMHDChunk header, IndexColorModel colorMap, CAMGChunk viewPort, List<GenericChunk> meta) {
|
IFFImageMetadata(int formType, BMHDChunk header, IndexColorModel colorMap, CAMGChunk viewPort, List<GenericChunk> meta) {
|
||||||
this.formType = formType;
|
this.formType = isTrue(validFormType(formType), formType, "Unknown IFF Form type: %s");
|
||||||
this.header = header;
|
this.header = notNull(header, "header");
|
||||||
this.colorMap = colorMap;
|
this.colorMap = colorMap;
|
||||||
this.viewPort = viewPort;
|
this.viewPort = viewPort;
|
||||||
this.meta = meta;
|
this.meta = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean validFormType(int formType) {
|
||||||
|
switch (formType) {
|
||||||
|
case TYPE_ACBM:
|
||||||
|
case TYPE_DEEP:
|
||||||
|
case TYPE_ILBM:
|
||||||
|
case TYPE_PBM:
|
||||||
|
case TYPE_RGB8:
|
||||||
|
case TYPE_RGBN:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IIOMetadataNode getStandardChromaNode() {
|
protected IIOMetadataNode getStandardChromaNode() {
|
||||||
IIOMetadataNode chroma = new IIOMetadataNode("Chroma");
|
IIOMetadataNode chroma = new IIOMetadataNode("Chroma");
|
||||||
@ -128,10 +145,10 @@ final class IFFImageMetadata extends AbstractMetadata {
|
|||||||
// PlanarConfiguration
|
// PlanarConfiguration
|
||||||
IIOMetadataNode planarConfiguration = new IIOMetadataNode("PlanarConfiguration");
|
IIOMetadataNode planarConfiguration = new IIOMetadataNode("PlanarConfiguration");
|
||||||
switch (formType) {
|
switch (formType) {
|
||||||
case IFF.TYPE_PBM:
|
case TYPE_PBM:
|
||||||
planarConfiguration.setAttribute("value", "PixelInterleaved");
|
planarConfiguration.setAttribute("value", "PixelInterleaved");
|
||||||
break;
|
break;
|
||||||
case IFF.TYPE_ILBM:
|
case TYPE_ILBM:
|
||||||
planarConfiguration.setAttribute("value", "PlaneInterleaved");
|
planarConfiguration.setAttribute("value", "PlaneInterleaved");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user