mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-27 00:00:02 -04:00
Sonar issues + roll back accidental check-in
This commit is contained in:
@@ -393,81 +393,85 @@ public final class IIOUtil {
|
|||||||
Validate.isTrue(source != destination, "source must be different from destination");
|
Validate.isTrue(source != destination, "source must be different from destination");
|
||||||
|
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
destination.setController(source.getController());
|
copyIIOParams(source, destination);
|
||||||
destination.setSourceSubsampling(
|
|
||||||
source.getSourceXSubsampling(), source.getSourceYSubsampling(),
|
|
||||||
source.getSubsamplingXOffset(), source.getSubsamplingYOffset()
|
|
||||||
);
|
|
||||||
destination.setSourceRegion(source.getSourceRegion());
|
|
||||||
destination.setSourceBands(source.getSourceBands());
|
|
||||||
destination.setDestinationOffset(source.getDestinationOffset());
|
|
||||||
destination.setDestinationType(source.getDestinationType());
|
|
||||||
|
|
||||||
// TODO: API & usage... Is it ever useful to copy from a read to a write param or vice versa?
|
// TODO: API & usage... Is it ever useful to copy from a read to a write param or vice versa?
|
||||||
// If not, maybe throw an IllegalArgumentException instead
|
// If not, maybe throw an IllegalArgumentException instead
|
||||||
|
|
||||||
if (source instanceof ImageReadParam && destination instanceof ImageReadParam) {
|
if (source instanceof ImageReadParam && destination instanceof ImageReadParam) {
|
||||||
ImageReadParam sourceReadParam = (ImageReadParam) source;
|
copyImageReadParams((ImageReadParam) source, (ImageReadParam) destination);
|
||||||
ImageReadParam destinationReadParam = (ImageReadParam) destination;
|
|
||||||
|
|
||||||
destinationReadParam.setDestination(sourceReadParam.getDestination());
|
|
||||||
destinationReadParam.setDestinationBands(sourceReadParam.getDestinationBands());
|
|
||||||
|
|
||||||
if (destinationReadParam.canSetSourceRenderSize()) {
|
|
||||||
destinationReadParam.setSourceRenderSize(sourceReadParam.getSourceRenderSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
destinationReadParam.setSourceProgressivePasses(
|
|
||||||
sourceReadParam.getSourceMinProgressivePass(),
|
|
||||||
sourceReadParam.getSourceMaxProgressivePass()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof ImageWriteParam && destination instanceof ImageWriteParam) {
|
if (source instanceof ImageWriteParam && destination instanceof ImageWriteParam) {
|
||||||
ImageWriteParam sourceWriteParam = (ImageWriteParam) source;
|
copyImageWriteParams((ImageWriteParam) source, (ImageWriteParam) destination);
|
||||||
ImageWriteParam destinationWriteParam = (ImageWriteParam) destination;
|
|
||||||
|
|
||||||
// TODO: Usage... It's very unlikely that compression settings of one plugin is compatible with another...
|
|
||||||
// Is the the below useful?
|
|
||||||
// Also, is it okay to just silently ignore settings from one format that isn't compatible with another?
|
|
||||||
|
|
||||||
// Quirky API, we can't query for compression mode, unless source.canWriteCompressed is true...
|
|
||||||
if (sourceWriteParam.canWriteCompressed() && destinationWriteParam.canWriteCompressed()) {
|
|
||||||
int compressionMode = sourceWriteParam.getCompressionMode();
|
|
||||||
destinationWriteParam.setCompressionMode(compressionMode);
|
|
||||||
|
|
||||||
if (compressionMode == ImageWriteParam.MODE_EXPLICIT
|
|
||||||
&& sourceWriteParam.getCompressionType() != null) {
|
|
||||||
if (Arrays.asList(destinationWriteParam.getCompressionTypes())
|
|
||||||
.contains(sourceWriteParam.getCompressionType())) {
|
|
||||||
destinationWriteParam.setCompressionType(sourceWriteParam.getCompressionType());
|
|
||||||
destinationWriteParam.setCompressionQuality(sourceWriteParam.getCompressionQuality());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceWriteParam.canWriteProgressive() && destinationWriteParam.canWriteProgressive()) {
|
|
||||||
destinationWriteParam.setProgressiveMode(sourceWriteParam.getProgressiveMode());
|
|
||||||
}
|
|
||||||
if (sourceWriteParam.canWriteTiles() && destinationWriteParam.canWriteTiles()) {
|
|
||||||
int tilingMode = sourceWriteParam.getTilingMode();
|
|
||||||
destinationWriteParam.setTilingMode(tilingMode);
|
|
||||||
|
|
||||||
if (tilingMode == ImageWriteParam.MODE_EXPLICIT) {
|
|
||||||
// TODO: What if source can offset (and has offsets) and dest can't? Is it ok to just ignore the setting?
|
|
||||||
boolean canWriteOffsetTiles =
|
|
||||||
sourceWriteParam.canOffsetTiles() && destinationWriteParam.canOffsetTiles();
|
|
||||||
|
|
||||||
destinationWriteParam.setTiling(
|
|
||||||
sourceWriteParam.getTileWidth(), sourceWriteParam.getTileHeight(),
|
|
||||||
canWriteOffsetTiles ? sourceWriteParam.getTileGridXOffset() : 0,
|
|
||||||
canWriteOffsetTiles ? sourceWriteParam.getTileGridYOffset() : 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void copyImageWriteParams(ImageWriteParam source, ImageWriteParam destination) {
|
||||||
|
// TODO: Usage... It's very unlikely that compression settings of one plugin is compatible with another...
|
||||||
|
// Is the the below useful?
|
||||||
|
// Also, is it okay to just silently ignore settings from one format that isn't compatible with another?
|
||||||
|
|
||||||
|
// Quirky API, we can't query for compression mode, unless source.canWriteCompressed is true...
|
||||||
|
if (source.canWriteCompressed() && destination.canWriteCompressed()) {
|
||||||
|
int compressionMode = source.getCompressionMode();
|
||||||
|
destination.setCompressionMode(compressionMode);
|
||||||
|
|
||||||
|
if (compressionMode == ImageWriteParam.MODE_EXPLICIT
|
||||||
|
&& source.getCompressionType() != null
|
||||||
|
&& Arrays.asList(destination.getCompressionTypes()).contains(source.getCompressionType())) {
|
||||||
|
destination.setCompressionType(source.getCompressionType());
|
||||||
|
destination.setCompressionQuality(source.getCompressionQuality());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.canWriteProgressive() && destination.canWriteProgressive()) {
|
||||||
|
destination.setProgressiveMode(source.getProgressiveMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.canWriteTiles() && destination.canWriteTiles()) {
|
||||||
|
int tilingMode = source.getTilingMode();
|
||||||
|
destination.setTilingMode(tilingMode);
|
||||||
|
|
||||||
|
if (tilingMode == ImageWriteParam.MODE_EXPLICIT) {
|
||||||
|
// TODO: What if source can offset (and has offsets) and dest can't? Is it ok to just ignore the setting?
|
||||||
|
boolean canWriteOffsetTiles = source.canOffsetTiles() && destination.canOffsetTiles();
|
||||||
|
|
||||||
|
destination.setTiling(
|
||||||
|
source.getTileWidth(), source.getTileHeight(),
|
||||||
|
canWriteOffsetTiles ? source.getTileGridXOffset() : 0,
|
||||||
|
canWriteOffsetTiles ? source.getTileGridYOffset() : 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyImageReadParams(ImageReadParam source, ImageReadParam destination) {
|
||||||
|
destination.setDestination(source.getDestination());
|
||||||
|
destination.setDestinationBands(source.getDestinationBands());
|
||||||
|
|
||||||
|
if (destination.canSetSourceRenderSize()) {
|
||||||
|
destination.setSourceRenderSize(source.getSourceRenderSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
destination.setSourceProgressivePasses(
|
||||||
|
source.getSourceMinProgressivePass(),
|
||||||
|
source.getSourceMaxProgressivePass()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyIIOParams(IIOParam source, IIOParam destination) {
|
||||||
|
destination.setController(source.getController());
|
||||||
|
destination.setSourceSubsampling(
|
||||||
|
source.getSourceXSubsampling(), source.getSourceYSubsampling(),
|
||||||
|
source.getSubsamplingXOffset(), source.getSubsamplingYOffset()
|
||||||
|
);
|
||||||
|
destination.setSourceRegion(source.getSourceRegion());
|
||||||
|
destination.setSourceBands(source.getSourceBands());
|
||||||
|
destination.setDestinationOffset(source.getDestinationOffset());
|
||||||
|
destination.setDestinationType(source.getDestinationType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.twelvemonkeys.imageio.util;
|
package com.twelvemonkeys.imageio.util;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.function.Executable;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -219,8 +218,10 @@ public class IIOUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void copyStandardParamsDestinationNull() {
|
void copyStandardParamsDestinationNull() {
|
||||||
|
ImageReadParam param = new ImageReadParam();
|
||||||
|
|
||||||
assertThrows(NullPointerException.class, () -> IIOUtil.copyStandardParams(null, null));
|
assertThrows(NullPointerException.class, () -> IIOUtil.copyStandardParams(null, null));
|
||||||
assertThrows(NullPointerException.class, () -> IIOUtil.copyStandardParams(new ImageReadParam(), null));
|
assertThrows(NullPointerException.class, () -> IIOUtil.copyStandardParams(param, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+3
-2
@@ -177,8 +177,9 @@ enum DDSType {
|
|||||||
|
|
||||||
case DXGI.DXGI_FORMAT_BC5_SNORM:
|
case DXGI.DXGI_FORMAT_BC5_SNORM:
|
||||||
return BC5S;
|
return BC5S;
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unsupported DXGI_FORMAT: " + dxgiFormat);
|
default:
|
||||||
|
throw new IllegalArgumentException("Unsupported DXGI_FORMAT: " + dxgiFormat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-16
@@ -59,9 +59,7 @@ import com.twelvemonkeys.io.FileUtil;
|
|||||||
import com.twelvemonkeys.io.enc.DecoderStream;
|
import com.twelvemonkeys.io.enc.DecoderStream;
|
||||||
import com.twelvemonkeys.io.enc.PackBitsDecoder;
|
import com.twelvemonkeys.io.enc.PackBitsDecoder;
|
||||||
import com.twelvemonkeys.lang.StringUtil;
|
import com.twelvemonkeys.lang.StringUtil;
|
||||||
import com.twelvemonkeys.xml.XMLSerializer;
|
|
||||||
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
@@ -71,7 +69,6 @@ import javax.imageio.ImageReader;
|
|||||||
import javax.imageio.ImageTypeSpecifier;
|
import javax.imageio.ImageTypeSpecifier;
|
||||||
import javax.imageio.event.IIOReadWarningListener;
|
import javax.imageio.event.IIOReadWarningListener;
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
import javax.imageio.metadata.IIOMetadata;
|
||||||
import javax.imageio.metadata.IIOMetadataFormatImpl;
|
|
||||||
import javax.imageio.metadata.IIOMetadataNode;
|
import javax.imageio.metadata.IIOMetadataNode;
|
||||||
import javax.imageio.plugins.jpeg.JPEGImageReadParam;
|
import javax.imageio.plugins.jpeg.JPEGImageReadParam;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
@@ -2900,19 +2897,18 @@ public final class TIFFImageReader extends ImageReaderBase {
|
|||||||
BufferedImage image = reader.read(imageNo, param);
|
BufferedImage image = reader.read(imageNo, param);
|
||||||
System.err.println("Read time: " + (System.currentTimeMillis() - start) + " ms");
|
System.err.println("Read time: " + (System.currentTimeMillis() - start) + " ms");
|
||||||
|
|
||||||
IIOMetadata metadata = reader.getImageMetadata(imageNo);
|
// IIOMetadata metadata = reader.getImageMetadata(imageNo);
|
||||||
if (metadata != null) {
|
// if (metadata != null) {
|
||||||
if (metadata.getNativeMetadataFormatName() != null) {
|
// if (metadata.getNativeMetadataFormatName() != null) {
|
||||||
Node tree = metadata.getAsTree(metadata.getNativeMetadataFormatName());
|
// Node tree = metadata.getAsTree(metadata.getNativeMetadataFormatName());
|
||||||
replaceBytesWithUndefined((IIOMetadataNode) tree);
|
// replaceBytesWithUndefined((IIOMetadataNode) tree);
|
||||||
new XMLSerializer(System.out, "UTF-8").serialize(tree, false);
|
// new XMLSerializer(System.out, "UTF-8").serialize(tree, false);
|
||||||
}
|
// }
|
||||||
/*else*/
|
// /*else*/
|
||||||
if (metadata.isStandardMetadataFormatSupported()) {
|
// if (metadata.isStandardMetadataFormatSupported()) {
|
||||||
new XMLSerializer(System.out, "UTF-8").serialize(metadata.getAsTree(
|
// new XMLSerializer(System.out, "UTF-8").serialize(metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName), false);
|
||||||
IIOMetadataFormatImpl.standardMetadataFormatName), false);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
System.err.println("image: " + image);
|
System.err.println("image: " + image);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user