Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0ef5a26
Adding eraseattrib_fromfile as a feature
lydia-zheng May 16, 2025
459a0e7
fixing format
lydia-zheng May 16, 2025
a45ba8a
incorporating comment changes and removing build folder
lydia-zheng May 16, 2025
ce356cc
removing extraneous build files
lydia-zheng May 16, 2025
9c08661
updating to latest cpp file
lydia-zheng May 16, 2025
22b1982
clang format after incorporating suggestions
lydia-zheng May 16, 2025
f77aa13
Merge branch 'main' into feat_eraseattrib_fromfile
lydia-zheng May 16, 2025
9f49d13
removing called out extra variable, updating rough copy of doc
lydia-zheng May 16, 2025
6d8b22a
Merge branch 'feat_eraseattrib_fromfile' of https://github.com/lydia-…
lydia-zheng May 16, 2025
677580c
added regex file contents in doc examples
lydia-zheng May 16, 2025
e15c948
walking back on editor space inserts
lydia-zheng May 17, 2025
a9779c7
Merge branch 'AcademySoftwareFoundation:main' into feat_eraseattrib_f…
lydia-zheng May 17, 2025
00c9f26
Merge branch 'feat_eraseattrib_fromfile' of https://github.com/lydia-…
lydia-zheng May 17, 2025
ed492e4
incorporating suggestions for cpp
lydia-zheng May 17, 2025
c12d26f
doc should have whitespace changes all reverted, reference file 0ef5a…
lydia-zheng May 17, 2025
7f2e758
Adding eraseattrib_fromfile as a feature
lydia-zheng May 16, 2025
16624b3
fixing format
lydia-zheng May 16, 2025
8de1107
incorporating comment changes and removing build folder
lydia-zheng May 16, 2025
ca513ed
removing extraneous build files
lydia-zheng May 16, 2025
49ec3d2
updating to latest cpp file
lydia-zheng May 16, 2025
503db40
clang format after incorporating suggestions
lydia-zheng May 16, 2025
1f7ac0d
removing called out extra variable, updating rough copy of doc
lydia-zheng May 16, 2025
1134864
added regex file contents in doc examples
lydia-zheng May 16, 2025
6e22d19
walking back on editor space inserts
lydia-zheng May 17, 2025
067d747
incorporating suggestions for cpp
lydia-zheng May 17, 2025
5cb32bf
doc should have whitespace changes all reverted, reference file 0ef5a…
lydia-zheng May 17, 2025
e1c6636
Merge branch 'feat_eraseattrib_fromfile' of https://github.com/lydia-…
lydia-zheng May 20, 2025
e46de5c
switching to design 2,fixing clang
lydia-zheng May 20, 2025
c59fa38
Update src/doc/oiiotool.rst
lydia-zheng May 21, 2025
98fe6ec
Update src/doc/oiiotool.rst
lydia-zheng May 21, 2025
395ea0b
Update src/doc/oiiotool.rst
lydia-zheng May 21, 2025
5b990db
removing outdated comment
lydia-zheng May 21, 2025
5d5a7f7
removing spacing around action_attrib_helper
lydia-zheng May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/doc/oiiotool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,13 @@ current top image.
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.

`:fromfile=` *int*
When set to 1, the next argument will be interpreted as
the name of a file containing a list of patterns to erase, for example:
`--eraseattrib:fromfile=1 patterns.txt`,
The patterns will be case insensitive and one pattern per line of the file.
Default value is 0 (False).

Examples::

Expand All @@ -2043,6 +2050,13 @@ current top image.
# Remove all metadata
oiiotool in.exr --eraseattrib:subimages=all ".*" -o no_metadata.exr

# Remove all attribute that match any regex in text file
oiiotool in.exr --eraseattrib:fromfile=1 no_gps_make.txt -o no_gps_make_metadata.exr

Example contents of file no_gps_make.txt:
Make
GPS:.*


.. option:: --orientation <orient>

Expand Down Expand Up @@ -4765,7 +4779,3 @@ General commands that also work for deep images
`NaN` or `Inf` values (hereafter referred to collectively as
"nonfinite") are repaired. The *strategy* may be either `black` or
`error`.




34 changes: 30 additions & 4 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,14 @@ set_oiio_attribute(Oiiotool& ot, cspan<const char*> argv)
OIIO::attribute(p.name(), p.type(), p.data());
}

static std::vector<std::string>
get_regex_list_from_file(string_view filename)
{
// helper function that takes a text file and return all regex attribname entries as a list
std::string contents;
Filesystem::read_text_file(filename, contents);
return Strutil::splits(contents, "\n");
}


