mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-28 00:00:03 -04:00
Format tabs -> 4 spaces
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
package com.twelvemonkeys.imageio.plugins.dds;
|
package com.twelvemonkeys.imageio.plugins.dds;
|
||||||
|
|
||||||
interface DDS {
|
interface DDS {
|
||||||
byte[] MAGIC = new byte[]{'D', 'D', 'S', ' '};
|
byte[] MAGIC = new byte[]{'D', 'D', 'S', ' '};
|
||||||
int HEADER_SIZE = 124;
|
int HEADER_SIZE = 124;
|
||||||
|
|
||||||
int FLAG_CAPS = 0x1; // Required in every .dds file.
|
int FLAG_CAPS = 0x1; // Required in every .dds file.
|
||||||
int FLAG_HEIGHT = 0x2; // Required in every .dds file.
|
int FLAG_HEIGHT = 0x2; // Required in every .dds file.
|
||||||
int FLAG_WIDTH = 0x4; // Required in every .dds file.
|
int FLAG_WIDTH = 0x4; // Required in every .dds file.
|
||||||
int FLAG_PITCH = 0x8; // Required when pitch is provided for an uncompressed texture.
|
int FLAG_PITCH = 0x8; // Required when pitch is provided for an uncompressed texture.
|
||||||
int FLAG_PIXELFORMAT = 0x1000; // Required in every .dds file.
|
int FLAG_PIXELFORMAT = 0x1000; // Required in every .dds file.
|
||||||
int FLAG_MIPMAPCOUNT = 0x20000; // Required in a mipmapped texture.
|
int FLAG_MIPMAPCOUNT = 0x20000; // Required in a mipmapped texture.
|
||||||
int FLAG_LINEARSIZE = 0x80000; // Required when pitch is provided for a compressed texture.
|
int FLAG_LINEARSIZE = 0x80000; // Required when pitch is provided for a compressed texture.
|
||||||
int FLAG_DEPTH = 0x800000; // Required in a depth texture.
|
int FLAG_DEPTH = 0x800000; // Required in a depth texture.
|
||||||
}
|
}
|
||||||
|
|||||||
+101
-101
@@ -8,134 +8,134 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public final class DDSHeader {
|
public final class DDSHeader {
|
||||||
|
|
||||||
// https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-pguide
|
// https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-pguide
|
||||||
private int flags;
|
private int flags;
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
private int mipmap;
|
private int mipmap;
|
||||||
|
|
||||||
private int pixelFormatFlags;
|
private int pixelFormatFlags;
|
||||||
private int fourCC;
|
private int fourCC;
|
||||||
private int bitCount;
|
private int bitCount;
|
||||||
private int redMask;
|
private int redMask;
|
||||||
private int greenMask;
|
private int greenMask;
|
||||||
private int blueMask;
|
private int blueMask;
|
||||||
private int alphaMask;
|
private int alphaMask;
|
||||||
|
|
||||||
public static DDSHeader read(final ImageInputStream imageInput) throws IOException {
|
public static DDSHeader read(final ImageInputStream imageInput) throws IOException {
|
||||||
DDSHeader header = new DDSHeader();
|
DDSHeader header = new DDSHeader();
|
||||||
|
|
||||||
imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
|
||||||
// Read MAGIC bytes [0,3]
|
// Read MAGIC bytes [0,3]
|
||||||
byte[] magic = new byte[DDS.MAGIC.length];
|
byte[] magic = new byte[DDS.MAGIC.length];
|
||||||
imageInput.readFully(magic);
|
imageInput.readFully(magic);
|
||||||
if (!Arrays.equals(DDS.MAGIC, magic)) {
|
if (!Arrays.equals(DDS.MAGIC, magic)) {
|
||||||
throw new IIOException(String.format("Not a DDS file. Expected DDS magic %02x, read %02x", DDS.MAGIC, magic));
|
throw new IIOException(String.format("Not a DDS file. Expected DDS magic %02x, read %02x", Arrays.toString(DDS.MAGIC), magic));
|
||||||
}
|
}
|
||||||
|
|
||||||
// DDS_HEADER structure
|
// DDS_HEADER structure
|
||||||
// https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dds-header
|
// https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dds-header
|
||||||
int dwSize = imageInput.readInt(); // [4,7]
|
int dwSize = imageInput.readInt(); // [4,7]
|
||||||
if (dwSize != DDS.HEADER_SIZE) {
|
if (dwSize != DDS.HEADER_SIZE) {
|
||||||
throw new IIOException(String.format("Invalid DDS header size (expected %d): %d", DDS.HEADER_SIZE, dwSize);
|
throw new IIOException(String.format("Invalid DDS header size (expected %d): %d", DDS.HEADER_SIZE, dwSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify flags
|
// Verify flags
|
||||||
header.flags = imageInput.readInt(); // [8,11]
|
header.flags = imageInput.readInt(); // [8,11]
|
||||||
if (header.getFlag(DDS.FLAG_CAPS
|
if (header.getFlag(DDS.FLAG_CAPS
|
||||||
& DDS.FLAG_HEIGHT
|
& DDS.FLAG_HEIGHT
|
||||||
& DDS.FLAG_WIDTH
|
& DDS.FLAG_WIDTH
|
||||||
& DDS.FLAG_PIXELFORMAT)) {
|
& DDS.FLAG_PIXELFORMAT)) {
|
||||||
throw new IIOException("Required DDS Flag missing in header: " + Integer.toHexString(header.flags));
|
throw new IIOException("Required DDS Flag missing in header: " + Integer.toHexString(header.flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read Height & Width
|
// Read Height & Width
|
||||||
header.height = imageInput.readInt(); // [12,15]
|
header.height = imageInput.readInt(); // [12,15]
|
||||||
header.width = imageInput.readInt(); // [16,19]
|
header.width = imageInput.readInt(); // [16,19]
|
||||||
|
|
||||||
|
|
||||||
int dwPitchOrLinearSize = imageInput.readInt(); // [20,23]
|
int dwPitchOrLinearSize = imageInput.readInt(); // [20,23]
|
||||||
int dwDepth = imageInput.readInt(); // [24,27]
|
int dwDepth = imageInput.readInt(); // [24,27]
|
||||||
header.mipmap = imageInput.readInt(); // [28,31]
|
header.mipmap = imageInput.readInt(); // [28,31]
|
||||||
|
|
||||||
byte[] dwReserved1 = new byte[11 * 4]; // [32,75]
|
byte[] dwReserved1 = new byte[11 * 4]; // [32,75]
|
||||||
imageInput.readFully(dwReserved1);
|
imageInput.readFully(dwReserved1);
|
||||||
|
|
||||||
// DDS_PIXELFORMAT structure
|
// DDS_PIXELFORMAT structure
|
||||||
int px_dwSize = imageInput.readInt(); // [76,79]
|
int px_dwSize = imageInput.readInt(); // [76,79]
|
||||||
|
|
||||||
header.pixelFormatFlags = imageInput.readInt(); // [80,83]
|
header.pixelFormatFlags = imageInput.readInt(); // [80,83]
|
||||||
header.fourCC = imageInput.readInt(); // [84,87]
|
header.fourCC = imageInput.readInt(); // [84,87]
|
||||||
header.bitCount = imageInput.readInt(); // [88,91]
|
header.bitCount = imageInput.readInt(); // [88,91]
|
||||||
header.redMask = imageInput.readInt(); // [92,95]
|
header.redMask = imageInput.readInt(); // [92,95]
|
||||||
header.greenMask = imageInput.readInt(); // [96,99]
|
header.greenMask = imageInput.readInt(); // [96,99]
|
||||||
header.blueMask = imageInput.readInt(); // [100,103]
|
header.blueMask = imageInput.readInt(); // [100,103]
|
||||||
header.alphaMask = imageInput.readInt(); // [104,107]
|
header.alphaMask = imageInput.readInt(); // [104,107]
|
||||||
|
|
||||||
int dwCaps = imageInput.readInt(); // [108,111]
|
int dwCaps = imageInput.readInt(); // [108,111]
|
||||||
int dwCaps2 = imageInput.readInt(); // [112,115]
|
int dwCaps2 = imageInput.readInt(); // [112,115]
|
||||||
int dwCaps3 = imageInput.readInt(); // [116,119]
|
int dwCaps3 = imageInput.readInt(); // [116,119]
|
||||||
int dwCaps4 = imageInput.readInt(); // [120,123]
|
int dwCaps4 = imageInput.readInt(); // [120,123]
|
||||||
|
|
||||||
int dwReserved2 = imageInput.readInt(); // [124,127]
|
int dwReserved2 = imageInput.readInt(); // [124,127]
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getFlag(int mask) {
|
private boolean getFlag(int mask) {
|
||||||
return (flags & mask) != 0;
|
return (flags & mask) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWidth(int width) {
|
public void setWidth(int width) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeight(int height) {
|
public void setHeight(int height) {
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMipmap() {
|
public int getMipmap() {
|
||||||
return mipmap;
|
return mipmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAlphaMask() {
|
public int getAlphaMask() {
|
||||||
return alphaMask;
|
return alphaMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBitCount() {
|
public int getBitCount() {
|
||||||
return bitCount;
|
return bitCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBlueMask() {
|
public int getBlueMask() {
|
||||||
return blueMask;
|
return blueMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFlags() {
|
public int getFlags() {
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFourCC() {
|
public int getFourCC() {
|
||||||
return fourCC;
|
return fourCC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGreenMask() {
|
public int getGreenMask() {
|
||||||
return greenMask;
|
return greenMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPixelFormatFlags() {
|
public int getPixelFormatFlags() {
|
||||||
return pixelFormatFlags;
|
return pixelFormatFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRedMask() {
|
public int getRedMask() {
|
||||||
return redMask;
|
return redMask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+94
-94
@@ -17,123 +17,123 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class DDSImageReader extends ImageReaderBase {
|
public final class DDSImageReader extends ImageReaderBase {
|
||||||
|
|
||||||
private DDSHeader header;
|
private DDSHeader header;
|
||||||
|
|
||||||
public DDSImageReader(final ImageReaderSpi provider) {
|
public DDSImageReader(final ImageReaderSpi provider) {
|
||||||
super(provider);
|
super(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void resetMembers() {
|
protected void resetMembers() {
|
||||||
header = null;
|
header = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth(final int imageIndex) throws IOException {
|
public int getWidth(final int imageIndex) throws IOException {
|
||||||
checkBounds(imageIndex);
|
checkBounds(imageIndex);
|
||||||
readHeader();
|
readHeader();
|
||||||
|
|
||||||
return header.getWidth();
|
return header.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHeight(int imageIndex) throws IOException {
|
public int getHeight(int imageIndex) throws IOException {
|
||||||
checkBounds(imageIndex);
|
checkBounds(imageIndex);
|
||||||
readHeader();
|
readHeader();
|
||||||
|
|
||||||
return header.getHeight();
|
return header.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException {
|
public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException {
|
||||||
checkBounds(imageIndex);
|
checkBounds(imageIndex);
|
||||||
readHeader();
|
readHeader();
|
||||||
|
|
||||||
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
|
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
|
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
|
||||||
return Collections.singletonList(getRawImageType(imageIndex)).iterator();
|
return Collections.singletonList(getRawImageType(imageIndex)).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
|
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
|
||||||
checkBounds(imageIndex);
|
checkBounds(imageIndex);
|
||||||
readHeader();
|
readHeader();
|
||||||
|
|
||||||
processImageStarted(imageIndex);
|
processImageStarted(imageIndex);
|
||||||
|
|
||||||
DDSReader dds = new DDSReader(header);
|
DDSReader dds = new DDSReader(header);
|
||||||
int[] pixels = dds.read(imageInput, imageIndex);
|
int[] pixels = dds.read(imageInput, imageIndex);
|
||||||
|
|
||||||
int width = getWidth(imageIndex);
|
int width = getWidth(imageIndex);
|
||||||
int height = getHeight(imageIndex);
|
int height = getHeight(imageIndex);
|
||||||
|
|
||||||
BufferedImage destination = getDestination(param, getImageTypes(imageIndex), width, height);
|
BufferedImage destination = getDestination(param, getImageTypes(imageIndex), width, height);
|
||||||
destination.setRGB(0, 0, width, height, pixels, 0, width);
|
destination.setRGB(0, 0, width, height, pixels, 0, width);
|
||||||
|
|
||||||
// TODO: break read into raster line and add progress and abort checks
|
// TODO: break read into raster line and add progress and abort checks
|
||||||
processImageProgress(100f);
|
processImageProgress(100f);
|
||||||
if (abortRequested()) {
|
if (abortRequested()) {
|
||||||
processReadAborted();
|
processReadAborted();
|
||||||
}
|
}
|
||||||
|
|
||||||
processImageComplete();
|
processImageComplete();
|
||||||
|
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readHeader() throws IOException {
|
private void readHeader() throws IOException {
|
||||||
if (header == null) {
|
if (header == null) {
|
||||||
header = DDSHeader.read(imageInput);
|
header = DDSHeader.read(imageInput);
|
||||||
|
|
||||||
imageInput.flushBefore(imageInput.getStreamPosition());
|
imageInput.flushBefore(imageInput.getStreamPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
imageInput.seek(imageInput.getFlushedPosition());
|
imageInput.seek(imageInput.getFlushedPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(final String[] args) throws IOException {
|
public static void main(final String[] args) throws IOException {
|
||||||
|
|
||||||
String parentDir = "imageio/imageio-dds/src/test/resources/dds";
|
String parentDir = "imageio/imageio-dds/src/test/resources/dds";
|
||||||
|
|
||||||
List<File> testFiles = new ArrayList<>();
|
List<File> testFiles = new ArrayList<>();
|
||||||
testFiles.add(new File(parentDir, "dds_A1R5G5B5.dds"));
|
testFiles.add(new File(parentDir, "dds_A1R5G5B5.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_A1R5G5B5_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_A4R4G4B4_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_A8B8G8R8_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_A8R8G8B8_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_DXT1_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_DXT2_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_DXT3_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_DXT4_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_DXT5_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_R5G6B5_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_R8G8B8_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_X1R5G5B5_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_X4R4G4B4_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_X8B8G8R8_mipmap.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.dds"));
|
||||||
testFiles.add(new File(parentDir, "dds_X8R8G8B8_mipmap.dds"));
|
testFiles.add(new File(parentDir, "dds_X8R8G8B8_mipmap.dds"));
|
||||||
|
|
||||||
for (File file : testFiles) {
|
for (File file : testFiles) {
|
||||||
BufferedImage image = ImageIO.read(file);
|
BufferedImage image = ImageIO.read(file);
|
||||||
showIt(image, file.getName());
|
showIt(image, file.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-26
@@ -10,37 +10,37 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public final class DDSImageReaderSpi extends ImageReaderSpiBase {
|
public final class DDSImageReaderSpi extends ImageReaderSpiBase {
|
||||||
|
|
||||||
public DDSImageReaderSpi() {
|
public DDSImageReaderSpi() {
|
||||||
super(new DDSProviderInfo());
|
super(new DDSProviderInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDecodeInput(final Object source) throws IOException {
|
public boolean canDecodeInput(final Object source) throws IOException {
|
||||||
if (!(source instanceof ImageInputStream)) {
|
if (!(source instanceof ImageInputStream)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageInputStream stream = (ImageInputStream) source;
|
ImageInputStream stream = (ImageInputStream) source;
|
||||||
|
|
||||||
stream.mark();
|
stream.mark();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] magic = new byte[DDS.MAGIC.length];
|
byte[] magic = new byte[DDS.MAGIC.length];
|
||||||
stream.readFully(magic);
|
stream.readFully(magic);
|
||||||
|
|
||||||
return Arrays.equals(DDS.MAGIC, magic);
|
return Arrays.equals(DDS.MAGIC, magic);
|
||||||
} finally {
|
} finally {
|
||||||
stream.reset();
|
stream.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImageReader createReaderInstance(Object extension) throws IOException {
|
public ImageReader createReaderInstance(Object extension) throws IOException {
|
||||||
return new DDSImageReader(this);
|
return new DDSImageReader(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription(Locale locale) {
|
public String getDescription(Locale locale) {
|
||||||
return "Direct DrawSurface (DDS) Image Reader";
|
return "Direct DrawSurface (DDS) Image Reader";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -3,18 +3,18 @@ package com.twelvemonkeys.imageio.plugins.dds;
|
|||||||
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
|
||||||
|
|
||||||
final class DDSProviderInfo extends ReaderWriterProviderInfo {
|
final class DDSProviderInfo extends ReaderWriterProviderInfo {
|
||||||
DDSProviderInfo() {
|
DDSProviderInfo() {
|
||||||
super(
|
super(
|
||||||
DDSProviderInfo.class,
|
DDSProviderInfo.class,
|
||||||
new String[] {"DDS", "dds"},
|
new String[]{"DDS", "dds"},
|
||||||
new String[] {"dds"},
|
new String[]{"dds"},
|
||||||
new String[] {"image/vnd-ms.dds"},
|
new String[]{"image/vnd-ms.dds"},
|
||||||
"com.twelvemonkeys.imageio.plugins.dds.DDSImageReader",
|
"com.twelvemonkeys.imageio.plugins.dds.DDSImageReader",
|
||||||
new String[]{"com.twelvemonkeys.imageio.plugins.dds.DDSImageReaderSpi"},
|
new String[]{"com.twelvemonkeys.imageio.plugins.dds.DDSImageReaderSpi"},
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
false, null, null, null, null,
|
false, null, null, null, null,
|
||||||
true, null, null, null, null
|
true, null, null, null, null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+510
-510
File diff suppressed because it is too large
Load Diff
+30
-30
@@ -4,38 +4,38 @@ import javax.imageio.IIOException;
|
|||||||
|
|
||||||
public enum DDSType {
|
public enum DDSType {
|
||||||
|
|
||||||
DXT1(0x31545844),
|
DXT1(0x31545844),
|
||||||
DXT2(0x32545844),
|
DXT2(0x32545844),
|
||||||
DXT3(0x33545844),
|
DXT3(0x33545844),
|
||||||
DXT4(0x34545844),
|
DXT4(0x34545844),
|
||||||
DXT5(0x35545844),
|
DXT5(0x35545844),
|
||||||
A1R5G5B5((1 << 16) | 2),
|
A1R5G5B5((1 << 16) | 2),
|
||||||
X1R5G5B5((2 << 16) | 2),
|
X1R5G5B5((2 << 16) | 2),
|
||||||
A4R4G4B4((3 << 16) | 2),
|
A4R4G4B4((3 << 16) | 2),
|
||||||
X4R4G4B4((4 << 16) | 2),
|
X4R4G4B4((4 << 16) | 2),
|
||||||
R5G6B5((5 << 16) | 2),
|
R5G6B5((5 << 16) | 2),
|
||||||
R8G8B8((1 << 16) | 3),
|
R8G8B8((1 << 16) | 3),
|
||||||
A8B8G8R8((1 << 16) | 4),
|
A8B8G8R8((1 << 16) | 4),
|
||||||
X8B8G8R8((2 << 16) | 4),
|
X8B8G8R8((2 << 16) | 4),
|
||||||
A8R8G8B8((3 << 16) | 4),
|
A8R8G8B8((3 << 16) | 4),
|
||||||
X8R8G8B8((4 << 16) | 4);
|
X8R8G8B8((4 << 16) | 4);
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
DDSType(int value) {
|
DDSType(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int value() {
|
public int value() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DDSType parse(int type) throws IIOException {
|
public static DDSType parse(int type) throws IIOException {
|
||||||
for (DDSType t : DDSType.values()) {
|
for (DDSType t : DDSType.values()) {
|
||||||
if (type == t.value()) {
|
if (type == t.value()) {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IIOException("Unknown type: " + Integer.toHexString(type));
|
throw new IIOException("Unknown type: " + Integer.toHexString(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,62 +10,62 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DDSImageTeaderTest extends ImageReaderAbstractTest<DDSImageReader> {
|
public class DDSImageTeaderTest extends ImageReaderAbstractTest<DDSImageReader> {
|
||||||
@Override
|
@Override
|
||||||
protected ImageReaderSpi createProvider() {
|
protected ImageReaderSpi createProvider() {
|
||||||
return new DDSImageReaderSpi();
|
return new DDSImageReaderSpi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<TestData> getTestData() {
|
protected List<TestData> getTestData() {
|
||||||
Dimension dim = new Dimension(256, 256);
|
Dimension dim = new Dimension(256, 256);
|
||||||
|
|
||||||
List<TestData> testData = new ArrayList<>();
|
List<TestData> testData = new ArrayList<>();
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_A1R5G5B5.dds"), dim));
|
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_A1R5G5B5_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_A4R4G4B4.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_A4R4G4B4_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_A8B8G8R8.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_A8B8G8R8_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_A8R8G8B8.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_A8R8G8B8_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT1.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_DXT1_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT2.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_DXT2_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT3.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_DXT3_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT4.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_DXT4_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_DXT5.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_DXT5_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_R5G6B5.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_R5G6B5_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_R8G8B8.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_R8G8B8_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_X1R5G5B5.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_X1R5G5B5_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_X4R4G4B4.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_X4R4G4B4_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_X8B8G8R8.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_X8B8G8R8_mipmap.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8.dds"), dim));
|
testData.add(new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8.dds"), dim));
|
||||||
testData.add(new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8_mipmap.dds"), dim));
|
testData.add(new TestData(getClassLoaderResource("/dds/dds_X8R8G8B8_mipmap.dds"), dim));
|
||||||
|
|
||||||
return testData;
|
return testData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getFormatNames() {
|
protected List<String> getFormatNames() {
|
||||||
return Arrays.asList("DDS", "dds");
|
return Arrays.asList("DDS", "dds");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getSuffixes() {
|
protected List<String> getSuffixes() {
|
||||||
return Arrays.asList("dds");
|
return Arrays.asList("dds");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getMIMETypes() {
|
protected List<String> getMIMETypes() {
|
||||||
return Collections.singletonList("image/vnd-ms.dds");
|
return Collections.singletonList("image/vnd-ms.dds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -30,16 +30,15 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.imageio.reference;
|
package com.twelvemonkeys.imageio.reference;
|
||||||
|
|
||||||
|
import com.sun.imageio.plugins.png.PNGImageReader;
|
||||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||||
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTest;
|
||||||
|
|
||||||
import com.sun.imageio.plugins.png.PNGImageReader;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.imageio.IIOException;
|
import javax.imageio.IIOException;
|
||||||
import javax.imageio.spi.IIORegistry;
|
import javax.imageio.spi.IIORegistry;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
import java.awt.*;
|
import java.awt.Dimension;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -86,8 +85,7 @@ public class PNGImageReaderTest extends ImageReaderAbstractTest<PNGImageReader>
|
|||||||
public void testSetDestinationTypeIllegal() throws IOException {
|
public void testSetDestinationTypeIllegal() throws IOException {
|
||||||
try {
|
try {
|
||||||
super.testSetDestinationTypeIllegal();
|
super.testSetDestinationTypeIllegal();
|
||||||
}
|
} catch (IIOException expected) {
|
||||||
catch (IIOException expected) {
|
|
||||||
// Known bug
|
// Known bug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user