mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-25 00:00:03 -04:00
#280 Support for bitsPerSample == 6, 10, 12, 14 & 24
This commit is contained in:
+18
-18
@@ -182,24 +182,24 @@ public class ImageTypeSpecifiersTest {
|
||||
public void testCreateInterleaved32() {
|
||||
// 32 bits/sample
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0}, false, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0}, false, false),
|
||||
ImageTypeSpecifiers.createInterleaved(GRAY, new int[] {0}, DataBuffer.TYPE_INT, false, false)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0, 1}, true, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, false),
|
||||
ImageTypeSpecifiers.createInterleaved(GRAY, new int[] {0, 1}, DataBuffer.TYPE_INT, true, false)
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(sRGB, new int[] {0, 1, 2}, false, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int[] {0, 1, 2}, false, false),
|
||||
ImageTypeSpecifiers.createInterleaved(sRGB, new int[] {0, 1, 2}, DataBuffer.TYPE_INT, false, false)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(sRGB, new int[] {0, 1, 2, 3}, true, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, true, false),
|
||||
ImageTypeSpecifiers.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, DataBuffer.TYPE_INT, true, false)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(sRGB, new int[] {0, 1, 2, 3}, true, true),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, true, true),
|
||||
ImageTypeSpecifiers.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, DataBuffer.TYPE_INT, true, true)
|
||||
);
|
||||
}
|
||||
@@ -303,15 +303,15 @@ public class ImageTypeSpecifiersTest {
|
||||
@Test
|
||||
public void testCreateBanded32() {
|
||||
assertEquals(
|
||||
ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_INT, false, false),
|
||||
UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, false, false),
|
||||
ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_INT, false, false)
|
||||
);
|
||||
assertEquals(
|
||||
ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_INT, true, false),
|
||||
UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, true, false),
|
||||
ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_INT, true, false)
|
||||
);
|
||||
assertEquals(
|
||||
ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, DataBuffer.TYPE_INT, true, true),
|
||||
UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, true, true),
|
||||
ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, DataBuffer.TYPE_INT, true, true)
|
||||
);
|
||||
}
|
||||
@@ -383,11 +383,11 @@ public class ImageTypeSpecifiersTest {
|
||||
@Test
|
||||
public void testCreateGrayscale32() {
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0}, false, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0}, false, false),
|
||||
ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0}, false, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0}, false, false),
|
||||
ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT)
|
||||
);
|
||||
}
|
||||
@@ -446,19 +446,19 @@ public class ImageTypeSpecifiersTest {
|
||||
@Test
|
||||
public void testCreateGrayscaleAlpha32() {
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0, 1}, true, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, false),
|
||||
ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, false)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0, 1}, true, false),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, false),
|
||||
ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, false)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0, 1}, true, true),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, true),
|
||||
ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, true)
|
||||
);
|
||||
assertEquals(
|
||||
new UInt32ImageTypeSpecifier(GRAY, new int[] {0, 1}, true, true),
|
||||
UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, true),
|
||||
ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, true)
|
||||
);
|
||||
}
|
||||
@@ -573,7 +573,7 @@ public class ImageTypeSpecifiersTest {
|
||||
for (int bits = 1; bits <= 8; bits <<= 1) {
|
||||
int[] colors = createIntLut(1 << bits);
|
||||
assertEquals(
|
||||
new IndexedImageTypeSpecifier(new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE)),
|
||||
IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE)),
|
||||
ImageTypeSpecifiers.createIndexed(colors, false, -1, bits, DataBuffer.TYPE_BYTE)
|
||||
);
|
||||
}
|
||||
@@ -583,7 +583,7 @@ public class ImageTypeSpecifiersTest {
|
||||
public void testCreateIndexedIntArray16() {
|
||||
int[] colors = createIntLut(1 << 16);
|
||||
assertEquals(
|
||||
new IndexedImageTypeSpecifier(new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT)),
|
||||
IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT)),
|
||||
ImageTypeSpecifiers.createIndexed(colors, false, -1, 16, DataBuffer.TYPE_USHORT)
|
||||
);
|
||||
|
||||
@@ -595,7 +595,7 @@ public class ImageTypeSpecifiersTest {
|
||||
int[] colors = createIntLut(1 << bits);
|
||||
IndexColorModel colorModel = new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
assertEquals(
|
||||
new IndexedImageTypeSpecifier(colorModel),
|
||||
IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel),
|
||||
ImageTypeSpecifiers.createFromIndexColorModel(colorModel)
|
||||
);
|
||||
}
|
||||
@@ -606,7 +606,7 @@ public class ImageTypeSpecifiersTest {
|
||||
int[] colors = createIntLut(1 << 16);
|
||||
IndexColorModel colorModel = new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT);
|
||||
assertEquals(
|
||||
new IndexedImageTypeSpecifier(colorModel),
|
||||
IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel),
|
||||
ImageTypeSpecifiers.createFromIndexColorModel(colorModel)
|
||||
);
|
||||
}
|
||||
|
||||
+10
-9
@@ -2,6 +2,7 @@ package com.twelvemonkeys.imageio.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.IndexColorModel;
|
||||
@@ -20,9 +21,9 @@ public class IndexedImageTypeSpecifierTest {
|
||||
public void testEquals() {
|
||||
IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
|
||||
IndexedImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
|
||||
IndexedImageTypeSpecifier other = new IndexedImageTypeSpecifier(cm);
|
||||
IndexedImageTypeSpecifier different = new IndexedImageTypeSpecifier(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 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));
|
||||
|
||||
assertEquals(spec, other);
|
||||
assertEquals(other, spec);
|
||||
@@ -41,9 +42,9 @@ public class IndexedImageTypeSpecifierTest {
|
||||
public void testHashCode() {
|
||||
IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
|
||||
IndexedImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
|
||||
IndexedImageTypeSpecifier other = new IndexedImageTypeSpecifier(cm);
|
||||
IndexedImageTypeSpecifier different = new IndexedImageTypeSpecifier(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 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));
|
||||
|
||||
// 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
|
||||
@@ -53,13 +54,13 @@ public class IndexedImageTypeSpecifierTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCreateNull() {
|
||||
new IndexedImageTypeSpecifier(null);
|
||||
IndexedImageTypeSpecifier.createFromIndexColorModel(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateBufferedImageBinary() {
|
||||
IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
IndexedImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
|
||||
ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
|
||||
|
||||
BufferedImage image = spec.createBufferedImage(2, 2);
|
||||
|
||||
@@ -71,7 +72,7 @@ public class IndexedImageTypeSpecifierTest {
|
||||
@Test
|
||||
public void testCreateBufferedImageIndexed() {
|
||||
IndexColorModel cm = new IndexColorModel(8, 256, new int[256], 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
IndexedImageTypeSpecifier spec = new IndexedImageTypeSpecifier(cm);
|
||||
ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm);
|
||||
|
||||
BufferedImage image = spec.createBufferedImage(2, 2);
|
||||
|
||||
|
||||
+13
-13
@@ -19,7 +19,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testGray() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(GRAY, new int [] {0}, false, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int [] {0}, false, false);
|
||||
|
||||
assertEquals(1, spec.getNumBands());
|
||||
assertEquals(1, spec.getNumComponents());
|
||||
@@ -38,7 +38,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testGrayAlpha() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(GRAY, new int [] {0, 1}, true, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int [] {0, 1}, true, false);
|
||||
assertEquals(2, spec.getNumBands());
|
||||
assertEquals(2, spec.getNumComponents());
|
||||
assertEquals(32, spec.getBitsPerBand(0));
|
||||
@@ -57,7 +57,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testRGB() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
|
||||
assertEquals(3, spec.getNumBands());
|
||||
assertEquals(3, spec.getNumComponents());
|
||||
@@ -78,7 +78,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testRGBAlpha() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2, 3}, true, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, false);
|
||||
assertEquals(4, spec.getNumBands());
|
||||
assertEquals(4, spec.getNumComponents());
|
||||
assertEquals(32, spec.getBitsPerBand(0));
|
||||
@@ -99,7 +99,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testRGBAlphaPre() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2, 3}, true, true);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, true);
|
||||
assertEquals(4, spec.getNumBands());
|
||||
assertEquals(4, spec.getNumComponents());
|
||||
assertEquals(32, spec.getBitsPerBand(0));
|
||||
@@ -120,7 +120,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testCMYK() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(CMYK, new int [] {0, 1, 2, 3}, false, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(CMYK, new int [] {0, 1, 2, 3}, false, false);
|
||||
|
||||
assertEquals(4, spec.getNumBands());
|
||||
assertEquals(4, spec.getNumComponents());
|
||||
@@ -142,7 +142,7 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testCMYKAlpha() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(CMYK, new int [] {0, 1, 2, 3, 4}, true, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(CMYK, new int [] {0, 1, 2, 3, 4}, true, false);
|
||||
assertEquals(5, spec.getNumBands());
|
||||
assertEquals(5, spec.getNumComponents());
|
||||
assertEquals(32, spec.getBitsPerBand(0));
|
||||
@@ -165,9 +165,9 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier other = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier different = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2, 3}, true, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier other = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier different = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, false);
|
||||
// Equivalent, but broken, not equal
|
||||
ImageTypeSpecifier broken =
|
||||
ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, DataBuffer.TYPE_INT, false, false);
|
||||
@@ -185,9 +185,9 @@ public class UInt32ImageTypeSpecifierTest {
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
ImageTypeSpecifier spec = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier other = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier different = new UInt32ImageTypeSpecifier(sRGB, new int [] {0, 1, 2, 3}, true, false);
|
||||
ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier other = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false);
|
||||
ImageTypeSpecifier different = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, false);
|
||||
// Equivalent, but broken, not equal
|
||||
ImageTypeSpecifier broken =
|
||||
ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, DataBuffer.TYPE_INT, false, false);
|
||||
|
||||
Reference in New Issue
Block a user