summaryrefslogtreecommitdiff
path: root/includes/dynamic_depth/light_estimate.h
blob: 51cbde2c2b295b6b166b180cc767f81b09e01791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_LIGHT_ESTIMATE_H_  // NOLINT
#define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_LIGHT_ESTIMATE_H_  // NOLINT

#include <memory>
#include <string>
#include <unordered_map>

#include "dynamic_depth/element.h"
#include "xmpmeta/xml/deserializer.h"
#include "xmpmeta/xml/serializer.h"

namespace photos_editing_formats {
namespace dynamic_depth {

// Light estimation parameters for a camera.
// This is stored as a sibling element to LightEstimate because it may apply to
// the container image, so the decoupling is required.
class LightEstimate : public Element {
 public:
  // Appends child elements' namespaces' and their respective hrefs to the
  // given collection, and any parent nodes' names to prefix_names.
  // Key: Name of the namespace.
  // Value: Full namespace URL.
  // Example: ("LightEstimate", "http://ns.google.com/photos/dd/1.0/image/")
  void GetNamespaces(
      std::unordered_map<string, string>* ns_name_href_map) override;

  // Serializes this object.
  bool Serialize(xml::Serializer* serializer) const override;

  // Creates an LightEstimate from the given field.
  static std::unique_ptr<LightEstimate> FromData(float pixel_intensity);

  // Takes the first three values from color_correction if the vector length is
  // greater than 3.
  // Color correction values should be between 0 and 1 (plus or minus 0.2).
  static std::unique_ptr<LightEstimate> FromData(
      float pixel_intensity, const std::vector<float>& color_correction);

  // Returns the deserialized LightEstimate; null if parsing fails.
  static std::unique_ptr<LightEstimate> FromDeserializer(
      const xml::Deserializer& parent_deserializer);

  // Returns the average pixel internsity.
  float GetPixelIntensity() const;
  const std::vector<float>& GetColorCorrection() const;

  // Disallow copying.
  LightEstimate(const LightEstimate&) = delete;
  void operator=(const LightEstimate&) = delete;

 private:
  LightEstimate();

  float pixel_intensity_ = 1.0f;

  // Optional, either all three together or none at all.
  // A size-3 vector of color correction values, in the order R, G, B.
  // Values can be approximately between 0 and 1 (plus or minus 0.2).
  // On reading back image metadata, if only one or two of the values are
  // present, then the defaults below are used.
  std::vector<float> color_correction_ = {1.0f, 1.0f, 1.0f};
};

}  // namespace dynamic_depth
}  // namespace photos_editing_formats

#endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_LIGHT_ESTIMATE_H_  // NOLINT