Skip to content

Commit

Permalink
#865 TIFF: Half decoding fix, now uses standard conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldk committed Nov 15, 2023
1 parent 1d3a7fe commit 0378f50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ public static float shortBitsToFloat(final short shortBits) {
}
else if (exponent != 0) { // Normalized value
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
exponent = 0x1c400; // Make it normal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.twelvemonkeys.imageio.metadata.tiff;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.twelvemonkeys.io.FastByteArrayOutputStream;

import org.junit.Test;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Random;

import org.junit.Test;

import com.twelvemonkeys.io.FastByteArrayOutputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* HalfTest.
Expand All @@ -36,6 +36,13 @@ public void testRoundTrip() {
}
}

@Test
public void testExactEncoding() {
for (short half = -2048; half < 2048; half++) {
assertEquals(String.valueOf(half), half, Half.shortBitsToFloat(Half.floatToShortBits(half)), 0);
}
}

@Test
public void testRoundTripBack() {
for (int i = 0; i < 1024; i++) {
Expand Down

0 comments on commit 0378f50

Please sign in to comment.