#292 Now builds on Java 8, 11 and 15.

This commit is contained in:
Harald Kuhr
2020-12-02 22:08:18 +01:00
parent c7d2f422b8
commit 73044bea58
11 changed files with 196 additions and 140 deletions
@@ -30,14 +30,20 @@
package com.twelvemonkeys.imageio.util;
import com.twelvemonkeys.lang.Validate;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
import java.awt.image.IndexColorModel;
import javax.imageio.ImageTypeSpecifier;
import java.awt.color.ColorSpace;
import java.awt.image.*;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.twelvemonkeys.lang.Validate;
public class ImageTypeSpecifiersTest {
@@ -541,8 +547,7 @@ public class ImageTypeSpecifiersTest {
}
@Test
public void testCreatePackedGrayscale1() {
// TODO: Fails on Java 11, because IndexColorModel now has an overloaded equals that actually tests the color entries
public void testCreatePackedGrayscale1BPP() {
assertEquals(
ImageTypeSpecifier.createGrayscale(1, DataBuffer.TYPE_BYTE, false),
ImageTypeSpecifiers.createPackedGrayscale(GRAY, 1, DataBuffer.TYPE_BYTE)
@@ -550,8 +555,8 @@ public class ImageTypeSpecifiersTest {
}
@Test
public void testCreatePackedGrayscale2() {
// TODO: Fails on Java 11, because IndexColorModel now has an overloaded equals that actually tests the color entries
public void testCreatePackedGrayscale2BPP() {
// TODO: Fails on Java 11+, because IndexColorModel now has an overloaded equals that actually tests the color entries
assertEquals(
ImageTypeSpecifier.createGrayscale(2, DataBuffer.TYPE_BYTE, false),
ImageTypeSpecifiers.createPackedGrayscale(GRAY, 2, DataBuffer.TYPE_BYTE)
@@ -559,8 +564,8 @@ public class ImageTypeSpecifiersTest {
}
@Test
public void testCreatePackedGrayscale4() throws Exception {
// TODO: Fails on Java 11, because IndexColorModel now has an overloaded equals that actually tests the color entries
public void testCreatePackedGrayscale4BPP() {
// TODO: Fails on Java 11+, because IndexColorModel now has an overloaded equals that actually tests the color entries
assertEquals(
ImageTypeSpecifier.createGrayscale(4, DataBuffer.TYPE_BYTE, false),
ImageTypeSpecifiers.createPackedGrayscale(GRAY, 4, DataBuffer.TYPE_BYTE)
@@ -653,7 +658,7 @@ public class ImageTypeSpecifiersTest {
for (int bits = 1; bits <= 8; bits <<= 1) {
int[] colors = createIntLut(1 << bits);
assertEquals(
IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE)),
new IndexedImageTypeSpecifier(new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE)),
ImageTypeSpecifiers.createIndexed(colors, false, -1, bits, DataBuffer.TYPE_BYTE)
);
}
@@ -663,7 +668,7 @@ public class ImageTypeSpecifiersTest {
public void testCreateIndexedIntArray16() {
int[] colors = createIntLut(1 << 16);
assertEquals(
IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT)),
new IndexedImageTypeSpecifier(new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT)),
ImageTypeSpecifiers.createIndexed(colors, false, -1, 16, DataBuffer.TYPE_USHORT)
);
@@ -675,7 +680,7 @@ public class ImageTypeSpecifiersTest {
int[] colors = createIntLut(1 << bits);
IndexColorModel colorModel = new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE);
assertEquals(
IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel),
new IndexedImageTypeSpecifier(colorModel),
ImageTypeSpecifiers.createFromIndexColorModel(colorModel)
);
}
@@ -686,7 +691,7 @@ public class ImageTypeSpecifiersTest {
int[] colors = createIntLut(1 << 16);
IndexColorModel colorModel = new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT);
assertEquals(
IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel),
new IndexedImageTypeSpecifier(colorModel),
ImageTypeSpecifiers.createFromIndexColorModel(colorModel)
);
}
@@ -30,14 +30,17 @@
package com.twelvemonkeys.imageio.util;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import javax.imageio.ImageTypeSpecifier;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.IndexColorModel;
import static org.junit.Assert.*;
import javax.imageio.ImageTypeSpecifier;
import org.junit.Test;
/**
* IndexedImageTypeSpecifierTestCase
@@ -51,46 +54,43 @@ public class IndexedImageTypeSpecifierTest {
public void testEquals() {
IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE);
ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
ImageTypeSpecifier other = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
ImageTypeSpecifier different = IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE));
ImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
ImageTypeSpecifier other = new IndexedImageTypeSpecifier(cm);
ImageTypeSpecifier different = new IndexedImageTypeSpecifier(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE));
assertEquals(spec, other);
assertEquals(other, spec);
assertEquals(spec.hashCode(), other.hashCode());
assertTrue(spec.equals(other));
assertTrue(other.equals(spec));
// TODO: There is still a problem that IndexColorModel does not override equals,
// so any model with the same number of bits, transparency, and transfer type will be treated as equal
assertFalse(other.equals(different));
assertNotEquals(other, different);
}
@Test
public void testHashCode() {
IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE);
ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
ImageTypeSpecifier other = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
ImageTypeSpecifier different = IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE));
ImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
ImageTypeSpecifier other = new IndexedImageTypeSpecifier(cm);
ImageTypeSpecifier different = new IndexedImageTypeSpecifier(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE));
// TODO: There is still a problem that IndexColorModel does not override hashCode,
// so any model with the same number of bits, transparency, and transfer type will have same hash
assertEquals(spec.hashCode(), other.hashCode());
assertFalse(spec.hashCode() == different.hashCode());
assertNotEquals(spec.hashCode(), different.hashCode());
}
@Test(expected = IllegalArgumentException.class)
public void testCreateNull() {
IndexedImageTypeSpecifier.createFromIndexColorModel(null);
new IndexedImageTypeSpecifier(null);
}
@Test
public void testCreateBufferedImageBinary() {
IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE);
ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
ImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
BufferedImage image = spec.createBufferedImage(2, 2);
@@ -102,7 +102,7 @@ public class IndexedImageTypeSpecifierTest {
@Test
public void testCreateBufferedImageIndexed() {
IndexColorModel cm = new IndexColorModel(8, 256, new int[256], 0, false, -1, DataBuffer.TYPE_BYTE);
ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
ImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
BufferedImage image = spec.createBufferedImage(2, 2);