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
diff --git a/libs/jpegrecoverymap/jpegrutils.cpp b/libs/jpegrecoverymap/jpegrutils.cpp
index bcca91a..49526c8 100644
--- a/libs/jpegrecoverymap/jpegrutils.cpp
+++ b/libs/jpegrecoverymap/jpegrutils.cpp
@@ -95,6 +95,8 @@
if (context.BuildTokenValue(&val)) {
if (!val.compare(maxContentBoostAttrName)) {
lastAttributeName = maxContentBoostAttrName;
+ } else if (!val.compare(minContentBoostAttrName)) {
+ lastAttributeName = minContentBoostAttrName;
} else {
lastAttributeName = "";
}
@@ -109,6 +111,8 @@
if (context.BuildTokenValue(&val, true)) {
if (!lastAttributeName.compare(maxContentBoostAttrName)) {
maxContentBoostStr = val;
+ } else if (!lastAttributeName.compare(minContentBoostAttrName)) {
+ minContentBoostStr = val;
}
}
}
@@ -130,10 +134,27 @@
}
}
+ 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 @@
// 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 @@
return false;
}
+ if (!handler.getMinContentBoost(&metadata->minContentBoost)) {
+ return false;
+ }
+
return true;
}
@@ -235,13 +262,14 @@
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();