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 EXIF write support to PNG output. #3736

Merged

Conversation

joris-nijs
Copy link
Contributor

@joris-nijs joris-nijs commented Jan 3, 2023

Description

Stores any EXIF data from the given ImageSpec into the PNG eXIf chunk.

Tests

Checklist:

  • I have read the contribution guidelines.
  • If this is more extensive than a small change to existing code, I
    have previously submitted a Contributor License Agreement
    (individual, and if there is any way my
    employers might think my programming belongs to them, then also
    corporate).
    Change is small enough to not require a CLA
  • I have updated the documentation, if applicable. Not applicable I think
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • My code follows the prevailing code style of this project.

Stores any Exif data from the given ImageSpec into the PNG eXIf chunk.
@joris-nijs
Copy link
Contributor Author

If you think this contribution is valuable, could you give some guidance on:

  • whether a test should be added somewhere
  • whether a CLA is required for a change this small (I did do this on company time)

@@ -684,6 +684,13 @@ write_info(png_structp& sp, png_infop& ip, int& color_type, ImageSpec& spec,
(png_uint_32)(yres * scale), unittype);
}

#ifdef PNG_eXIf_SUPPORTED
Copy link
Collaborator

Choose a reason for hiding this comment

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

What determines if PNG_eXIf_SUPPORTED is found? Is it always present in sufficiently new libpng? (If so, how new? Is it always present based on a minimum version that we should try enforcing?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed libpng >= 1.6.32 added support for the eXIf chunk in PNG and defines PNG_EXIf_SUPPORTED. To be honest, I'm not entirely sure if there is a way to build libpng >= 1.6.32 without this support. I took the same approach as is used elsewhere in this file for reading eXIf data.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense.

#ifdef PNG_eXIf_SUPPORTED
std::vector<char> exifBlob;
encode_exif(spec, exifBlob, endian::big);
png_set_eXIf_1(sp, ip, static_cast<png_uint_32>(exifBlob.size()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also be using png_get_eXIf functions for the reading, or is what we have sufficient?

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, OIIO seems to read Exif from PNG from the eXIf chunk and from embedded text (unofficial convention from before the eXIf chunk existed).

@lgritz
Copy link
Collaborator

lgritz commented Jan 3, 2023

whether a test should be added somewhere -- yes, it would be helpful to test this. I think the best approach would be to augment testsuite/png/run.py to just write a simple small png with some Exif metadata, then print the metadata for the file you wrote and make sure it matches what you think you set? I can help you with this if you aren't quite sure what to do in those scripts.

whether a CLA is required for a change this small (I did do this on company time) -- that mostly depends on the arrangement you have with your company. For a change this small, the OIIO project doesn't insist on a CLA. But you know more about the relationship with your employers. If you think there could be any dispute and you want to get it in writing that it was ok for you to contribute this code, then by all means have them fill out a CLA (more for your safety than ours). But if you are confident that company policy is that you are free to make contributions to open source projects like this one, then we'll take it at face value and won't require a CLA.

@joris-nijs
Copy link
Contributor Author

I added a test to the png test suite as you suggested. Please let me know if you want this to be extended more.

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

Well done, that's exactly the kind of test I had in mind.

@lgritz
Copy link
Collaborator

lgritz commented Jan 5, 2023

It turns out that for many of our CI tests (which purposely span many versions of various dependencies), the ones running in CentOS7-based containers are using an older version of libpng that doesn't support this feature! So the new testsuite/png/ref/out.txt now no longer matches the output of those tests.

To fix it, restore the original out.txt and name it out-libpng15.txt (leaving out.txt being the correct output for the newer libpng varieties). The testsuite scripts will know that a test can pass if it matches any of the reference outputs.

@lgritz
Copy link
Collaborator

lgritz commented Jan 8, 2023

CI is still failing, but I know why, it's simple. I'm going to merge this and then just immediately amend the fix myself.

Thanks for the patch!

@lgritz lgritz merged commit 8cfa5f9 into AcademySoftwareFoundation:master Jan 8, 2023
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Jan 12, 2023
* Add Exif write support to PNG output.

Stores any Exif data from the given ImageSpec into the PNG eXIf chunk.

* add test for writing Exif data in png

* add test reference output for libpng versions not supporting the eXIf chunk.

* Update testsuite/png/ref/out-libpng15.txt

Co-authored-by: Joris Nijs <joris.nijs@esko.com>
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.

None yet

4 participants