Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <jpegrecoverymap/recoverymaputils.h> |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 18 | #include <image_io/xml/xml_reader.h> |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 19 | #include <image_io/xml/xml_writer.h> |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 20 | #include <image_io/base/message_handler.h> |
| 21 | #include <image_io/xml/xml_element_rules.h> |
| 22 | #include <image_io/xml/xml_handler.h> |
| 23 | #include <image_io/xml/xml_rule.h> |
| 24 | |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 25 | using namespace photos_editing_formats::image_io; |
| 26 | using namespace std; |
Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame] | 27 | |
| 28 | namespace android::recoverymap { |
| 29 | |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 30 | /* |
| 31 | * Helper function used for generating XMP metadata. |
| 32 | * |
| 33 | * @param prefix The prefix part of the name. |
| 34 | * @param suffix The suffix part of the name. |
| 35 | * @return A name of the form "prefix:suffix". |
| 36 | */ |
| 37 | string Name(const string &prefix, const string &suffix) { |
| 38 | std::stringstream ss; |
| 39 | ss << prefix << ":" << suffix; |
| 40 | return ss.str(); |
| 41 | } |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 42 | |
Dichen Zhang | 91dfc57 | 2023-01-19 11:22:43 -0800 | [diff] [blame] | 43 | /* |
| 44 | * Helper function used for writing data to destination. |
| 45 | */ |
| 46 | status_t Write(jr_compressed_ptr destination, const void* source, size_t length, int &position) { |
| 47 | if (position + length > destination->maxLength) { |
| 48 | return ERROR_JPEGR_BUFFER_TOO_SMALL; |
| 49 | } |
| 50 | |
| 51 | memcpy((uint8_t*)destination->data + sizeof(uint8_t) * position, source, length); |
| 52 | position += length; |
| 53 | return NO_ERROR; |
| 54 | } |
| 55 | |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 56 | // Extremely simple XML Handler - just searches for interesting elements |
| 57 | class XMPXmlHandler : public XmlHandler { |
| 58 | public: |
| 59 | |
| 60 | XMPXmlHandler() : XmlHandler() { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 61 | gContainerItemState = NotStrarted; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | enum ParseState { |
| 65 | NotStrarted, |
| 66 | Started, |
| 67 | Done |
| 68 | }; |
| 69 | |
| 70 | virtual DataMatchResult StartElement(const XmlTokenContext& context) { |
| 71 | string val; |
| 72 | if (context.BuildTokenValue(&val)) { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 73 | if (!val.compare(gContainerItemName)) { |
| 74 | gContainerItemState = Started; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 75 | } else { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 76 | if (gContainerItemState != Done) { |
| 77 | gContainerItemState = NotStrarted; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | } |
| 81 | return context.GetResult(); |
| 82 | } |
| 83 | |
| 84 | virtual DataMatchResult FinishElement(const XmlTokenContext& context) { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 85 | if (gContainerItemState == Started) { |
| 86 | gContainerItemState = Done; |
| 87 | lastAttributeName = ""; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 88 | } |
| 89 | return context.GetResult(); |
| 90 | } |
| 91 | |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 92 | virtual DataMatchResult AttributeName(const XmlTokenContext& context) { |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 93 | string val; |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 94 | if (gContainerItemState == Started) { |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 95 | if (context.BuildTokenValue(&val)) { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 96 | if (!val.compare(rangeScalingFactorAttrName)) { |
| 97 | lastAttributeName = rangeScalingFactorAttrName; |
| 98 | } else if (!val.compare(transferFunctionAttrName)) { |
| 99 | lastAttributeName = transferFunctionAttrName; |
| 100 | } else { |
| 101 | lastAttributeName = ""; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | return context.GetResult(); |
| 106 | } |
| 107 | |
| 108 | virtual DataMatchResult AttributeValue(const XmlTokenContext& context) { |
| 109 | string val; |
| 110 | if (gContainerItemState == Started) { |
| 111 | if (context.BuildTokenValue(&val, true)) { |
| 112 | if (!lastAttributeName.compare(rangeScalingFactorAttrName)) { |
| 113 | rangeScalingFactorStr = val; |
| 114 | } else if (!lastAttributeName.compare(transferFunctionAttrName)) { |
| 115 | transferFunctionStr = val; |
| 116 | } |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | return context.GetResult(); |
| 120 | } |
| 121 | |
| 122 | bool getRangeScalingFactor(float* scaling_factor) { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 123 | if (gContainerItemState == Done) { |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 124 | stringstream ss(rangeScalingFactorStr); |
| 125 | float val; |
| 126 | if (ss >> val) { |
| 127 | *scaling_factor = val; |
| 128 | return true; |
| 129 | } else { |
| 130 | return false; |
| 131 | } |
| 132 | } else { |
| 133 | return false; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | bool getTransferFunction(jpegr_transfer_function* transfer_function) { |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 138 | if (gContainerItemState == Done) { |
| 139 | stringstream ss(transferFunctionStr); |
| 140 | int val; |
| 141 | if (ss >> val) { |
| 142 | *transfer_function = static_cast<jpegr_transfer_function>(val); |
| 143 | return true; |
| 144 | } else { |
| 145 | return false; |
| 146 | } |
| 147 | } else { |
| 148 | return false; |
| 149 | } |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | |
| 153 | private: |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 154 | static const string gContainerItemName; |
| 155 | static const string rangeScalingFactorAttrName; |
| 156 | static const string transferFunctionAttrName; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 157 | string rangeScalingFactorStr; |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 158 | string transferFunctionStr; |
| 159 | string lastAttributeName; |
| 160 | ParseState gContainerItemState; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 163 | // GContainer XMP constants - URI and namespace prefix |
| 164 | const string kContainerUri = "http://ns.google.com/photos/1.0/container/"; |
| 165 | const string kContainerPrefix = "GContainer"; |
Fyodor Kyslov | ad58a34 | 2022-12-12 02:10:35 +0000 | [diff] [blame] | 166 | |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 167 | // GContainer XMP constants - element and attribute names |
| 168 | const string kConDirectory = Name(kContainerPrefix, "Directory"); |
| 169 | const string kConItem = Name(kContainerPrefix, "Item"); |
| 170 | const string kConItemLength = Name(kContainerPrefix, "ItemLength"); |
| 171 | const string kConItemMime = Name(kContainerPrefix, "ItemMime"); |
| 172 | const string kConItemSemantic = Name(kContainerPrefix, "ItemSemantic"); |
| 173 | const string kConVersion = Name(kContainerPrefix, "Version"); |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 174 | |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 175 | // GContainer XMP constants - element and attribute values |
| 176 | const string kSemanticPrimary = "Primary"; |
| 177 | const string kSemanticRecoveryMap = "RecoveryMap"; |
| 178 | const string kMimeImageJpeg = "image/jpeg"; |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 179 | |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 180 | const int kGContainerVersion = 1; |
| 181 | |
| 182 | // GContainer XMP constants - names for XMP handlers |
| 183 | const string XMPXmlHandler::gContainerItemName = kConItem; |
| 184 | |
| 185 | // RecoveryMap XMP constants - URI and namespace prefix |
| 186 | const string kRecoveryMapUri = "http://ns.google.com/photos/1.0/recoverymap/"; |
| 187 | const string kRecoveryMapPrefix = "RecoveryMap"; |
| 188 | |
| 189 | // RecoveryMap XMP constants - element and attribute names |
| 190 | const string kMapRangeScalingFactor = Name(kRecoveryMapPrefix, "RangeScalingFactor"); |
| 191 | const string kMapTransferFunction = Name(kRecoveryMapPrefix, "TransferFunction"); |
| 192 | const string kMapVersion = Name(kRecoveryMapPrefix, "Version"); |
| 193 | |
| 194 | const string kMapHdr10Metadata = Name(kRecoveryMapPrefix, "HDR10Metadata"); |
| 195 | const string kMapHdr10MaxFall = Name(kRecoveryMapPrefix, "HDR10MaxFALL"); |
| 196 | const string kMapHdr10MaxCll = Name(kRecoveryMapPrefix, "HDR10MaxCLL"); |
| 197 | |
| 198 | const string kMapSt2086Metadata = Name(kRecoveryMapPrefix, "ST2086Metadata"); |
| 199 | const string kMapSt2086MaxLum = Name(kRecoveryMapPrefix, "ST2086MaxLuminance"); |
| 200 | const string kMapSt2086MinLum = Name(kRecoveryMapPrefix, "ST2086MinLuminance"); |
| 201 | const string kMapSt2086Primary = Name(kRecoveryMapPrefix, "ST2086Primary"); |
| 202 | const string kMapSt2086Coordinate = Name(kRecoveryMapPrefix, "ST2086Coordinate"); |
| 203 | const string kMapSt2086CoordinateX = Name(kRecoveryMapPrefix, "ST2086CoordinateX"); |
| 204 | const string kMapSt2086CoordinateY = Name(kRecoveryMapPrefix, "ST2086CoordinateY"); |
| 205 | |
| 206 | // RecoveryMap XMP constants - element and attribute values |
| 207 | const int kSt2086PrimaryRed = 0; |
| 208 | const int kSt2086PrimaryGreen = 1; |
| 209 | const int kSt2086PrimaryBlue = 2; |
| 210 | const int kSt2086PrimaryWhite = 3; |
| 211 | |
| 212 | // RecoveryMap XMP constants - names for XMP handlers |
| 213 | const string XMPXmlHandler::rangeScalingFactorAttrName = kMapRangeScalingFactor; |
| 214 | const string XMPXmlHandler::transferFunctionAttrName = kMapTransferFunction; |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 215 | |
Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame] | 216 | bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* metadata) { |
Fyodor Kyslov | 6c87e7b | 2022-11-23 03:12:14 +0000 | [diff] [blame] | 217 | string nameSpace = "http://ns.adobe.com/xap/1.0/\0"; |
| 218 | |
| 219 | if (xmp_size < nameSpace.size()+2) { |
| 220 | // Data too short |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | if (strncmp(reinterpret_cast<char*>(xmp_data), nameSpace.c_str(), nameSpace.size())) { |
| 225 | // Not correct namespace |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | // Position the pointers to the start of XMP XML portion |
| 230 | xmp_data += nameSpace.size()+1; |
| 231 | xmp_size -= nameSpace.size()+1; |
| 232 | XMPXmlHandler handler; |
| 233 | |
| 234 | // We need to remove tail data until the closing tag. Otherwise parser will throw an error. |
| 235 | while(xmp_data[xmp_size-1]!='>' && xmp_size > 1) { |
| 236 | xmp_size--; |
| 237 | } |
| 238 | |
| 239 | string str(reinterpret_cast<const char*>(xmp_data), xmp_size); |
| 240 | MessageHandler msg_handler; |
| 241 | unique_ptr<XmlRule> rule(new XmlElementRule); |
| 242 | XmlReader reader(&handler, &msg_handler); |
| 243 | reader.StartParse(std::move(rule)); |
| 244 | reader.Parse(str); |
| 245 | reader.FinishParse(); |
| 246 | if (reader.HasErrors()) { |
| 247 | // Parse error |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | if (!handler.getRangeScalingFactor(&metadata->rangeScalingFactor)) { |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | if (!handler.getTransferFunction(&metadata->transferFunction)) { |
| 256 | return false; |
| 257 | } |
Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 261 | string generateXmp(int secondary_image_length, jpegr_metadata& metadata) { |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 262 | const vector<string> kConDirSeq({kConDirectory, string("rdf:Seq")}); |
| 263 | const vector<string> kLiItem({string("rdf:li"), kConItem}); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 264 | |
| 265 | std::stringstream ss; |
| 266 | photos_editing_formats::image_io::XmlWriter writer(ss); |
| 267 | writer.StartWritingElement("x:xmpmeta"); |
| 268 | writer.WriteXmlns("x", "adobe:ns:meta/"); |
| 269 | writer.WriteAttributeNameAndValue("x:xmptk", "Adobe XMP Core 5.1.2"); |
| 270 | writer.StartWritingElement("rdf:RDF"); |
| 271 | writer.WriteXmlns("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); |
| 272 | writer.StartWritingElement("rdf:Description"); |
| 273 | writer.WriteXmlns(kContainerPrefix, kContainerUri); |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 274 | writer.WriteXmlns(kRecoveryMapPrefix, kRecoveryMapUri); |
| 275 | writer.WriteElementAndContent(kConVersion, kGContainerVersion); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 276 | writer.StartWritingElements(kConDirSeq); |
| 277 | size_t item_depth = writer.StartWritingElements(kLiItem); |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 278 | writer.WriteAttributeNameAndValue(kConItemSemantic, kSemanticPrimary); |
| 279 | writer.WriteAttributeNameAndValue(kConItemMime, kMimeImageJpeg); |
| 280 | writer.WriteAttributeNameAndValue(kMapVersion, metadata.version); |
| 281 | writer.WriteAttributeNameAndValue(kMapRangeScalingFactor, metadata.rangeScalingFactor); |
| 282 | writer.WriteAttributeNameAndValue(kMapTransferFunction, metadata.transferFunction); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 283 | if (metadata.transferFunction == JPEGR_TF_PQ) { |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 284 | writer.StartWritingElement(kMapHdr10Metadata); |
| 285 | writer.WriteAttributeNameAndValue(kMapHdr10MaxFall, metadata.hdr10Metadata.maxFALL); |
| 286 | writer.WriteAttributeNameAndValue(kMapHdr10MaxCll, metadata.hdr10Metadata.maxCLL); |
| 287 | writer.StartWritingElement(kMapSt2086Metadata); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 288 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 289 | kMapSt2086MaxLum, metadata.hdr10Metadata.st2086Metadata.maxLuminance); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 290 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 291 | kMapSt2086MinLum, metadata.hdr10Metadata.st2086Metadata.minLuminance); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 292 | |
| 293 | // red |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 294 | writer.StartWritingElement(kMapSt2086Coordinate); |
| 295 | writer.WriteAttributeNameAndValue(kMapSt2086Primary, kSt2086PrimaryRed); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 296 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 297 | kMapSt2086CoordinateX, metadata.hdr10Metadata.st2086Metadata.redPrimary.x); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 298 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 299 | kMapSt2086CoordinateY, metadata.hdr10Metadata.st2086Metadata.redPrimary.y); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 300 | writer.FinishWritingElement(); |
| 301 | |
| 302 | // green |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 303 | writer.StartWritingElement(kMapSt2086Coordinate); |
| 304 | writer.WriteAttributeNameAndValue(kMapSt2086Primary, kSt2086PrimaryGreen); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 305 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 306 | kMapSt2086CoordinateX, metadata.hdr10Metadata.st2086Metadata.greenPrimary.x); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 307 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 308 | kMapSt2086CoordinateY, metadata.hdr10Metadata.st2086Metadata.greenPrimary.y); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 309 | writer.FinishWritingElement(); |
| 310 | |
| 311 | // blue |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 312 | writer.StartWritingElement(kMapSt2086Coordinate); |
| 313 | writer.WriteAttributeNameAndValue(kMapSt2086Primary, kSt2086PrimaryBlue); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 314 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 315 | kMapSt2086CoordinateX, metadata.hdr10Metadata.st2086Metadata.bluePrimary.x); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 316 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 317 | kMapSt2086CoordinateY, metadata.hdr10Metadata.st2086Metadata.bluePrimary.y); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 318 | writer.FinishWritingElement(); |
| 319 | |
| 320 | // white |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 321 | writer.StartWritingElement(kMapSt2086Coordinate); |
| 322 | writer.WriteAttributeNameAndValue(kMapSt2086Primary, kSt2086PrimaryWhite); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 323 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 324 | kMapSt2086CoordinateX, metadata.hdr10Metadata.st2086Metadata.whitePoint.x); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 325 | writer.WriteAttributeNameAndValue( |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 326 | kMapSt2086CoordinateY, metadata.hdr10Metadata.st2086Metadata.whitePoint.y); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 327 | writer.FinishWritingElement(); |
| 328 | } |
| 329 | writer.FinishWritingElementsToDepth(item_depth); |
| 330 | writer.StartWritingElements(kLiItem); |
Nick Deakin | 7dfe016 | 2023-01-19 18:27:09 -0500 | [diff] [blame] | 331 | writer.WriteAttributeNameAndValue(kConItemSemantic, kSemanticRecoveryMap); |
| 332 | writer.WriteAttributeNameAndValue(kConItemMime, kMimeImageJpeg); |
| 333 | writer.WriteAttributeNameAndValue(kConItemLength, secondary_image_length); |
Dichen Zhang | dc8452b | 2022-11-23 17:17:56 +0000 | [diff] [blame] | 334 | writer.FinishWriting(); |
| 335 | |
| 336 | return ss.str(); |
| 337 | } |
| 338 | |
Dichen Zhang | 50ff129 | 2023-01-27 18:03:43 +0000 | [diff] [blame^] | 339 | } // namespace android::recoverymap |