Skip to content

Commit

Permalink
style check and some other cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
WeatherGod committed May 6, 2024
1 parent bbdf615 commit 07e9ec3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
27 changes: 12 additions & 15 deletions cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,20 @@ private int writeIntValue(ByteBuffer buffer, IFDEntry ifd, int v) {
case 2:
case 6:
case 7:
// unsigned byte and ascii
// signed byte and undefined (usually treated as raw binary)
// unsigned byte and ascii
// signed byte and undefined (usually treated as raw binary)
buffer.put((byte) v);
return 1;
case 3:
case 8:
// unsigned and signed short
// unsigned and signed short
buffer.putShort((short) v);
return 2;
case 4:
case 5:
case 9:
case 10:
// unsigned and signed rational and 32-bit integer
// unsigned and signed rational and 32-bit integer
buffer.putInt(v);
return 4;
}
Expand Down Expand Up @@ -558,32 +558,29 @@ private void readValues(ByteBuffer buffer, IFDEntry ifd) {
private int readIntValue(ByteBuffer buffer, IFDEntry ifd) {
switch (ifd.type.code) {
case 1:
// unsigned byte
//return (int) buffer.get() & 0xff;
case 2:
// unsigned ascii
// unsigned byte and unsigned ascii
return (int) buffer.get() & 0xff;
case 3:
// unsigned short
// unsigned short
return readUShortValue(buffer);
case 4:
case 5:
// unsigned rational and 32-bit integer
// unsigned rational and unsigned 32-bit integer
// Yes, this can lead to truncation. This is a bug
// in the design of the IFDEntry API
return (int) (buffer.getInt() & 0xffffffffL);
//return buffer.getInt();
case 6:
case 7:
// signed byte & "undefined" (usually treated as binary data
// signed byte and "undefined" (usually treated as binary data)
return (int) buffer.get();
case 8:
// signed short
return (int) buffer.getShort();
// signed short
return (int) buffer.getShort();
case 9:
case 10:
// signed rational and 32-bit integer
return buffer.getInt();
// signed rational and signed 32-bit integer
return buffer.getInt();
}
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions cdm/misc/src/test/java/ucar/nc2/geotiff/TestIFDEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static List<Object[]> getTestParameters() {
// for all possible values because Java's integer is signed.
result.add(new Object[] {new IFDEntry(null, FieldType.LONG, 1), Integer.MAX_VALUE});

//Signed
// Signed
result.add(new Object[] {new IFDEntry(null, FieldType.SBYTE, 1), 0});
result.add(new Object[] {new IFDEntry(null, FieldType.SBYTE, 1), Byte.MIN_VALUE});
result.add(new Object[] {new IFDEntry(null, FieldType.SBYTE, 1), Byte.MAX_VALUE});
Expand Down Expand Up @@ -89,8 +89,8 @@ public void testRoundtrip() throws ReflectiveOperationException {
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
buffer.order(byteOrder);

logger.info("geotiff methods: {}", geotiff.getClass().getDeclaredMethods());
Method writeMethod = geotiff.getClass().getDeclaredMethod("writeIntValue", ByteBuffer.class, ifd.getClass(), int.class);
Method writeMethod =
geotiff.getClass().getDeclaredMethod("writeIntValue", ByteBuffer.class, ifd.getClass(), int.class);
Method readMethod = geotiff.getClass().getDeclaredMethod("readIntValue", ByteBuffer.class, ifd.getClass());
readMethod.setAccessible(true);
writeMethod.setAccessible(true);
Expand Down

0 comments on commit 07e9ec3

Please sign in to comment.