Skip to content

TIKA-4861: Detect raw camera formats by content - #3099

Merged
THausherr merged 5 commits into
apache:mainfrom
dschmidt:raw-detection
Aug 30, 2026
Merged

TIKA-4861: Detect raw camera formats by content#3099
THausherr merged 5 commits into
apache:mainfrom
dschmidt:raw-detection

Conversation

@dschmidt

@dschmidt dschmidt commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Raw camera formats were detected by extension only; without a name they came back as image/tiff and the previews of TIKA-4824 never appeared.

RawTiffDetector (tika-parser-image-module) tells the TIFF-based formats apart by their image directory:

  1. DNGVersion tag: DNG
  2. vendor Compression code (ExifTool's rule): Nikon, Sony, Pentax, Samsung
  3. sensor data (CFA/LinearRaw, or a full-resolution single deep sample without PhotometricInterpretation) plus Make: the uncompressed variants

A 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-samsung added and handled by RawTiffParser.

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

… the TIFF-based ones, magic for RAF, RW2, MRW and ORF
…t PhotometricInterpretation counts as raw (Nikon Z 6, Samsung NX1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RawTiffDetector to distinguish TIFF-based raw camera formats from plain TIFF by walking TIFF/BigTIFF IFDs (including SubIFDs) within a bounded prefix.
  • Add image/x-raw-samsung mime type and ensure RawTiffParser supports 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.

@dschmidt

Copy link
Copy Markdown
Contributor Author

Thanks @THausherr for helping out :)

@THausherr
THausherr merged commit 0baf52f into apache:main Aug 30, 2026
4 checks passed
@dschmidt

Copy link
Copy Markdown
Contributor Author

Wooop wooop 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants