summaryrefslogtreecommitdiff
path: root/includes/image_io/jpeg/jpeg_image_extractor.h
blob: 966f60922c36b5154abd2e250ce6180a4abec13d (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
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef IMAGE_IO_JPEG_JPEG_IMAGE_EXTRACTOR_H_  // NOLINT
#define IMAGE_IO_JPEG_JPEG_IMAGE_EXTRACTOR_H_  // NOLINT

#include "image_io/base/data_destination.h"
#include "image_io/base/data_source.h"
#include "image_io/base/message_handler.h"
#include "image_io/jpeg/jpeg_info.h"

namespace photos_editing_formats {
namespace image_io {

/// A class that can make use of the data in a JpegInfo instance to transfer
/// Apple depth and GDepth/GImage images from a DataSource and ship it to a
/// DataDestination.
class JpegImageExtractor {
 public:
  /// @param jpeg_info The JpegInfo instance containing depth/image data.
  /// @param data_source The DataSource from which to transfer depth/image data.
  /// @param message_handler An optional message handler to write messages to.
  JpegImageExtractor(const JpegInfo& jpeg_info, DataSource* data_source,
                     MessageHandler* message_handler)
      : jpeg_info_(jpeg_info),
        data_source_(data_source),
        message_handler_(message_handler) {}

  /// This function extracts the Apple depth image from the DataSource and sends
  /// the bytes to the DataDestination.
  /// @param image_destination The DataDestination to receive the image data.
  /// @return True if an image was extracted.
  bool ExtractAppleDepthImage(DataDestination* image_destination);

  /// This function extracts the Apple matte image from the DataSource and sends
  /// the bytes to the DataDestination.
  /// @param image_destination The DataDestination to receive the image data.
  /// @return True if an image was extracted.
  bool ExtractAppleMatteImage(DataDestination* image_destination);

  /// This function extracts the GDepth type image from the DataSource and
  /// sends the bytes to the DataDestination.
  /// @param image_destination The DataDestination to receive the image data.
  /// @return True if an image was extracted.
  bool ExtractGDepthImage(DataDestination* image_destination);

  /// This function extracts the GImage type image from the DataSource and
  /// sends the bytes to the DataDestination.
  /// @param image_destination The DataDestination to receive the image data.
  /// @return True if an image was extracted.
  bool ExtractGImageImage(DataDestination* image_destination);

 private:
  /// Worker function called for GDepth/GImage type image extraction.
  /// @param xmp_info_type The type of image to extract.
  /// @param image_destination The DataDestination to receive the image data.
  /// @return True if an image was extracted.
  bool ExtractImage(JpegXmpInfo::Type xmp_info_type,
                    DataDestination* image_destination);

  /// Worker function called for Apple depth/matte type image extraction.
  /// @param image_range The range of the image data to extract. If invalid,
  ///     the image_destination's StartTransfer/FinishTransfer functions are
  ///     still called, and this function will return true (i.e., zero bytes
  ///     "successfully" transferred).
  /// @param image_destination The DataDestination to receive the image data.
  /// @return True if the transfer succeeded.
  bool ExtractImage(const DataRange& image_range,
                    DataDestination* image_destination);

  /// The jpeg info object contains the location of the Apple and Google images.
  JpegInfo jpeg_info_;

  /// The data source from which the images are extracted.
  DataSource* data_source_;

  /// An optional message handler to write messages to.
  MessageHandler* message_handler_;
};

}  // namespace image_io
}  // namespace photos_editing_formats

#endif // IMAGE_IO_JPEG_JPEG_IMAGE_EXTRACTOR_H_  // NOLINT