diff --git a/lib/src/jpegrutils.cpp b/lib/src/jpegrutils.cpp index 2115043c..9b8b3bfd 100644 --- a/lib/src/jpegrutils.cpp +++ b/lib/src/jpegrutils.cpp @@ -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; diff --git a/tests/ultrahdr_api_test.cpp b/tests/ultrahdr_api_test.cpp index 8c9f3006..a58a0614 100644 --- a/tests/ultrahdr_api_test.cpp +++ b/tests/ultrahdr_api_test.cpp @@ -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); @@ -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 = + "" + ""; + + 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(""), std::string::npos); +} + TEST_F(UltraHdrApiTest, StripGainMapStripsTrailingBinaryTrailerAfterPrimaryEoi) { EncoderPtr enc = makeEncoder(); ASSERT_NE(enc, nullptr);