TIKA-4861: Detect raw camera formats by content - #3099
Merged
Conversation
… the TIFF-based ones, magic for RAF, RW2, MRW and ORF
… NRW/BigTIFF/cycle tests
…t PhotometricInterpretation counts as raw (Nikon Z 6, Samsung NX1)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Apache Tika’s raw camera format detection so TIFF-based raw files (e.g., NEF/ARW/PEF/SRW/DNG) can be correctly identified by content even when a resource name/extension is missing, and extends mime magic coverage for several other raw formats (RAF/RW2/MRW/ORF).
Changes:
- Add
RawTiffDetectorto distinguish TIFF-based raw camera formats from plain TIFF by walking TIFF/BigTIFF IFDs (including SubIFDs) within a bounded prefix. - Add
image/x-raw-samsungmime type and ensureRawTiffParsersupports parsing Samsung SRW. - Expand mime magic signatures (Fuji RAF, Panasonic RW2, Minolta MRW, additional Olympus ORF byte orders) and add/extend integration/unit tests covering the new behavior.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/detect/image/RawTiffDetectorTest.java | Adds focused unit tests for raw-vs-TIFF discrimination logic, BigTIFF handling, cycle safety, and stream reset behavior. |
| tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/main/java/org/apache/tika/parser/image/RawTiffParser.java | Extends supported types to include image/x-raw-samsung. |
| tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/main/java/org/apache/tika/detect/image/RawTiffDetector.java | Introduces content-based detector for TIFF-based raw camera formats with bounded read and safe IFD/SubIFD traversal. |
| tika-parsers/tika-parsers-standard/tika-parsers-standard-integration-tests/src/test/java/org/apache/tika/mime/TestMimeTypes.java | Adds assertions for new/expanded raw magic signatures and documents the separation between MimeTypes-only vs container-aware detection for TIFF-based raws. |
| tika-parsers/tika-parsers-standard/tika-parsers-standard-integration-tests/src/test/java/org/apache/tika/detect/TestContainerAwareDetector.java | Adds integration test ensuring container-aware detection resolves TIFF-based raw types by data without relying on file name. |
| tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml | Adds image/x-raw-samsung and adds/extends magic matches for RAF/RW2/MRW/ORF variants. |
| CHANGES.txt | Documents the new content-based detection and the new Samsung raw mime type. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
Thanks @THausherr for helping out :) |
Contributor
Author
|
Wooop wooop 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Raw camera formats were detected by extension only; without a name they came back as
image/tiffand the previews of TIKA-4824 never appeared.RawTiffDetector(tika-parser-image-module) tells the TIFF-based formats apart by their image directory:DNGVersiontag: DNGCompressioncode (ExifTool's rule): Nikon, Sony, Pentax, SamsungMake: the uncompressed variantsA TIFF a camera wrote has RGB data and stays a TIFF. The third rule's shape-based part exists only for the Samsung NX1 and is the weakest; dropping it costs just the NX1 without a file name.
It reads the stream on demand up to 1 MiB (directories sit behind the embedded previews, up to ~460 KB in practice), a plain TIFF costs a few KB, and the stream is reset.
Also: magic entries for RAF, RW2, MRW and the other ORF byte orders;
image/x-raw-samsungadded and handled byRawTiffParser.Verified without a file name on 21 files from raw.pixls.us (NEF D1 to Z 6, NRW, ARW old and new, SR2, SRW NX100 and NX1, PEF, DNG from Ricoh, Leica and Nokia, RAF, RW2, MRW, ORF, and a CR2 that keeps its type), 20 to 600 microseconds each. Not added to the repo because of their size; the unit tests build their own TIFFs instead.
https://issues.apache.org/jira/browse/TIKA-4861