#865 TIFF: Half decoding fix, now uses standard conversion.

This commit is contained in:
Harald Kuhr 2023-11-15 10:49:33 +01:00
parent 1d3a7fe812
commit 0378f504e7
2 changed files with 12 additions and 10 deletions

View File

@ -87,11 +87,6 @@ public final class Half extends Number implements Comparable<Half> {
} }
else if (exponent != 0) { // Normalized value else if (exponent != 0) { // Normalized value
exponent += 0x1c000; // exp - 15 + 127 exponent += 0x1c000; // exp - 15 + 127
// Smooth transition
if (mantissa == 0 && exponent > 0x1c400) {
return Float.intBitsToFloat((shortBits & 0x8000) << 16 | exponent << 13 | 0x3ff);
}
} }
else if (mantissa != 0) { // && exp == 0 -> subnormal else if (mantissa != 0) { // && exp == 0 -> subnormal
exponent = 0x1c400; // Make it normal exponent = 0x1c400; // Make it normal

View File

@ -1,16 +1,16 @@
package com.twelvemonkeys.imageio.metadata.tiff; package com.twelvemonkeys.imageio.metadata.tiff;
import static org.junit.Assert.assertEquals; import com.twelvemonkeys.io.FastByteArrayOutputStream;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Random; import java.util.Random;
import org.junit.Test; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.twelvemonkeys.io.FastByteArrayOutputStream;
/** /**
* HalfTest. * HalfTest.
@ -36,6 +36,13 @@ public class HalfTest {
} }
} }
@Test
public void testExactEncoding() {
for (short half = -2048; half < 2048; half++) {
assertEquals(String.valueOf(half), half, Half.shortBitsToFloat(Half.floatToShortBits(half)), 0);
}
}
@Test @Test
public void testRoundTripBack() { public void testRoundTripBack() {
for (int i = 0; i < 1024; i++) { for (int i = 0; i < 1024; i++) {