/** * Gets the key/value pairs. * The array is sorted in ascending key order. * @return the key/value pairs with {@code pairs[i] = {key, value}} */ public int[][] getPairs() { final int[] keys = getKeys(); final int[][] pairs = new int[keys.length][2]; for (int i = 0; i < keys.length; i++) { pairs[i][0] = keys[i]; pairs[i][1] = getValue(keys[i]); } return pairs; }
/** * Gets the key/value ranges. * @return {@code ranges = {{keyMin, keyMax}, {valueMin, valueMax}}} */ public int[][] getRanges() { int[] keys = getKeys(); int keyMin = Integer.MAX_VALUE; int keyMax = Integer.MIN_VALUE; int valueMin = Integer.MAX_VALUE; int valueMax = Integer.MIN_VALUE; for (int key : keys) { keyMin = Math.min(keyMin, key); keyMax = Math.max(keyMax, key); final int value = getValue(key); valueMin = Math.min(valueMin, value); valueMax = Math.max(valueMax, value); } return new int[][]{{keyMin, keyMax}, {valueMin, valueMax}}; }
public static PlanarImage createMapping2(RenderedImage sourceImage, IntMap indexMap) { final Raster sourceData = sourceImage.getData(); final WritableRaster targetData = sourceData.createCompatibleWritableRaster(); final DataBuffer targetBuffer = targetData.getDataBuffer(); for (int i = 0; i < targetBuffer.getSize(); i++) { final int index = indexMap.getValue(sourceData.getDataBuffer().getElem(i)); targetBuffer.setElem(i, index); } final BufferedImage image = new BufferedImage(sourceData.getWidth(), sourceData.getHeight(), BufferedImage.TYPE_BYTE_GRAY); image.setData(targetData); return PlanarImage.wrapRenderedImage(image); }
final byte[] table = new byte[keyRange + 2]; for (int i = 1; i < table.length - 1; i++) { final int value = intMap.getValue(keyMin + i - 1); table[i] = (byte) (value != IntMap.NULL ? value : undefinedIndex); final short[] table = new short[keyRange + 2]; for (int i = 1; i < table.length; i++) { final int value = intMap.getValue(keyMin + i - 1); table[i] = (short) (value != IntMap.NULL ? value : undefinedIndex); final int[] table = new int[keyRange + 2]; for (int i = 1; i < table.length; i++) { final int value = intMap.getValue(keyMin + i - 1); table[i] = value != IntMap.NULL ? value : undefinedIndex;
final byte[] table = new byte[keyRange + 2]; for (int i = 1; i < table.length - 1; i++) { final int value = intMap.getValue(keyMin + i - 1); table[i] = (byte) (value != IntMap.NULL ? value : undefinedIndex); final short[] table = new short[keyRange + 2]; for (int i = 1; i < table.length; i++) { final int value = intMap.getValue(keyMin + i - 1); table[i] = (short) (value != IntMap.NULL ? value : undefinedIndex); final int[] table = new int[keyRange + 2]; for (int i = 1; i < table.length; i++) { final int value = intMap.getValue(keyMin + i - 1); table[i] = value != IntMap.NULL ? value : undefinedIndex;
assertEquals(-4, intMap.getValue(-10000)); assertEquals(-3, intMap.getValue(-1000)); assertEquals(-2, intMap.getValue(-100)); assertEquals(-1, intMap.getValue(-10)); assertEquals(0, intMap.getValue(1)); assertEquals(1, intMap.getValue(10)); assertEquals(2, intMap.getValue(100)); assertEquals(3, intMap.getValue(1000)); assertEquals(4, intMap.getValue(10000)); assertEquals(IntMap.NULL, intMap.getValue(-10000 + 1)); assertEquals(IntMap.NULL, intMap.getValue(-1000 + 1)); assertEquals(IntMap.NULL, intMap.getValue(-100 + 1)); assertEquals(IntMap.NULL, intMap.getValue(-10 + 1)); assertEquals(IntMap.NULL, intMap.getValue(1 - 1)); assertEquals(IntMap.NULL, intMap.getValue(10 - 1)); assertEquals(IntMap.NULL, intMap.getValue(100 - 1)); assertEquals(IntMap.NULL, intMap.getValue(1000 - 1)); assertEquals(IntMap.NULL, intMap.getValue(10000 - 1)); assertEquals(IntMap.NULL, intMap.getValue(1)); assertEquals(IntMap.NULL, intMap.getValue(1000));
public void testSequentialAccess() { IntMap intMap = new IntMap(); assertEquals(0, intMap.getSize()); for (int i = -10000; i <= 10000; i++) { intMap.putValue(i, i + 99); } for (int i = -10000; i <= 10000; i++) { assertEquals(i + 99, intMap.getValue(i)); } assertEquals(20001, intMap.getSize()); for (int i = -10000; i <= 10000; i++) { intMap.removeValue(i); } assertEquals(0, intMap.getSize()); }
for (int pixelIndex = 0; pixelIndex < data.getNumElems(); pixelIndex++) { int sample = data.getElemIntAt(pixelIndex); int colorIndex = sampleColorIndexMap.getValue(sample); rgbSamples[pixelIndex * numColorComponents] = colorIndex != IntMap.NULL ? (byte) colorIndex : (byte) noDataIndex;