// Special OiiotoolOp whose purpose is to set attributes on the top image.
Expand All @@ -1503,8 +1511,16 @@ class OpAttribSetter final : public OiiotoolOp {
: OiiotoolOp(ot, opname, argv, 1)
{
inplace(true); // This action operates in-place
attribname = args(1);
value = (nargs() > 2 ? args(2) : "");
auto options = ot.extract_options(opname);
bool fromfile = options.get_int("fromfile", 0);
if (!fromfile) {
attribname = args(1);
} else {
// handle erase attribute using regex text file case
regex_file = args(1);
attribname_list = get_regex_list_from_file(regex_file);
}
value = (nargs() > 2 ? args(2) : "");
}
bool setup() override
{
Expand All @@ -1516,7 +1532,15 @@ class OpAttribSetter final : public OiiotoolOp {
// Because this is an in-place operation, img[0] is the same as
// img[1].
if (value.empty()) {
img[0]->specmod().erase_attribute(attribname);
if (attribname_list.empty()) {
img[0]->specmod().erase_attribute(attribname);
} else {
for (string_view attr : attribname_list) {
//std::cout << "list element:" << attr << std::endl;
img[0]->specmod().erase_attribute(attr);
}
}

} else {
TypeDesc type(options()["type"].as_string());
set_attribute_helper(img[0]->specmod(), attribname, value, type);
Expand All @@ -1527,6 +1551,8 @@ class OpAttribSetter final : public OiiotoolOp {
private:
string_view attribname;
string_view value;
string_view regex_file;
std::vector<std::string> attribname_list;
};


Expand Down Expand Up @@ -6641,7 +6667,7 @@ Oiiotool::getargs(int argc, char* argv[])
.help("Sets string metadata attribute")
.OTACTION(action_sattrib);
ap.arg("--eraseattrib %s:REGEX")
.help("Erase attributes matching regex")
.help("Erase attributes matching regex (options: fromfile=1 filename-containing-patterns")
.OTACTION(erase_attribute);
ap.arg("--caption %s:TEXT")
.help("Sets caption (ImageDescription metadata)")
Expand Down
18 changes: 18 additions & 0 deletions testsuite/oiiotool-attribs/ref/out-jpeg9d.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Reading nomakegps.jpg
nomakegps.jpg : 2048 x 1536, 3 channel, uint8 jpeg
SHA-1: A74C7DF2B01825DCB6881407AE77C11DC56AB741
channel list: R, G, B
Model: "T-Mobile G1"
Orientation: 1 (normal)
ResolutionUnit: "none"
XResolution: 72
YResolution: 72
Exif:ColorSpace: 1
Exif:ExifVersion: "0230"
Exif:FlashPixVersion: "0100"
Exif:PixelXDimension: 2048
Exif:PixelYDimension: 1536
Exif:WhiteBalance: 0 (auto)
Exif:YCbCrPositioning: 1
jpeg:subsampling: "4:2:0"
oiio:ColorSpace: "sRGB"
Reading nomake.jpg
nomake.jpg : 2048 x 1536, 3 channel, uint8 jpeg
SHA-1: A74C7DF2B01825DCB6881407AE77C11DC56AB741
Expand Down
18 changes: 18 additions & 0 deletions testsuite/oiiotool-attribs/ref/out.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Reading nomakegps.jpg
nomakegps.jpg : 2048 x 1536, 3 channel, uint8 jpeg
SHA-1: 2623446988E34395C6B0A4AA4FC75107C708BF18
channel list: R, G, B
Model: "T-Mobile G1"
Orientation: 1 (normal)
ResolutionUnit: "none"
XResolution: 72
YResolution: 72
Exif:ColorSpace: 1
Exif:ExifVersion: "0230"
Exif:FlashPixVersion: "0100"
Exif:PixelXDimension: 2048
Exif:PixelYDimension: 1536
Exif:WhiteBalance: 0 (auto)
Exif:YCbCrPositioning: 1
jpeg:subsampling: "4:2:0"
oiio:ColorSpace: "sRGB"
Reading nomake.jpg
nomake.jpg : 2048 x 1536, 3 channel, uint8 jpeg
SHA-1: 2623446988E34395C6B0A4AA4FC75107C708BF18
Expand Down
6 changes: 6 additions & 0 deletions testsuite/oiiotool-attribs/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# Test oiiotool's ability to add and delete attributes


# Test --eraseattrib:fromfile=1 to erase from a list of regex matching attributes

command += oiiotool (OIIO_TESTSUITE_IMAGEDIR+"/tahoe-gps.jpg --eraseattrib:fromfile=1 src/regex_list.txt -o nomakegps.jpg")
command += info_command ("nomakegps.jpg", safematch=True)


# Test --eraseattrib ability to erase one specific attribute
# The result should not have "Make"
command += oiiotool (OIIO_TESTSUITE_IMAGEDIR+"/tahoe-gps.jpg --eraseattrib Make -o nomake.jpg")
Expand Down
2 changes: 2 additions & 0 deletions testsuite/oiiotool-attribs/src/regex_list.txt