summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nick Deakin <deakin@google.com> 2023-02-14 20:35:42 -0500
committer Nick Deakin <deakin@google.com> 2023-02-15 10:37:55 -0500
commit3f89a3ee4780a6b4674b255848c04bbea9f07a16 (patch)
treef1358781d5cc9813322a2e634d8a4c31ea1f9c4a
parentbd0b40589bc30305ea5812f33cb30e2cd4602bdb (diff)
libjpegrecoverymap: XMP updates.
Actually write out MinContentBoost in the XMP. Also move XMP for RecoveryMap:* elements into the secondary image Item, to match updates to the ghdr spec. Update XMP test for min content boost. Bug: 264715926 Test: tests pass Change-Id: I8e32755ef3852511ee2e89949fcb7a3cd61d0507
-rw-r--r--libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h12
-rw-r--r--libs/jpegrecoverymap/jpegrutils.cpp32
-rw-r--r--libs/jpegrecoverymap/tests/jpegr_test.cpp4
3 files changed, 40 insertions, 8 deletions
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h
index 3a0f67de19..581806c54e 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h
@@ -56,6 +56,7 @@ bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* meta
* below is an example of the XMP metadata that this function generates where
* secondary_image_length = 1000
* max_content_boost = 8.0
+ * min_content_boost = 0.5
*
* <x:xmpmeta
* xmlns:x="adobe:ns:meta/"
@@ -70,16 +71,17 @@ bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* meta
* <rdf:Seq>
* <rdf:li>
* <Container:Item
- * Item:Semantic="Primary"
- * Item:Mime="image/jpeg"
- * RecoveryMap:Version="1"
- * RecoveryMap:MaxContentBoost="8.0"/>
+ * Item:Semantic="Primary"
+ * Item:Mime="image/jpeg"/>
* </rdf:li>
* <rdf:li>
* <Container:Item
* Item:Semantic="RecoveryMap"
* Item:Mime="image/jpeg"
- * Item:Length="1000"/>
+ * Item:Length="1000"
+ * RecoveryMap:Version="1"
+ * RecoveryMap:MaxContentBoost="8.0"
+ * RecoveryMap:MinContentBoost="0.5"/>
* </rdf:li>
* </rdf:Seq>
* </Container:Directory>
diff --git a/libs/jpegrecoverymap/jpegrutils.cpp b/libs/jpegrecoverymap/jpegrutils.cpp
index bcca91af35..49526c800f 100644
--- a/libs/jpegrecoverymap/jpegrutils.cpp
+++ b/libs/jpegrecoverymap/jpegrutils.cpp
@@ -95,6 +95,8 @@ public:
if (context.BuildTokenValue(&val)) {
if (!val.compare(maxContentBoostAttrName)) {
lastAttributeName = maxContentBoostAttrName;
+ } else if (!val.compare(minContentBoostAttrName)) {
+ lastAttributeName = minContentBoostAttrName;
} else {
lastAttributeName = "";
}
@@ -109,6 +111,8 @@ public:
if (context.BuildTokenValue(&val, true)) {
if (!lastAttributeName.compare(maxContentBoostAttrName)) {
maxContentBoostStr = val;
+ } else if (!lastAttributeName.compare(minContentBoostAttrName)) {
+ minContentBoostStr = val;
}
}
}
@@ -130,10 +134,27 @@ public:
}
}
+ bool getMinContentBoost(float* min_content_boost) {
+ if (gContainerItemState == Done) {
+ stringstream ss(minContentBoostStr);
+ float val;
+ if (ss >> val) {
+ *min_content_boost = val;
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
private:
static const string gContainerItemName;
static const string maxContentBoostAttrName;
string maxContentBoostStr;
+ static const string minContentBoostAttrName;
+ string minContentBoostStr;
string lastAttributeName;
ParseState gContainerItemState;
};
@@ -169,10 +190,12 @@ const string kRecoveryMapPrefix = "RecoveryMap";
// RecoveryMap XMP constants - element and attribute names
const string kMapMaxContentBoost = Name(kRecoveryMapPrefix, "MaxContentBoost");
+const string kMapMinContentBoost = Name(kRecoveryMapPrefix, "MinContentBoost");
const string kMapVersion = Name(kRecoveryMapPrefix, "Version");
// RecoveryMap XMP constants - names for XMP handlers
const string XMPXmlHandler::maxContentBoostAttrName = kMapMaxContentBoost;
+const string XMPXmlHandler::minContentBoostAttrName = kMapMinContentBoost;
bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* metadata) {
string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
@@ -213,6 +236,10 @@ bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* meta
return false;
}
+ if (!handler.getMinContentBoost(&metadata->minContentBoost)) {
+ return false;
+ }
+
return true;
}
@@ -235,13 +262,14 @@ string generateXmp(int secondary_image_length, jpegr_metadata& metadata) {
size_t item_depth = writer.StartWritingElements(kLiItem);
writer.WriteAttributeNameAndValue(kItemSemantic, kSemanticPrimary);
writer.WriteAttributeNameAndValue(kItemMime, kMimeImageJpeg);
- writer.WriteAttributeNameAndValue(kMapVersion, metadata.version);
- writer.WriteAttributeNameAndValue(kMapMaxContentBoost, metadata.maxContentBoost);
writer.FinishWritingElementsToDepth(item_depth);
writer.StartWritingElements(kLiItem);
writer.WriteAttributeNameAndValue(kItemSemantic, kSemanticRecoveryMap);
writer.WriteAttributeNameAndValue(kItemMime, kMimeImageJpeg);
writer.WriteAttributeNameAndValue(kItemLength, secondary_image_length);
+ writer.WriteAttributeNameAndValue(kMapVersion, metadata.version);
+ writer.WriteAttributeNameAndValue(kMapMaxContentBoost, metadata.maxContentBoost);
+ writer.WriteAttributeNameAndValue(kMapMinContentBoost, metadata.minContentBoost);
writer.FinishWriting();
return ss.str();
diff --git a/libs/jpegrecoverymap/tests/jpegr_test.cpp b/libs/jpegrecoverymap/tests/jpegr_test.cpp
index c0347e39c7..7a3133d10c 100644
--- a/libs/jpegrecoverymap/tests/jpegr_test.cpp
+++ b/libs/jpegrecoverymap/tests/jpegr_test.cpp
@@ -176,6 +176,7 @@ TEST_F(JpegRTest, build) {
TEST_F(JpegRTest, writeXmpThenRead) {
jpegr_metadata metadata_expected;
metadata_expected.maxContentBoost = 1.25;
+ metadata_expected.minContentBoost = 0.75;
int length_expected = 1000;
const std::string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
const int nameSpaceLength = nameSpace.size() + 1; // need to count the null terminator
@@ -192,6 +193,7 @@ TEST_F(JpegRTest, writeXmpThenRead) {
jpegr_metadata metadata_read;
EXPECT_TRUE(getMetadataFromXMP(xmpData.data(), xmpData.size(), &metadata_read));
ASSERT_EQ(metadata_expected.maxContentBoost, metadata_read.maxContentBoost);
+ ASSERT_EQ(metadata_expected.minContentBoost, metadata_read.minContentBoost);
}
/* Test Encode API-0 and decode */
@@ -496,4 +498,4 @@ TEST_F(JpegRTest, ProfileRecoveryMapFuncs) {
benchmark.BenchmarkApplyRecoveryMap(&mRawYuv420Image, &map, &metadata, &dest);
}
-} // namespace android::recoverymap \ No newline at end of file
+} // namespace android::recoverymap