1 #include "image_io/base/data_segment_data_source.h" 2 3 #include "image_io/base/data_destination.h" 4 #include "image_io/base/data_range.h" 5 #include "image_io/base/data_segment.h" 6 7 namespace photos_editing_formats { 8 namespace image_io { 9 Reset()10void DataSegmentDataSource::Reset() {} 11 GetDataSegment(size_t begin,size_t min_size)12std::shared_ptr<DataSegment> DataSegmentDataSource::GetDataSegment( 13 size_t begin, size_t min_size) { 14 DataRange range(begin, begin + min_size); 15 if (range.GetIntersection(shared_data_segment_->GetDataRange()).IsValid()) { 16 return shared_data_segment_; 17 } else { 18 return std::shared_ptr<DataSegment>(nullptr); 19 } 20 } 21 TransferData(const DataRange & data_range,size_t,DataDestination * data_destination)22DataSource::TransferDataResult DataSegmentDataSource::TransferData( 23 const DataRange& data_range, size_t /*best_size*/, 24 DataDestination* data_destination) { 25 bool data_transferred = false; 26 DataDestination::TransferStatus status = DataDestination::kTransferDone; 27 DataRange transfer_range = 28 shared_data_segment_->GetDataRange().GetIntersection(data_range); 29 if (data_destination && transfer_range.IsValid()) { 30 data_transferred = true; 31 status = data_destination->Transfer(transfer_range, *shared_data_segment_); 32 } 33 if (data_transferred) { 34 return status == DataDestination::kTransferError ? kTransferDataError 35 : kTransferDataSuccess; 36 } else { 37 return data_destination ? kTransferDataNone : kTransferDataError; 38 } 39 } 40 41 } // namespace image_io 42 } // namespace photos_editing_formats 43