Suppress spurious libtiff warnings when decoding GeoTIFF files#52
Open
shreyaskommuri wants to merge 2 commits intoNVIDIA:mainfrom
Open
Suppress spurious libtiff warnings when decoding GeoTIFF files#52shreyaskommuri wants to merge 2 commits intoNVIDIA:mainfrom
shreyaskommuri wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
GeoTIFF embeds geographic metadata using tags that libtiff does not recognise natively (ModelPixelScale 33550, ModelTiepoint 33922, ModelTransformation 34264, GeoKeyDirectory 34735, GeoDoubleParams 34736, GeoAsciiParams 34737, GDAL_METADATA 42112, GDAL_NODATA 42113). libtiff emits "Unknown field with tag X encountered" warnings for each one. The image data is decoded correctly; only the warnings pollute stderr. Install a custom TIFFWarningHandler (SuppressGeoTIFFTagWarnings) in error_handling.h that silently drops warnings for these eight known tags and forwards all other libtiff warnings to stderr unchanged. Call InstallGeoTIFFWarningFilter() — which uses std::call_once so the handler is registered exactly once per process — from libtiffExtensionCreate in libtiff_ext.cpp, which is the natural entry point for the libtiff extension. Add test_decode_tiff_geotiff to test/python/test_decode_tiff.py. The test helper _create_geotiff builds a valid TIFF from scratch using only struct (no third-party dependency), embedding all eight suppressed tags. The test decodes the synthetic file with CPU_ONLY and default backends and asserts correct pixel values. Fixes: NVIDIA/DALI#6114 Signed-off-by: shreyaskommuri <shreyaskommuri@gmail.com>
b"0\x00" is 2 bytes — since count*typesize (2) <= 4, TIFF requires the value to be stored inline in the IFD entry, not as a file offset. The IFD entry was incorrectly treating a file offset as the value. Use b"-9999\x00" (6 bytes) so the offset is spec-valid. Signed-off-by: shreyaskommuri <shreyaskommuri@gmail.com>
4 tasks
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.
Summary
GeoTIFF embeds geographic metadata using tags that libtiff does not recognise natively (ModelPixelScale 33550, ModelTiepoint 33922, ModelTransformation 34264, GeoKeyDirectory 34735, GeoDoubleParams 34736, GeoAsciiParams 34737, GDAL_METADATA 42112, GDAL_NODATA 42113). libtiff emits
TIFFReadDirectory: Warning, Unknown field with tag X encounteredfor each one on every decode. The image data is decoded correctly; only the warnings pollute stderr.TIFFWarningHandler(SuppressGeoTIFFTagWarnings) inextensions/libtiff/error_handling.hthat silently drops warnings for the eight known GeoTIFF/GDAL tags and forwards all other libtiff warnings to stderr unchanged. Guards against a nullmoduleargument (permitted by the libtiff contract).InstallGeoTIFFWarningFilter()— which usesstd::call_oncewith a function-localstaticin aninlinefunction, so theonce_flagis shared across all translation units and the handler is registered exactly once per process — fromlibtiffExtensionCreateinlibtiff_ext.cpp._create_geotifftest helper intest/python/test_decode_tiff.pythat builds a valid 4×4 GeoTIFF from scratch using onlystruct(no third-party dependency), embedding all eight suppressed tags. Addtest_decode_tiff_geotiffthat decodes the synthetic file withCPU_ONLYand default backends and asserts correct pixel values.Related
Ported from NVIDIA/DALI#6336 at the request of @jantonguirao — the fix belongs at the libtiff layer in nvImageCodec rather than in DALI's image decoder.
Closes NVIDIA/DALI#6114 (via nvImageCodec bump in DALI).
Type of Change
Test plan
_create_geotiffhelper produces a TIFF-spec-valid file (all 8 GeoTIFF tags, correct inline/offset layout, pixel data intact)test_decode_tiff_geotiffparametrized overCPU_ONLYand default backendspytest test/python/test_decode_tiff.py::test_decode_tiff_geotiffin CIAI Disclosure
Signed-off-by: shreyaskommuri shreyaskommuri@gmail.com