Skip to content

Commit

Permalink
Support BigTIFF encoded TIFF data
Browse files Browse the repository at this point in the history
Note that while BigTIFF supports files greater than 2 GiB in size, our current implementation does not due to the pervasive use of Int32 throughout the code to represent offsets into the data.
  • Loading branch information
don-vip committed Jul 29, 2024
1 parent f5ddfcd commit 6964deb
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 96 deletions.
4 changes: 3 additions & 1 deletion Source/com/drew/imaging/FileTypeDetector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 Drew Noakes and contributors
* Copyright 2002-2022 Drew Noakes and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,8 @@ public class FileTypeDetector
_root.addPath(FileType.Jpeg, new byte[]{(byte)0xff, (byte)0xd8});
_root.addPath(FileType.Tiff, "II".getBytes(), new byte[]{0x2a, 0x00});
_root.addPath(FileType.Tiff, "MM".getBytes(), new byte[]{0x00, 0x2a});
_root.addPath(FileType.Tiff, "II".getBytes(), new byte[]{0x2b, 0x00}); // BigTIFF
_root.addPath(FileType.Tiff, "MM".getBytes(), new byte[]{0x00, 0x2b}); // BigTIFF
_root.addPath(FileType.Psd, "8BPS".getBytes());
_root.addPath(FileType.Png, new byte[]{(byte)0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52});
_root.addPath(FileType.Bmp, "BM".getBytes()); // Standard Bitmap Windows and OS/2
Expand Down
16 changes: 14 additions & 2 deletions Source/com/drew/imaging/tiff/TiffDataFormat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 Drew Noakes and contributors
* Copyright 2002-2022 Drew Noakes and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,10 @@ public class TiffDataFormat
public static final int CODE_RATIONAL_S = 10;
public static final int CODE_SINGLE = 11;
public static final int CODE_DOUBLE = 12;
// From BigTIFF
public static final int CODE_INT64_U = 16;
public static final int CODE_INT64_S = 17;
public static final int CODE_IFD8 = 18;

@NotNull public static final TiffDataFormat INT8_U = new TiffDataFormat("BYTE", CODE_INT8_U, 1);
@NotNull public static final TiffDataFormat STRING = new TiffDataFormat("STRING", CODE_STRING, 1);
Expand All @@ -55,14 +59,18 @@ public class TiffDataFormat
@NotNull public static final TiffDataFormat RATIONAL_S = new TiffDataFormat("SRATIONAL", CODE_RATIONAL_S, 8);
@NotNull public static final TiffDataFormat SINGLE = new TiffDataFormat("SINGLE", CODE_SINGLE, 4);
@NotNull public static final TiffDataFormat DOUBLE = new TiffDataFormat("DOUBLE", CODE_DOUBLE, 8);
// From BigTIFF
@NotNull public static final TiffDataFormat INT64_U = new TiffDataFormat("ULONG8", CODE_INT64_U, 8);
@NotNull public static final TiffDataFormat INT64_S = new TiffDataFormat("SLONG8", CODE_INT64_S, 8);
@NotNull public static final TiffDataFormat IFD8 = new TiffDataFormat("IFD8", CODE_IFD8, 8);

@NotNull
private final String _name;
private final int _tiffFormatCode;
private final int _componentSizeBytes;

@Nullable
public static TiffDataFormat fromTiffFormatCode(int tiffFormatCode)
public static TiffDataFormat fromTiffFormatCode(int tiffFormatCode, boolean isBigTiff)
{
switch (tiffFormatCode) {
case 1: return INT8_U;
Expand All @@ -77,6 +85,10 @@ public static TiffDataFormat fromTiffFormatCode(int tiffFormatCode)
case 10: return RATIONAL_S;
case 11: return SINGLE;
case 12: return DOUBLE;
// From BigTIFF
case 16: return isBigTiff ? INT64_U : null;
case 17: return isBigTiff ? INT64_S : null;
case 18: return isBigTiff ? IFD8 : null;
}
return null;
}
Expand Down
10 changes: 8 additions & 2 deletions Source/com/drew/imaging/tiff/TiffHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public interface TiffHandler
* validation or perhaps differentiating the type of mapping to use for observed tags and IFDs.
*
* @param marker the 2-byte value found at position 2 of the TIFF header
* @return The TIFF standard via which to interpret the data stream.
*/
void setTiffMarker(int marker) throws TiffProcessingException;
TiffStandard processTiffMarker(int marker) throws TiffProcessingException;

boolean tryEnterSubIfd(int tagId);
boolean hasFollowerIfd();
Expand All @@ -59,7 +60,8 @@ boolean customProcessTag(int tagOffset,
@NotNull Set<Integer> processedIfdOffsets,
@NotNull RandomAccessReader reader,
int tagId,
int byteCount) throws IOException;
int byteCount,
boolean isBigTiff) throws IOException;

void warn(@NotNull String message);
void error(@NotNull String message);
Expand All @@ -84,4 +86,8 @@ boolean customProcessTag(int tagOffset,
void setInt32sArray(int tagId, @NotNull int[] array);
void setInt32u(int tagId, long int32u);
void setInt32uArray(int tagId, @NotNull long[] array);
void setInt64S(int tagId, long int64S);
void setInt64SArray(int tagId, @NotNull long[] array);
void setInt64U(int tagId, long int64U);
void setInt64UArray(int tagId, @NotNull long[] array);
}
Loading

0 comments on commit 6964deb

Please sign in to comment.