1 #ifndef IMAGE_IO_JPEG_JPEG_XMP_DATA_EXTRACTOR_H_ // NOLINT 2 #define IMAGE_IO_JPEG_JPEG_XMP_DATA_EXTRACTOR_H_ // NOLINT 3 4 #include "image_io/base/data_destination.h" 5 #include "image_io/base/message_handler.h" 6 #include "image_io/jpeg/jpeg_info.h" 7 8 namespace photos_editing_formats { 9 namespace image_io { 10 11 /// A class that can make use of the data in a JpegInfo instance to extract 12 /// the xmp data JpegSegments passed to it and forward it to a DataDestination. 13 class JpegXmpDataExtractor : public DataDestination { 14 public: 15 /// @param xmp_info_type The type of xmp data being extracted. 16 /// @param segment_count The number of segment ranges over which the xmp 17 /// data is spread. 18 /// @param data_destination The destination to which the extracted xmp data 19 /// is to be sent. JpegXmpDataExtractor(JpegXmpInfo::Type xmp_info_type,size_t segment_count,DataDestination * data_destination,MessageHandler * message_handler)20 JpegXmpDataExtractor(JpegXmpInfo::Type xmp_info_type, size_t segment_count, 21 DataDestination* data_destination, 22 MessageHandler* message_handler) 23 : xmp_info_type_(xmp_info_type), 24 last_segment_index_(segment_count - 1), 25 data_destination_(data_destination), 26 message_handler_(message_handler), 27 segment_index_(0), 28 has_error_(false) {} 29 30 /// Set the current segment index to the given value. 31 /// @param segment_index The index of the segment currently being processed. SetSegmentIndex(size_t segment_index)32 void SetSegmentIndex(size_t segment_index) { segment_index_ = segment_index; } 33 34 /// @return True if there was an error in the extraction process. HasError()35 bool HasError() const { return has_error_; } 36 37 void StartTransfer() override; 38 TransferStatus Transfer(const DataRange& transfer_range, 39 const DataSegment& data_segment) override; 40 void FinishTransfer() override; 41 42 /// @return The number of bytes written not to this extractor destination, but 43 /// to the next destination. Returns zero if the next destination is null. GetBytesTransferred()44 size_t GetBytesTransferred() const override { 45 return data_destination_ ? data_destination_->GetBytesTransferred() : 0; 46 } 47 48 private: 49 /// The type of xmp data being extracted. 50 JpegXmpInfo::Type xmp_info_type_; 51 52 /// The xmp data require special processing when the last segment is being 53 /// transferred. This value is the index of the last segment. 54 size_t last_segment_index_; 55 56 /// The DataDestination that the extracted xmp data is sent to. 57 DataDestination* data_destination_; 58 59 /// An optional message handler to write messages to. 60 MessageHandler* message_handler_; 61 62 /// The xmp data is spread over one or more segments in the DataSource. This 63 /// index tracks which one is being transferred. 64 size_t segment_index_; 65 66 /// A true value indicates that an error occurred in the decoding process. 67 bool has_error_; 68 }; 69 70 } // namespace image_io 71 } // namespace photos_editing_formats 72 73 #endif // IMAGE_IO_JPEG_JPEG_XMP_DATA_EXTRACTOR_H_ // NOLINT 74