diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-12-06 21:23:44 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-12-26 17:20:25 +0100 |
| commit | 1f077d2b791a059ccef4069dca07ead990bd568e (patch) | |
| tree | 5db62f135097a375aa0cf80ef9b64be8765480ea | |
| parent | d76b98b8cc9867a2cc9de42f78e6b9be575c0540 (diff) | |
Add Image::crop().
| -rw-r--r-- | src/lib/image.cc | 22 | ||||
| -rw-r--r-- | src/lib/image.h | 2 |
2 files changed, 24 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; +} + diff --git a/src/lib/image.h b/src/lib/image.h index ce4382a42..548ebf717 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -84,6 +84,8 @@ public: bool fast ) const; + std::shared_ptr<Image> crop(Crop crop) const; + void make_black (); void make_transparent (); void alpha_blend (std::shared_ptr<const Image> image, Position<int> pos); |
