-
Notifications
You must be signed in to change notification settings - Fork 597
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
feat(jpeg): Support encoding/decoding arbitrary metadata as comments #4430
Merged
lgritz
merged 4 commits into
AcademySoftwareFoundation:main
from
lukasstockner:jpeg-metadata
Nov 7, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ba93c68
feat(jpeg): Support encoding/decoding arbitrary metadata as comments
lukasstockner 39c6d81
Merge remote-tracking branch 'origin/main' into jpeg-metadata
lukasstockner 06ad8d5
Make parsing of JPEG comments more robust, handle ImageDescription sm…
lukasstockner 1763e1a
Fix test on Windows
lukasstockner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
Reading src/blender-render.jpg | ||
src/blender-render.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: A60D05FC42FDEE2FC8907531E3641C17D7C1E3AB | ||
channel list: R, G, B | ||
Blender:Camera: "Camera" | ||
Blender:Date: "2024/09/17 15:50:17" | ||
Blender:File: "<untitled>" | ||
Blender:Frame: "001" | ||
Blender:RenderTime: "00:03.49" | ||
Blender:Scene: "Scene" | ||
Blender:Time: "00:00:00:01" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Comparing "src/blender-render.jpg" and "no-attribs.jpg" | ||
PASS | ||
Reading no-attribs.jpg | ||
no-attribs.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: 329B449C07E6649023504E2C8E5130B41985CF7F | ||
channel list: R, G, B | ||
Exif:ColorSpace: 1 | ||
Exif:ExifVersion: "0230" | ||
Exif:FlashPixVersion: "0100" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Reading src/blender-render.jpg | ||
src/blender-render.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: A60D05FC42FDEE2FC8907531E3641C17D7C1E3AB | ||
channel list: R, G, B | ||
Blender:Camera: "Camera" | ||
Blender:Date: "2024/09/17 15:50:17" | ||
Blender:File: "<untitled>" | ||
Blender:Frame: "001" | ||
Blender:RenderTime: "00:03.49" | ||
Blender:Scene: "Scene" | ||
Blender:Time: "00:00:00:01" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Comparing "src/blender-render.jpg" and "with-attribs.jpg" | ||
PASS | ||
Reading with-attribs.jpg | ||
with-attribs.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: 329B449C07E6649023504E2C8E5130B41985CF7F | ||
channel list: R, G, B | ||
Blender:Camera: "Camera" | ||
Blender:Date: "2024/09/17 15:50:17" | ||
Blender:File: "<untitled>" | ||
Blender:Frame: "001" | ||
Blender:RenderTime: "00:03.49" | ||
Blender:Scene: "Scene" | ||
Blender:Time: "00:00:00:01" | ||
Exif:ColorSpace: 1 | ||
Exif:ExifVersion: "0230" | ||
Exif:FlashPixVersion: "0100" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Reading src/blender-render.jpg | ||
src/blender-render.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: A60D05FC42FDEE2FC8907531E3641C17D7C1E3AB | ||
channel list: R, G, B | ||
Blender:Camera: "Camera" | ||
Blender:Date: "2024/09/17 15:50:17" | ||
Blender:File: "<untitled>" | ||
Blender:Frame: "001" | ||
Blender:RenderTime: "00:03.49" | ||
Blender:Scene: "Scene" | ||
Blender:Time: "00:00:00:01" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Comparing "src/blender-render.jpg" and "with-attribs-and-desc.jpg" | ||
PASS | ||
Reading with-attribs-and-desc.jpg | ||
with-attribs-and-desc.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: 329B449C07E6649023504E2C8E5130B41985CF7F | ||
channel list: R, G, B | ||
ImageDescription: "A photo" | ||
Blender:Camera: "Camera" | ||
Blender:Date: "2024/09/17 15:50:17" | ||
Blender:File: "<untitled>" | ||
Blender:Frame: "001" | ||
Blender:RenderTime: "00:03.49" | ||
Blender:Scene: "Scene" | ||
Blender:Time: "00:00:00:01" | ||
Exif:ColorSpace: 1 | ||
Exif:ExifVersion: "0230" | ||
Exif:FlashPixVersion: "0100" | ||
IPTC:Caption: "A photo" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Reading src/blender-render.jpg | ||
src/blender-render.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: A60D05FC42FDEE2FC8907531E3641C17D7C1E3AB | ||
channel list: R, G, B | ||
Blender:Camera: "Camera" | ||
Blender:Date: "2024/09/17 15:50:17" | ||
Blender:File: "<untitled>" | ||
Blender:Frame: "001" | ||
Blender:RenderTime: "00:03.49" | ||
Blender:Scene: "Scene" | ||
Blender:Time: "00:00:00:01" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" | ||
Comparing "src/blender-render.jpg" and "with-colon-desc.jpg" | ||
PASS | ||
Reading with-colon-desc.jpg | ||
with-colon-desc.jpg : 640 x 480, 3 channel, uint8 jpeg | ||
SHA-1: 329B449C07E6649023504E2C8E5130B41985CF7F | ||
channel list: R, G, B | ||
ImageDescription: "Example:Text" | ||
Exif:ColorSpace: 1 | ||
Exif:ExifVersion: "0230" | ||
Exif:FlashPixVersion: "0100" | ||
IPTC:Caption: "Example:Text" | ||
jpeg:subsampling: "4:2:0" | ||
oiio:ColorSpace: "sRGB" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright Contributors to the OpenImageIO project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# https://github.com/AcademySoftwareFoundation/OpenImageIO | ||
|
||
|
||
redirect = ' >> out.txt 2>&1 ' | ||
|
||
# This file was rendered and saved in Blender, and therefore contains metadata | ||
# in the form of comments. | ||
|
||
# Check if the comments are correctly decoded as attributes, and that writing | ||
# to a new JPEG does not include them by default. | ||
command += rw_command ("src", "blender-render.jpg", use_oiiotool=1, | ||
output_filename="no-attribs.jpg") | ||
command += info_command ("no-attribs.jpg", safematch=True) | ||
|
||
# Check that, when jpeg:com_attributes is set, the attributes are preserved. | ||
command += rw_command ("src", "blender-render.jpg", use_oiiotool=1, | ||
output_filename="with-attribs.jpg", | ||
extraargs="--attrib:type=int jpeg:com_attributes 1") | ||
command += info_command ("with-attribs.jpg", safematch=True) | ||
|
||
# Check that JPEG comments that don't match an attribute will be read as ImageDescription. | ||
command += rw_command ("src", "blender-render.jpg", use_oiiotool=1, | ||
output_filename="with-attribs-and-desc.jpg", | ||
extraargs="--attrib:type=int jpeg:com_attributes 1 " | ||
"--attrib:type=string ImageDescription \"A photo\"") | ||
command += info_command ("with-attribs-and-desc.jpg", safematch=True) | ||
|
||
# Check that JPEG comments that would match an attribute will be read as ImageDescription | ||
# if jpeg:com_attributes is 0. | ||
command += rw_command ("src", "blender-render.jpg", use_oiiotool=1, | ||
output_filename="with-colon-desc.jpg", | ||
extraargs="--attrib:type=string ImageDescription \"Example:Text\"") | ||
command += info_command ("with-colon-desc.jpg", safematch=True, | ||
extraargs="--oiioattrib:type=int jpeg:com_attributes 0") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's worth explicitly starting by spelling out:
By the way, is this exactly what we want? What if the first COM looks like "key:value", should that always be slotted into ImageDescription?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer only setting ImageDescription if the parsing fails, but I figured that's a potentially breaking change so I kept it safe for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet that most traditional JPEG COM blocks that are true "image comments" are unlikely to have the specific form of "[ident:]string1:string2" where the optional ident (namespace prefix) follows C identifier rules and string1 won't start or end with whitespace. If we interpret only that pattern as metadata and the first COM that doesn't follow the pattern is "ImageDescription".
I'm willing to risk that an occasional "comment" with a quirky format might be incorrectly interpreted as metadata. Especially if there is some kind of OIIO global option that lets you revert to the old behavior (first COM is always ImageDescription), so somebody can get out of a bind if they have a pile of images with the ambiguous formatting of their COM blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the verdict here, @lukasstockner? Do you want to make any more changes, or do you want to keep the logic as-is and we can always revise later if it causes trouble?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's fine with you, I'll go ahead and add some more logic to only set the ImageDescription if a global option is set and/or the matched key fails a heuristic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.