Skip to content

Commit

Permalink
oiiotool: attribute actions get subimage controls (#3384)
Browse files Browse the repository at this point in the history
I realized that --attrib (and several related actions) only set the
attribute as directed for the first subimage if it's a multi-image
file (such as a multi-part exr), or all of them if the -a flag is
used.  But there was no ability to set it for a particular (non-first)
subimage, like many other oiiotool actions have the ability to do.

So in this patch, I refactor the following commands to use the
OiiotoolOp and related macros, which automatically make it responsive
to the `:subimages=` optional modifiers:

    --attrib
    --sattrib
    --eraseattrib
    --caption
    --orientation
    --clear-keywords
    --iscolorspace

As a bonus aside, one thing this lets you do is set a different
compression method per-subimage using, e.g.,
`--attrib compression:subimages=3 dwaa:100`.
But if you set compression with `--attrib compression`, do not also
use `--compression`, which will override it and also apply to all
subimages.
  • Loading branch information
lgritz authored Apr 21, 2022
1 parent 5767c62 commit 965cf04
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 420 deletions.
65 changes: 57 additions & 8 deletions src/doc/oiiotool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,14 @@ current top image.

Optional appended modifiers include:

- `type=` *typename* : Specify the metadata type.

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).
Only included subimages will have the attribute changed. If subimages
are not set, only the first subimage will be changed, or all subimages
if the `-a` command line flag was used.

`:type=` *typename* : Specify the metadata type.

If the optional `type=` specifier is used, that provides an explicit
type for the metadata. If not provided, it will try to infer the type of
the metadata from the value: if the value contains only numerals (with
Expand All @@ -1780,24 +1786,43 @@ current top image.

Examples::

# Set the IPTC:City attribute to "Berkeley"
oiiotool in.jpg --attrib "IPTC:City" "Berkeley" -o out.jpg
# Set a name attribute to "0", but force it to be a string
oiiotool in.jpg --attrib:type=string "Name" "0" -o out.jpg
# Another way to force a string attribute using --sattrib:
oiiotool in.jpg --sattrib "Name" "0" -o out.jpg
# Set the worldcam attribute to be a matrix
oiiotool in.exr --attrib:type=matrix worldtocam \
"1,0,0,0,0,1,0,0,0,0,1,0,2.3,2.1,0,1" -o out.exr
oiiotool in.exr --attrib:type=timecode smpte:TimeCode "11:34:04:00" \
-o out.exr

# Set an attribute to be a timecode
oiiotool in.exr --attrib:type=timecode smpte:TimeCode "11:34:04:00" -o out.exr

# Set an attribute in all subimages
oiiotool multipart.exr --attrib:subimages=all "Foo" "bar" -o out.exr

# Set an attribute just in subimages 0 and 3
oiiotool multipart.exr --attrib:subimages=0,3 "Foo" "bar" -o out.exr

.. option:: --caption <text>

Sets the image metadata `"ImageDescription"`. This has no effect if the
output image format does not support some kind of title, caption, or
description metadata field. Be careful to enclose *text in quotes if you
description metadata field. Be careful to enclose *text* in quotes if you
want your caption to include spaces or certain punctuation!

Optional appended modifiers include:

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).
Only included subimages will have the attribute changed. If subimages
are not set, only the first subimage will be changed, or all subimages
if the `-a` command line flag was used.

.. option:: --keyword <text>

Adds a keyword to the image metadata `"Keywords"`. Any existing
Expand All @@ -1806,7 +1831,7 @@ current top image.
effect if the output image format does not support some kind of keyword
field.

Be careful to enclose *text in quotes if you want your keyword to
Be careful to enclose *text* in quotes if you want your keyword to
include spaces or certain punctuation. For image formats that have only
a single field for keywords, OpenImageIO will concatenate the keywords,
separated by semicolon (`;`), so don't use semicolons within your
Expand All @@ -1816,6 +1841,14 @@ current top image.

Clears all existing keywords in the current image.

Optional appended modifiers include:

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).
Only included subimages will have the attribute changed. If subimages
are not set, only the first subimage will be changed, or all subimages
if the `-a` command line flag was used.

.. option:: --nosoftwareattrib

When set, this prevents the normal adjustment of "Software" and
Expand All @@ -1832,6 +1865,14 @@ current top image.
Removes any metadata whose name matches the regular expression *pattern*.
The pattern will be case insensitive.

Optional appended modifiers include:

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).
Only included subimages will have the attribute changed. If subimages
are not set, only the first subimage will be changed, or all subimages
if the `-a` command line flag was used.

Examples::

# Remove one item only
Expand All @@ -1841,7 +1882,7 @@ current top image.
oiiotool in.jpg --eraseattrib "GPS:.*" -o no_gps_metadata.jpg
# Remove all metadata
oiiotool in.exr --eraseattrib ".*" -o no_metadata.exr
oiiotool in.exr --eraseattrib:subimages=all ".*" -o no_metadata.exr


.. option:: --orientation <orient>
Expand All @@ -1852,6 +1893,14 @@ current top image.
displayed, it does NOT alter the pixels themselves, and so has no effect
for image formats that don't support some kind of orientation metadata.

Optional appended modifiers include:

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).
Only included subimages will have the attribute changed. If subimages
are not set, only the first subimage will be changed, or all subimages
if the `-a` command line flag was used.

.. option:: --orientcw
--orientccw
--orient180
Expand Down
Loading

0 comments on commit 965cf04

Please sign in to comment.