• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "image_io/base/data_range_tracking_destination.h"
2 
3 namespace photos_editing_formats {
4 namespace image_io {
5 
StartTransfer()6 void DataRangeTrackingDestination::StartTransfer() {
7   tracked_data_range_ = DataRange();
8   bytes_transferred_ = 0;
9   has_disjoint_transfer_ranges_ = false;
10   if (destination_ != nullptr) {
11     destination_->StartTransfer();
12   }
13 }
14 
Transfer(const DataRange & transfer_range,const DataSegment & data_segment)15 DataDestination::TransferStatus DataRangeTrackingDestination::Transfer(
16     const DataRange& transfer_range, const DataSegment& data_segment) {
17   DataDestination::TransferStatus transfer_status =
18       destination_ ? destination_->Transfer(transfer_range, data_segment)
19                    : DataDestination::kTransferOk;
20   if (transfer_status != kTransferError) {
21     bytes_transferred_ += transfer_range.GetLength();
22   }
23   if (has_disjoint_transfer_ranges_) {
24     return transfer_status;
25   }
26   if (!tracked_data_range_.IsValid()) {
27     tracked_data_range_ = transfer_range;
28     return transfer_status;
29   }
30   if (tracked_data_range_.GetEnd() == transfer_range.GetBegin()) {
31     tracked_data_range_ =
32         DataRange(tracked_data_range_.GetBegin(), transfer_range.GetEnd());
33     return transfer_status;
34   } else {
35     has_disjoint_transfer_ranges_ = true;
36     return transfer_status;
37   }
38 }
39 
FinishTransfer()40 void DataRangeTrackingDestination::FinishTransfer() {
41   if (destination_ != nullptr) {
42     destination_->FinishTransfer();
43   }
44 }
45 
46 }  // namespace image_io
47 }  // namespace photos_editing_formats
48