Fully support period == 1 (no subsampling) in subsampleRow even if different arrays

This commit is contained in:
Harald Kuhr 2024-09-26 10:31:27 +02:00
parent 9c8ae4ac3e
commit 84c10ed96d
2 changed files with 75 additions and 0 deletions

View File

@ -232,6 +232,10 @@ public final class IIOUtil {
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
// Period == 1 is a no-op...
if (samplePeriod == 1) {
if (srcRow != destRow) {
System.arraycopy(srcRow, srcPos, destRow, destPos, srcWidth);
}
return;
}
@ -275,6 +279,10 @@ public final class IIOUtil {
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
// Period == 1 is a no-op...
if (samplePeriod == 1) {
if (srcRow != destRow) {
System.arraycopy(srcRow, srcPos, destRow, destPos, srcWidth);
}
return;
}
@ -297,6 +305,10 @@ public final class IIOUtil {
int samplesPerPixel, int bitsPerSample, int samplePeriod) {
// Period == 1 is a no-op...
if (samplePeriod == 1) {
if (srcRow != destRow) {
System.arraycopy(srcRow, srcPos, destRow, destPos, srcWidth);
}
return;
}

View File

@ -139,6 +139,69 @@ public class IIOUtilTest {
assertArrayEquals(expected, output);
}
@Test
public void subsampleRowPeriod1ByteSameArray() {
byte[] inputOutput = {-1, 0, (byte) 0xAA, 0, -1};
byte[] expected = {-1, 0, (byte) 0xAA, 0, -1};
IIOUtil.subsampleRow(inputOutput, 0, inputOutput.length, inputOutput, 0, 1, 8, 1);
assertArrayEquals(expected, inputOutput);
}
@Test
public void subsampleRowPeriod1ByteDifferentArray() {
byte[] input = {-1, 0, (byte) 0xAA, 0, -1};
byte[] output = new byte[input.length];
byte[] expected = {-1, 0, (byte) 0xAA, 0, -1};
IIOUtil.subsampleRow(input, 0, input.length, output, 0, 1, 8, 1);
assertArrayEquals(expected, output);
}
@Test
public void subsampleRowPeriod1ShortSameArray() {
short[] inputOutput = {-1, 0, (short) 0xAA77, 0, -1};
short[] expected = {-1, 0, (short) 0xAA77, 0, -1};
IIOUtil.subsampleRow(inputOutput, 0, inputOutput.length, inputOutput, 0, 4, 4, 1);
assertArrayEquals(expected, inputOutput);
}
@Test
public void subsampleRowPeriod1ShortDifferentArray() {
short[] input = {-1, 0, (short) 0xAA77, 0, -1};
short[] output = new short[input.length];
short[] expected = {-1, 0, (short) 0xAA77, 0, -1};
IIOUtil.subsampleRow(input, 0, input.length, output, 0, 1, 16, 1);
assertArrayEquals(expected, output);
}
@Test
public void subsampleRowPeriod1IntSameArray() {
int[] inputOutput = {-1, 0, 0xAA997755, 0, -1};
int[] expected = {-1, 0, 0xAA997755, 0, -1};
IIOUtil.subsampleRow(inputOutput, 0, inputOutput.length, inputOutput, 0, 1, 32, 1);
assertArrayEquals(expected, inputOutput);
}
@Test
public void subsampleRowPeriod1IntDifferentArray() {
int[] input = {-1, 0, 0xAA997755, 0, -1};
int[] output = new int[input.length];
int[] expected = {-1, 0, 0xAA997755, 0, -1};
IIOUtil.subsampleRow(input, 0, input.length, output, 0, 4, 8, 1);
assertArrayEquals(expected, output);
}
private int divCeil(int numerator, int denominator) {
return (numerator + denominator - 1) / denominator;
}