diff --git a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java index 75b77683..c59b18e7 100644 --- a/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java +++ b/imageio/imageio-core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTest.java @@ -1391,6 +1391,8 @@ public abstract class ImageReaderAbstractTest { public void testSetDestination() throws IOException { ImageReader reader = createReader(); TestData data = getTestData().get(0); + Dimension size = data.getDimension(0); + reader.setInput(data.getInputStream()); ImageReadParam param = reader.getDefaultReadParam(); @@ -1398,7 +1400,7 @@ public abstract class ImageReaderAbstractTest { while (types.hasNext()) { ImageTypeSpecifier type = types.next(); - BufferedImage destination = type.createBufferedImage(50, 50); + BufferedImage destination = type.createBufferedImage(size.width, size.height); param.setDestination(destination); BufferedImage result = null; @@ -1448,13 +1450,15 @@ public abstract class ImageReaderAbstractTest { public void testSetDestinationIllegal() throws IOException { final ImageReader reader = createReader(); TestData data = getTestData().get(0); + Dimension size = data.getDimension(0); + reader.setInput(data.getInputStream()); List illegalTypes = createIllegalTypes(reader.getImageTypes(0)); ImageReadParam param = reader.getDefaultReadParam(); for (ImageTypeSpecifier illegalType : illegalTypes) { - BufferedImage destination = illegalType.createBufferedImage(50, 50); + BufferedImage destination = illegalType.createBufferedImage(size.width, size.height); param.setDestination(destination); try { @@ -1755,11 +1759,12 @@ public abstract class ImageReaderAbstractTest { ImageReader reader = createReader(); for (TestData testData : getTestDataForAffineTransformOpCompatibility()) { + Dimension size = testData.getDimension(0); try (ImageInputStream input = testData.getInputStream()) { reader.setInput(input); ImageReadParam param = reader.getDefaultReadParam(); - param.setSourceRegion(new Rectangle(min(reader.getWidth(0), 64), min(reader.getHeight(0), 64))); + param.setSourceRegion(new Rectangle(size.width, size.height)); BufferedImage originalImage = reader.read(0, param); diff --git a/imageio/imageio-dds/license.txt b/imageio/imageio-dds/license.txt new file mode 100755 index 00000000..11c975a1 --- /dev/null +++ b/imageio/imageio-dds/license.txt @@ -0,0 +1,52 @@ +Copyright (c) 2024, 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. + + +Parts of this software is based on DDSReader by Kenji Sasaki: + +The MIT License (MIT) + +Copyright (c) 2015 Kenji Sasaki + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSHeader.java b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSHeader.java index 6a2090b5..95b98fd8 100644 --- a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSHeader.java +++ b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSHeader.java @@ -23,14 +23,14 @@ final class DDSHeader { private int blueMask; private int alphaMask; - public static DDSHeader read(final ImageInputStream imageInput) throws IOException { + static DDSHeader read(final ImageInputStream imageInput) throws IOException { DDSHeader header = new DDSHeader(); // Read MAGIC bytes [0,3] byte[] magic = new byte[DDS.MAGIC.length]; imageInput.readFully(magic); if (!Arrays.equals(DDS.MAGIC, magic)) { - throw new IIOException(String.format("Not a DDS file. Expected DDS magic %08x, read %08x", new BigInteger(1, DDS.MAGIC), new BigInteger(1, magic))); + throw new IIOException(String.format("Not a DDS file. Expected DDS magic 0x%08x', read 0x%08x", new BigInteger(DDS.MAGIC), new BigInteger(magic))); } // DDS_HEADER structure @@ -42,11 +42,11 @@ final class DDSHeader { // Verify flags header.flags = imageInput.readInt(); // [8,11] - if (header.getFlag(DDS.FLAG_CAPS - & DDS.FLAG_HEIGHT - & DDS.FLAG_WIDTH - & DDS.FLAG_PIXELFORMAT)) { - throw new IIOException("Required DDS Flag missing in header: " + Integer.toHexString(header.flags)); + if (!header.getFlag(DDS.FLAG_CAPS + | DDS.FLAG_HEIGHT + | DDS.FLAG_WIDTH + | DDS.FLAG_PIXELFORMAT)) { + throw new IIOException("Required DDS Flag missing in header: " + Integer.toBinaryString(header.flags)); } // Read Height & Width @@ -55,7 +55,9 @@ final class DDSHeader { int dwPitchOrLinearSize = imageInput.readInt(); // [20,23] int dwDepth = imageInput.readInt(); // [24,27] - header.mipMapCount = imageInput.readInt(); // [28,31] + + // 0 = (unused) or 1 = (1 level), but still one 'base' image + header.mipMapCount = Math.max(1, imageInput.readInt()); // [28,31] // build dimensions list header.addDimensions(dwWidth, dwHeight); @@ -85,11 +87,11 @@ final class DDSHeader { } private void addDimensions(int width, int height) { - dimensions = new Dimension[getMipMapCount()]; + dimensions = new Dimension[mipMapCount]; int w = width; int h = height; - for (int i = 0; i < getMipMapCount(); i++) { + for (int i = 0; i < mipMapCount; i++) { dimensions[i] = new Dimension(w, h); w /= 2; h /= 2; @@ -100,50 +102,45 @@ final class DDSHeader { return (flags & mask) != 0; } - public int getWidth(int imageIndex) { + int getWidth(int imageIndex) { int lim = dimensions[imageIndex].width; return (lim <= 0) ? 1 : lim; } - public int getHeight(int imageIndex) { + int getHeight(int imageIndex) { int lim = dimensions[imageIndex].height; return (lim <= 0) ? 1 : lim; } - public int getMipMapCount() { - // 0 = (unused) or 1 = (1 level), but still only one 'base' image - return (mipMapCount == 0) ? 1 : mipMapCount; + int getMipMapCount() { + return mipMapCount; } - public int getAlphaMask() { - return alphaMask; - } - - public int getBitCount() { + int getBitCount() { return bitCount; } - public int getBlueMask() { - return blueMask; - } - - public int getFlags() { - return flags; - } - - public int getFourCC() { + int getFourCC() { return fourCC; } - public int getGreenMask() { - return greenMask; - } - - public int getPixelFormatFlags() { + int getPixelFormatFlags() { return pixelFormatFlags; } - public int getRedMask() { + int getRedMask() { return redMask; } + + int getGreenMask() { + return greenMask; + } + + int getBlueMask() { + return blueMask; + } + + int getAlphaMask() { + return alphaMask; + } } diff --git a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSImageReader.java b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSImageReader.java index bacdc733..7dbe0cb7 100644 --- a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSImageReader.java +++ b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSImageReader.java @@ -1,5 +1,7 @@ package com.twelvemonkeys.imageio.plugins.dds; +import static com.twelvemonkeys.imageio.util.IIOUtil.subsampleRow; + import com.twelvemonkeys.imageio.ImageReaderBase; import com.twelvemonkeys.imageio.util.ImageTypeSpecifiers; @@ -7,14 +9,14 @@ import javax.imageio.ImageIO; import javax.imageio.ImageReadParam; import javax.imageio.ImageTypeSpecifier; import javax.imageio.spi.ImageReaderSpi; + +import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.nio.ByteOrder; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; -import java.util.List; public final class DDSImageReader extends ImageReaderBase { @@ -47,6 +49,7 @@ public final class DDSImageReader extends ImageReaderBase { @Override public int getNumImages(final boolean allowSearch) throws IOException { + assertInput(); readHeader(); return header.getMipMapCount(); @@ -79,12 +82,28 @@ public final class DDSImageReader extends ImageReaderBase { int height = getHeight(imageIndex); BufferedImage destination = getDestination(param, getImageTypes(imageIndex), width, height); - destination.setRGB(0, 0, width, height, pixels, 0, width); - // TODO: break read into raster line and add progress and abort checks - processImageProgress(100f); - if (abortRequested()) { - processReadAborted(); + Rectangle srcRegion = new Rectangle(); + Rectangle destRegion = new Rectangle(); + + computeRegions(param, width, height, destination, srcRegion, destRegion); + + int srcXStep = param != null ? param.getSourceXSubsampling() : 1; + int srcYStep = param != null ? param.getSourceYSubsampling() : 1; + int srcMaxY = srcRegion.y + srcRegion.height; + + for (int srcY = srcRegion.y, destY = destRegion.y; srcY < srcMaxY; srcY += srcYStep, destY++) { + int offset = width * srcY + srcRegion.x; + + subsampleRow(pixels, offset, width, pixels, offset, 1, 32, srcXStep); + destination.setRGB(destRegion.x, destY, destRegion.width, 1, pixels, offset, width); + + if (abortRequested()) { + processReadAborted(); + break; + } + + processImageProgress(100f * srcY / srcRegion.height); } processImageComplete(); @@ -104,45 +123,10 @@ public final class DDSImageReader extends ImageReaderBase { } public static void main(final String[] args) throws IOException { - - String parentDir = "imageio/imageio-dds/src/test/resources/dds"; - - List testFiles = new ArrayList<>(); - testFiles.add(new File(parentDir, "dds_A1R5G5B5.dds")); - testFiles.add(new File(parentDir, "dds_A1R5G5B5_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_A4R4G4B4.dds")); - testFiles.add(new File(parentDir, "dds_A4R4G4B4_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_A8B8G8R8.dds")); - testFiles.add(new File(parentDir, "dds_A8B8G8R8_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_A8R8G8B8.dds")); - testFiles.add(new File(parentDir, "dds_A8R8G8B8_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_DXT1.dds")); - testFiles.add(new File(parentDir, "dds_DXT1_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_DXT2.dds")); - testFiles.add(new File(parentDir, "dds_DXT2_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_DXT3.dds")); - testFiles.add(new File(parentDir, "dds_DXT3_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_DXT4.dds")); - testFiles.add(new File(parentDir, "dds_DXT4_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_DXT5.dds")); - testFiles.add(new File(parentDir, "dds_DXT5_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_R5G6B5.dds")); - testFiles.add(new File(parentDir, "dds_R5G6B5_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_R8G8B8.dds")); - testFiles.add(new File(parentDir, "dds_R8G8B8_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_X1R5G5B5.dds")); - testFiles.add(new File(parentDir, "dds_X1R5G5B5_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_X4R4G4B4.dds")); - testFiles.add(new File(parentDir, "dds_X4R4G4B4_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_X8B8G8R8.dds")); - testFiles.add(new File(parentDir, "dds_X8B8G8R8_mipmap.dds")); - testFiles.add(new File(parentDir, "dds_X8R8G8B8.dds")); - testFiles.add(new File(parentDir, "dds_X8R8G8B8_mipmap.dds")); - - for (File file : testFiles) { + for (String arg : args) { + File file = new File(arg); BufferedImage image = ImageIO.read(file); showIt(image, file.getName()); } - } } diff --git a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSReader.java b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSReader.java index 71ed3536..0343685d 100644 --- a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSReader.java +++ b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSReader.java @@ -20,16 +20,15 @@ import java.io.IOException; final class DDSReader { - public static final Order order = new Order(16, 8, 0, 24); + static final Order ARGB_ORDER = new Order(16, 8, 0, 24); private final DDSHeader header; - - public DDSReader(DDSHeader header) { + DDSReader(DDSHeader header) { this.header = header; } - public int[] read(ImageInputStream imageInput, int imageIndex) throws IOException { + int[] read(ImageInputStream imageInput, int imageIndex) throws IOException { // type DDSType type = getType(); @@ -87,7 +86,7 @@ final class DDSReader { if ((flags & 0x04) != 0) { // DXT int type = header.getFourCC(); - return DDSType.parse(type); + return DDSType.valueOf(type); } else if ((flags & 0x40) != 0) { // RGB int bitCount = header.getBitCount(); @@ -316,7 +315,7 @@ final class DDSReader { int g = BIT5[(rgba & A1R5G5B5_MASKS[1]) >> 5]; int b = BIT5[(rgba & A1R5G5B5_MASKS[2])]; int a = 255 * ((rgba & A1R5G5B5_MASKS[3]) >> 15); - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -331,7 +330,7 @@ final class DDSReader { int g = BIT5[(rgba & X1R5G5B5_MASKS[1]) >> 5]; int b = BIT5[(rgba & X1R5G5B5_MASKS[2])]; int a = 255; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -346,7 +345,7 @@ final class DDSReader { int g = 17 * ((rgba & A4R4G4B4_MASKS[1]) >> 4); int b = 17 * ((rgba & A4R4G4B4_MASKS[2])); int a = 17 * ((rgba & A4R4G4B4_MASKS[3]) >> 12); - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -361,7 +360,7 @@ final class DDSReader { int g = 17 * ((rgba & A4R4G4B4_MASKS[1]) >> 4); int b = 17 * ((rgba & A4R4G4B4_MASKS[2])); int a = 255; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -376,7 +375,7 @@ final class DDSReader { int g = BIT6[((rgba & R5G6B5_MASKS[1]) >> 5)]; int b = BIT5[((rgba & R5G6B5_MASKS[2]))]; int a = 255; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -389,7 +388,7 @@ final class DDSReader { int g = buffer[index++] & 0xFF; int r = buffer[index++] & 0xFF; int a = 255; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -402,7 +401,7 @@ final class DDSReader { int g = buffer[index++] & 0xFF; int b = buffer[index++] & 0xFF; int a = buffer[index++] & 0xFF; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -416,7 +415,7 @@ final class DDSReader { int b = buffer[index++] & 0xFF; int a = 255; index++; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -429,7 +428,7 @@ final class DDSReader { int g = buffer[index++] & 0xFF; int r = buffer[index++] & 0xFF; int a = buffer[index++] & 0xFF; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -443,7 +442,7 @@ final class DDSReader { int r = buffer[index++] & 0xFF; int a = 255; index++; - pixels[i] = (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + pixels[i] = (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } return pixels; } @@ -467,7 +466,7 @@ final class DDSReader { int r = (2 * BIT5[(c0 & 0xFC00) >> 11] + BIT5[(c1 & 0xFC00) >> 11]) / 3; int g = (2 * BIT6[(c0 & 0x07E0) >> 5] + BIT6[(c1 & 0x07E0) >> 5]) / 3; int b = (2 * BIT5[c0 & 0x001F] + BIT5[c1 & 0x001F]) / 3; - return (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + return (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } private static int getDXTColor1_1(int c0, int c1, int a) { @@ -475,14 +474,14 @@ final class DDSReader { int r = (BIT5[(c0 & 0xFC00) >> 11] + BIT5[(c1 & 0xFC00) >> 11]) / 2; int g = (BIT6[(c0 & 0x07E0) >> 5] + BIT6[(c1 & 0x07E0) >> 5]) / 2; int b = (BIT5[c0 & 0x001F] + BIT5[c1 & 0x001F]) / 2; - return (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + return (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } private static int getDXTColor1(int c, int a) { int r = BIT5[(c & 0xFC00) >> 11]; int g = BIT6[(c & 0x07E0) >> 5]; int b = BIT5[(c & 0x001F)]; - return (a << order.alphaShift) | (r << order.redShift) | (g << order.greenShift) | (b << order.blueShift); + return (a << ARGB_ORDER.alphaShift) | (r << ARGB_ORDER.redShift) | (g << ARGB_ORDER.greenShift) | (b << ARGB_ORDER.blueShift); } private static int getDXT5Alpha(int a0, int a1, int t) { diff --git a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSType.java b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSType.java index 9b16445d..39d74cef 100644 --- a/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSType.java +++ b/imageio/imageio-dds/src/main/java/com/twelvemonkeys/imageio/plugins/dds/DDSType.java @@ -1,7 +1,5 @@ package com.twelvemonkeys.imageio.plugins.dds; -import javax.imageio.IIOException; - enum DDSType { DXT1(0x31545844), @@ -30,12 +28,13 @@ enum DDSType { return value; } - public static DDSType parse(int type) throws IIOException { - for (DDSType t : DDSType.values()) { - if (type == t.value()) { - return t; + public static DDSType valueOf(int value) { + for (DDSType type : DDSType.values()) { + if (value == type.value()) { + return type; } } - throw new IIOException("Unknown type: " + Integer.toHexString(type)); + + throw new IllegalArgumentException(String.format("Unknown type: 0x%08x", value)); } } diff --git a/imageio/imageio-dds/src/test/java/DDSImageTeaderTest.java b/imageio/imageio-dds/src/test/java/DDSImageTeaderTest.java index 06a08734..9207a3aa 100644 --- a/imageio/imageio-dds/src/test/java/DDSImageTeaderTest.java +++ b/imageio/imageio-dds/src/test/java/DDSImageTeaderTest.java @@ -1,13 +1,9 @@ import com.twelvemonkeys.imageio.plugins.dds.DDSImageReader; import com.twelvemonkeys.imageio.plugins.dds.DDSImageReaderSpi; import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest; -import org.junit.Ignore; -import org.junit.Test; import javax.imageio.spi.ImageReaderSpi; import java.awt.Dimension; -import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -20,41 +16,48 @@ public class DDSImageTeaderTest extends ImageReaderAbstractTest @Override protected List getTestData() { - Dimension dim = new Dimension(256, 256); + Dimension dim256 = new Dimension(256, 256); + Dimension dim128 = new Dimension(128, 128); + Dimension dim64 = new Dimension(64, 64); + Dimension dim32 = new Dimension(32, 32); + Dimension dim16 = new Dimension(16, 16); + Dimension dim8 = new Dimension(8, 8); + Dimension dim4 = new Dimension(4, 4); + Dimension dim2 = new Dimension(2, 2); + Dimension dim1 = new Dimension(1, 1); - List testData = new ArrayList<>(); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A1R5G5B5.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A1R5G5B5_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A4R4G4B4.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A4R4G4B4_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A8B8G8R8.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A8B8G8R8_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A8R8G8B8.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_A8R8G8B8_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT1.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT1_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT2.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT2_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT3.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT3_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT4.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT4_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT5.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT5_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_R5G6B5.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_R5G6B5_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_R8G8B8.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_R8G8B8_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X1R5G5B5.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X1R5G5B5_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X4R4G4B4.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X4R4G4B4_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X8B8G8R8.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X8B8G8R8_mipmap.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8.dds"), dim)); - testData.add(new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8_mipmap.dds"), dim)); - - return testData; + return Arrays.asList( + new TestData(getClassLoaderResource("/dds/dds_A1R5G5B5.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_A1R5G5B5_mipmap.dds"), dim256, dim128, dim64, dim32, dim16, dim8, dim4, dim2, dim1), + new TestData(getClassLoaderResource("/dds/dds_A4R4G4B4.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_A4R4G4B4_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_A8B8G8R8.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_A8B8G8R8_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_A8R8G8B8.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_A8R8G8B8_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_DXT1.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_DXT1_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_DXT2.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_DXT2_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_DXT3.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_DXT3_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_DXT4.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_DXT4_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_DXT5.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_DXT5_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_R5G6B5.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_R5G6B5_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_R8G8B8.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_R8G8B8_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_X1R5G5B5.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_X1R5G5B5_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_X4R4G4B4.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_X4R4G4B4_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_X8B8G8R8.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_X8B8G8R8_mipmap.dds"), dim256, dim128, dim64), + new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8.dds"), dim256), + new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8_mipmap.dds"), dim256, dim128, dim64) + ); } @Override @@ -64,78 +67,11 @@ public class DDSImageTeaderTest extends ImageReaderAbstractTest @Override protected List getSuffixes() { - return Arrays.asList("dds"); + return Collections.singletonList("dds"); } @Override protected List getMIMETypes() { return Collections.singletonList("image/vnd-ms.dds"); } - - /* ************************************************************************************************************* * - * IGNORE Broken Tests... - * ************************************************************************************************************* */ - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testGetNumImagesNoInput() throws IOException { - super.testGetNumImagesNoInput(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testAffineTransformOpCompatibility() throws IOException { - super.testAffineTransformOpCompatibility(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testReadWithSourceRegionParam() throws IOException { - super.testReadWithSourceRegionParam(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testReadWithSourceRegionParamEqualImage() throws IOException { - super.testReadWithSourceRegionParamEqualImage(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testReadWithSubsampleAndSourceRegionParam() throws IOException { - super.testReadWithSubsampleAndSourceRegionParam(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testReadWithSubsampleParamDimensions() throws IOException { - super.testReadWithSubsampleParamDimensions(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testReadWithSubsampleParamPixels() throws IOException { - super.testReadWithSubsampleParamPixels(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testSetDestination() throws IOException { - super.testSetDestination(); - } - - @Ignore("Known issue: currently not supported in DDS") - @Test - @Override - public void testSetDestinationIllegal() throws IOException { - super.testSetDestinationIllegal(); - } }