Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for variable length custom tags #173

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

pieleric
Copy link
Contributor

In libtiff, custom tags with variable length (eg, a binary blob) are indicated with the special constants TIFF_VARIABLE (-1) or TIFF_VARIABLE2 (-3). In such case, when reading a field, the length is passed as first argument, and a pointer to the data as second argument.

So far, some standard tags with such format were supported, but not custom tags. We needed such tags to support reading metadata from some microscopes. We had to hack it by modifying directly tifftags. You can see it here:
https://github.com/delmic/odemis/blob/a025bc7d991a37b408adb031a2561c35c3b87d23/src/odemis/dataio/tiff.py#L95

This change allows to directly extend the custom tags, with add_tags().

Also fix the names of the automatically created attribute, which got broken in the switch from Python 2 to 3.
What should have been named, for instance, TIFFTAG_CUSTOM, was named like TIFFTAG_b'CUSTOM', quotes included!

Also fix the test cases, which were not working, mostly related to reading/writing tags.

Now, all the tests pass, as run with:
python3 ./libtiff/libtiff_ctypes.py

@coveralls
Copy link

coveralls commented Jan 11, 2024

Pull Request Test Coverage Report for Build 7534177906

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 39.325%

Totals Coverage Status
Change from base Build 7492144358: -0.1%
Covered Lines: 1700
Relevant Lines: 4323

💛 - Coveralls

libtiff/libtiff_ctypes.py Outdated Show resolved Hide resolved
@pieleric pieleric force-pushed the ctypes-suport-adding-custom-tags-vlen branch from 363f5ec to a3a8bbc Compare January 14, 2024 00:48
Copy link
Owner

@pearu pearu left a comment

Choose a reason for hiding this comment

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

I have a couple of minor nits but overall looks good to me. Thanks!

libtiff/libtiff_ctypes.py Outdated Show resolved Hide resolved
libtiff/libtiff_ctypes.py Show resolved Hide resolved
libtiff/libtiff_ctypes.py Outdated Show resolved Hide resolved
@pieleric pieleric force-pushed the ctypes-suport-adding-custom-tags-vlen branch from a3a8bbc to 4cb287b Compare January 14, 2024 23:31
@pieleric pieleric force-pushed the ctypes-suport-adding-custom-tags-vlen branch 2 times, most recently from 10ff716 to d1b67d1 Compare January 15, 2024 17:04
In libtiff, custom tags with variable length (eg, a binary blob) are indicated with
the special constants TIFF_VARIABLE (-1) or TIFF_VARIABLE2 (-3). In such
case, when reading a field the length is passed as first argument, and
the data as a pointer as second argument.

So far, some standard tags with such format were supported, but not
custom tags.
=> Add support for such tags.

Also fix the names of the attribute created automatically, which got
broken in the switch from Python 2 to 3.
What should have been named, for instance, TIFFTAG_CUSTOM, was named
like TIFFTAG_b'CUSTOM', quotes included!

Also fix the test cases, which were not working, mostly related to
reading/writing tags.
@pieleric pieleric force-pushed the ctypes-suport-adding-custom-tags-vlen branch from d1b67d1 to 8fdf307 Compare January 15, 2024 21:30
@pieleric pieleric requested a review from pearu January 15, 2024 21:31
Copy link
Owner

@pearu pearu left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks, @pieleric!

@djhoese djhoese self-assigned this Jan 16, 2024
@djhoese djhoese merged commit d9c97de into pearu:master Jan 16, 2024
13 checks passed
@djhoese djhoese changed the title ctypes: support adding custom tags with variable length Add support for variable length custom tags Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants