Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1fb7d4c authored by Nick Deakin's avatar Nick Deakin Committed by Android (Google) Code Review
Browse files

Merge "libjpegrecoverymap: XMP updates."

parents 25f3b708 3f89a3ee
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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/"
@@ -71,15 +72,16 @@ bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* meta
 *           <rdf:li>
 *             <Container:Item
 *               Item:Semantic="Primary"
 *              Item:Mime="image/jpeg"
 *              RecoveryMap:Version="1"
 *              RecoveryMap:MaxContentBoost="8.0"/>
 *               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>
+30 −2
Original line number Diff line number Diff line
@@ -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();
+3 −1
Original line number Diff line number Diff line
@@ -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 */