diff options
Diffstat (limited to 'src/lib/image.cc')
| -rw-r--r-- | src/lib/image.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc index f1586be4d..80ef92d06 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -60,9 +60,11 @@ using std::list; using std::make_shared; using std::max; using std::min; +using std::pair; using std::runtime_error; using std::shared_ptr; using std::string; +using std::vector; using dcp::Size; @@ -1706,3 +1708,23 @@ Image::video_range_to_full_range () } } + +shared_ptr<Image> +Image::crop(Crop crop) const +{ + vector<uint8_t*> scale_in_data; + dcp::Size cropped_size; + std::tie(scale_in_data, cropped_size) = crop_source_pointers(crop); + + auto out = make_shared<Image>(_pixel_format, cropped_size, _alignment); + + for (int c = 0; c < planes(); ++c) { + auto const out_data = out->data()[c]; + for (int y = 0; y < cropped_size.height; ++y) { + memcpy(out_data + y * out->stride()[c], scale_in_data[c] + y * stride()[c], cropped_size.width * bytes_per_pixel(c)); + } + } + + return out; +} + |
