Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions lib/src/jpegrutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,13 +1575,8 @@ bool stripGainMapFromXmp(const std::string& xmp_data, std::string* stripped_xmp)
}

for (const XmpAttributeSpan& attribute : primary.attributes) {
bool should_remove = false;
// Namespace bindings may still be used by retained descendants in a mixed description.
if (!attribute.namespace_declaration && IsGainMapPropertyUri(attribute.uri)) {
should_remove = true;
} else if (attribute.namespace_declaration && IsGainMapPropertyUri(attribute.value)) {
should_remove = true;
}
if (should_remove) {
size_t attr_begin = attribute.name_begin;
while (attr_begin > primary.start_begin && IsXmlWhitespace(parse_xml[attr_begin - 1])) {
--attr_begin;
Expand Down
19 changes: 16 additions & 3 deletions tests/ultrahdr_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,6 @@ TEST_F(UltraHdrApiTest, StripGainMapPreservesSharedDescriptionAndExtendedXmp) {
std::string::npos);
EXPECT_EQ(stripped_shared.find("hdrgm:"), std::string::npos);
EXPECT_EQ(stripped_shared.find("Container:"), std::string::npos);
EXPECT_EQ(stripped_shared.find("xmlns:hdrgm"), std::string::npos);
EXPECT_EQ(stripped_shared.find("xmlns:Container"), std::string::npos);
EXPECT_EQ(stripped_shared.find("xmlns:Item"), std::string::npos);

// Part 2: Multi-segment Extended XMP (> 64 KB) preserved through uhdr_strip_gain_map.
const std::string ext_xmp = makeLargeXmp(140000);
Expand All @@ -1063,6 +1060,22 @@ TEST_F(UltraHdrApiTest, StripGainMapPreservesSharedDescriptionAndExtendedXmp) {
EXPECT_EQ(memcmp(stripped_decoder.getXMPPtr(), ext_xmp.data(), ext_xmp.size()), 0);
}

TEST_F(UltraHdrApiTest, StripGainMapKeepsNamespaceUsedByRetainedDescendant) {
const std::string shared_xmp =
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF "
"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description "
"rdf:about=\"\" xmlns:hdrgm=\"http://ns.adobe.com/hdr-gain-map/1.0/\" "
"xmlns:u=\"urn:user\" hdrgm:Version=\"1.0\"><u:keep hdrgm:custom=\"x\"/>"
"</rdf:Description></rdf:RDF></x:xmpmeta>";

std::string stripped;
ASSERT_TRUE(stripGainMapFromXmp(shared_xmp, &stripped));
EXPECT_EQ(stripped.find("hdrgm:Version=\"1.0\""), std::string::npos);
EXPECT_NE(stripped.find("xmlns:hdrgm=\"http://ns.adobe.com/hdr-gain-map/1.0/\""),
std::string::npos);
EXPECT_NE(stripped.find("<u:keep hdrgm:custom=\"x\"/>"), std::string::npos);
}

TEST_F(UltraHdrApiTest, StripGainMapStripsTrailingBinaryTrailerAfterPrimaryEoi) {
EncoderPtr enc = makeEncoder();
ASSERT_NE(enc, nullptr);
Expand Down
Loading