• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef IMAGE_IO_JPEG_JPEG_APPLE_DEPTH_BUILDER_H_  // NOLINT
2 #define IMAGE_IO_JPEG_JPEG_APPLE_DEPTH_BUILDER_H_  // NOLINT
3 
4 #include <vector>
5 
6 #include "image_io/base/data_destination.h"
7 #include "image_io/base/data_range.h"
8 #include "image_io/base/data_source.h"
9 #include "image_io/base/message_handler.h"
10 
11 namespace photos_editing_formats {
12 namespace image_io {
13 
14 /// Builds an Apple depth file containing a (possibly scaled down) primary image
15 /// and original depth image.
16 class JpegAppleDepthBuilder {
17  public:
JpegAppleDepthBuilder(MessageHandler * message_handler)18   explicit JpegAppleDepthBuilder(MessageHandler* message_handler)
19       : message_handler_(message_handler),
20         primary_image_data_source_(nullptr),
21         depth_image_data_source_(nullptr),
22         data_destination_(nullptr) {}
23 
24   /// @param primary_image_data_source The data source containing the primary
25   ///     image. The builder uses the first image in this data source.
26   /// @param depth_image_data_source The data source containing the depth image.
27   ///     The builder finds the depth image using a JpegInfoBuilder and the
28   ///     JpegInfo::GetAppleDepthImageRange() function. Consequently, this
29   ///     image source must refer a valid Apple depth file.
30   /// @param data_destination The data destination for the combined primary
31   ///     and depth images.
32   /// @return Whether the building and transfer was successful.
33   bool Run(DataSource* primary_image_data_source,
34            DataSource* depth_image_data_source,
35            DataDestination* data_destination);
36 
37  private:
38   /// Gets the data associated with the primary image its data source.
39   /// @return Whether the primary image data was gotten successfully.
40   bool GetPrimaryImageData();
41 
42   /// Gets the data associated with the depth image from its data source.
43   /// @return Whether the depth image data was gotten successfully.
44   bool GetDepthImageData();
45 
46   /// Transfers the primary image from its data source to the data destination,
47   /// adding and transforming the jpeg segments it needs to make the resulting
48   /// data destination a valid Apple depth file.
49   /// @return Whether the transfer was successful or not.
50   bool TransferPrimaryImage();
51 
52   /// Transfers the depth image from its data source to the data destination.
53   /// @return Whether the transfer was successful or not.
54   bool TransferDepthImage();
55 
56   /// Modifies the existing primary Jfif segment to contain the information
57   /// needed for a valid Apple depth file, and transfers the result to the data
58   /// destination.
59   /// @param jfif_length_delta The increased size of the Jfif segment.
60   /// @return Whether the transfer was successful or not.
61   bool TransferNewJfifSegment(size_t *jfif_length_delta);
62 
63   /// Creates a new Mpf segment needed for a valid Apple depth file and
64   /// transfers the result to the data destination.
65   /// @param jfif_length_delta The increased size of the Jfif segment.
66   /// @return Whether the transfer was successful or not.
67   bool TransferNewMpfSegment(size_t jfif_length_delta);
68 
69   /// @param data_source The data source from which to transfer bytes to the
70   ///     data destination.
71   /// @param data_range The data range in the data source to transfer.
72   bool TransferData(DataSource *data_source, const DataRange& data_range);
73 
74   /// An optional message handler to write messages to.
75   MessageHandler* message_handler_;
76 
77   /// The data source containing the primary image.
78   DataSource* primary_image_data_source_;
79 
80   /// The data source representing a valid Apple depth file.
81   DataSource* depth_image_data_source_;
82 
83   /// The final destination of the new Apple depth data.
84   DataDestination* data_destination_;
85 
86   /// The range in the primary image data source containing the primary image.
87   DataRange primary_image_range_;
88 
89   /// The range in the primary image data source containing the primary image's
90   /// Jfif segment.
91   DataRange primary_image_jfif_segment_range_;
92 
93   /// The bytes of the primary image's Jfif segment.
94   std::vector<Byte> primary_image_jfif_segment_bytes_;
95 
96   /// The range in the primary image data source containing the primary images's
97   /// Mpf segment, or the location at a new Mpf segment should be written.
98   DataRange primary_image_mpf_segment_range_;
99 
100   /// The range in the depth image data source containing the depth image.
101   DataRange depth_image_range_;
102 };
103 
104 }  // namespace image_io
105 }  // namespace photos_editing_formats
106 
107 #endif // IMAGE_IO_JPEG_JPEG_APPLE_DEPTH_BUILDER_H_  // NOLINT
108