1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_LIGHT_ESTIMATE_H_ // NOLINT 2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_LIGHT_ESTIMATE_H_ // NOLINT 3 4 #include <memory> 5 #include <string> 6 #include <unordered_map> 7 8 #include "dynamic_depth/element.h" 9 #include "xmpmeta/xml/deserializer.h" 10 #include "xmpmeta/xml/serializer.h" 11 12 namespace dynamic_depth { 13 14 // Light estimation parameters for a camera. 15 // This is stored as a sibling element to LightEstimate because it may apply to 16 // the container image, so the decoupling is required. 17 class LightEstimate : public Element { 18 public: 19 // Appends child elements' namespaces' and their respective hrefs to the 20 // given collection, and any parent nodes' names to prefix_names. 21 // Key: Name of the namespace. 22 // Value: Full namespace URL. 23 // Example: ("LightEstimate", "http://ns.google.com/photos/dd/1.0/image/") 24 void GetNamespaces( 25 std::unordered_map<string, string>* ns_name_href_map) override; 26 27 // Serializes this object. 28 bool Serialize( 29 ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override; 30 31 // Creates an LightEstimate from the given field. 32 static std::unique_ptr<LightEstimate> FromData(float pixel_intensity); 33 34 // Takes the first three values from color_correction if the vector length is 35 // greater than 3. 36 // Color correction values should be between 0 and 1 (plus or minus 0.2). 37 static std::unique_ptr<LightEstimate> FromData( 38 float pixel_intensity, const std::vector<float>& color_correction); 39 40 // Returns the deserialized LightEstimate; null if parsing fails. 41 static std::unique_ptr<LightEstimate> FromDeserializer( 42 const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer); 43 44 // Returns the average pixel internsity. 45 float GetPixelIntensity() const; 46 const std::vector<float>& GetColorCorrection() const; 47 48 // Disallow copying. 49 LightEstimate(const LightEstimate&) = delete; 50 void operator=(const LightEstimate&) = delete; 51 52 private: 53 LightEstimate(); 54 55 float pixel_intensity_ = 1.0f; 56 57 // Optional, either all three together or none at all. 58 // A size-3 vector of color correction values, in the order R, G, B. 59 // Values can be approximately between 0 and 1 (plus or minus 0.2). 60 // On reading back image metadata, if only one or two of the values are 61 // present, then the defaults below are used. 62 std::vector<float> color_correction_ = {1.0f, 1.0f, 1.0f}; 63 }; 64 65 } // namespace dynamic_depth 66 67 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_LIGHT_ESTIMATE_H_ // NOLINT 68