diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-04-14 21:38:26 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-04-14 21:38:26 +0200 |
| commit | 3b31d2d8a129ae6d8d267427bd6b5bc444b40b2a (patch) | |
| tree | 780947aefb2249a2614bf9e3d894b5256f015967 /src/lib | |
| parent | b029cb06c4e0fca1fad9fecd78939efe5532fa9a (diff) | |
Use a struct rather than a std::pair as the return type from ImageProxy::image.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ffmpeg_image_proxy.cc | 7 | ||||
| -rw-r--r-- | src/lib/ffmpeg_image_proxy.h | 2 | ||||
| -rw-r--r-- | src/lib/image_examiner.cc | 2 | ||||
| -rw-r--r-- | src/lib/image_proxy.h | 20 | ||||
| -rw-r--r-- | src/lib/j2k_image_proxy.cc | 5 | ||||
| -rw-r--r-- | src/lib/j2k_image_proxy.h | 2 | ||||
| -rw-r--r-- | src/lib/player_video.cc | 20 | ||||
| -rw-r--r-- | src/lib/raw_image_proxy.cc | 6 | ||||
| -rw-r--r-- | src/lib/raw_image_proxy.h | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 2 |
10 files changed, 40 insertions, 28 deletions
diff --git a/src/lib/ffmpeg_image_proxy.cc b/src/lib/ffmpeg_image_proxy.cc index 9c91d1d87..87fb154d0 100644 --- a/src/lib/ffmpeg_image_proxy.cc +++ b/src/lib/ffmpeg_image_proxy.cc @@ -112,13 +112,14 @@ FFmpegImageProxy::avio_seek (int64_t const pos, int whence) return _pos; } -pair<shared_ptr<Image>, int> + +ImageProxy::Result FFmpegImageProxy::image (optional<dcp::Size>) const { boost::mutex::scoped_lock lm (_mutex); if (_image) { - return make_pair (_image, 0); + return Result (_image, 0); } uint8_t* avio_buffer = static_cast<uint8_t*> (wrapped_av_malloc(4096)); @@ -192,7 +193,7 @@ FFmpegImageProxy::image (optional<dcp::Size>) const av_free (avio_context->buffer); av_free (avio_context); - return make_pair (_image, 0); + return Result (_image, 0); } void diff --git a/src/lib/ffmpeg_image_proxy.h b/src/lib/ffmpeg_image_proxy.h index 5f9b3b131..88e31ad4a 100644 --- a/src/lib/ffmpeg_image_proxy.h +++ b/src/lib/ffmpeg_image_proxy.h @@ -30,7 +30,7 @@ public: explicit FFmpegImageProxy (dcp::Data); FFmpegImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket); - std::pair<boost::shared_ptr<Image>, int> image ( + Result image ( boost::optional<dcp::Size> size = boost::optional<dcp::Size> () ) const; diff --git a/src/lib/image_examiner.cc b/src/lib/image_examiner.cc index b9ef89865..6586a0d09 100644 --- a/src/lib/image_examiner.cc +++ b/src/lib/image_examiner.cc @@ -64,7 +64,7 @@ ImageExaminer::ImageExaminer (shared_ptr<const Film> film, shared_ptr<const Imag delete[] buffer; } else { FFmpegImageProxy proxy(content->path(0)); - _video_size = proxy.image().first->size(); + _video_size = proxy.image().image->size(); } if (content->still ()) { diff --git a/src/lib/image_proxy.h b/src/lib/image_proxy.h index b6fe87732..9619fab75 100644 --- a/src/lib/image_proxy.h +++ b/src/lib/image_proxy.h @@ -60,14 +60,26 @@ class ImageProxy : public boost::noncopyable public: virtual ~ImageProxy () {} + struct Result { + Result (boost::shared_ptr<Image> image_, int log2_scaling_) + : image (image_) + , log2_scaling (log2_scaling_) + {} + + /** Image (which will be aligned) */ + boost::shared_ptr<Image> image; + /** log2 of any scaling down that has already been applied to the image; + * e.g. if the image is already half the size of the original, this value + * will be 1. + */ + int log2_scaling; + }; + /** @param log Log to write to, or 0. * @param size Size that the returned image will be scaled to, in case this * can be used as an optimisation. - * @return Image (which must be aligned) and log2 of any scaling down that has - * already been applied to the image; e.g. if the the image is already half the size - * of the original, the second part of the return value will be 1. */ - virtual std::pair<boost::shared_ptr<Image>, int> image ( + virtual Result image ( boost::optional<dcp::Size> size = boost::optional<dcp::Size> () ) const = 0; diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index 31fda2510..da3e23caf 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -167,14 +167,15 @@ J2KImageProxy::prepare (optional<dcp::Size> target_size) const return reduce; } -pair<shared_ptr<Image>, int> + +ImageProxy::Result J2KImageProxy::image (optional<dcp::Size> target_size) const { int const r = prepare (target_size); /* I think this is safe without a lock on mutex. _image is guaranteed to be set up when prepare() has happened. */ - return make_pair (_image, r); + return Result (_image, r); } void diff --git a/src/lib/j2k_image_proxy.h b/src/lib/j2k_image_proxy.h index 510c0ff25..ec99e71a9 100644 --- a/src/lib/j2k_image_proxy.h +++ b/src/lib/j2k_image_proxy.h @@ -50,7 +50,7 @@ public: J2KImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket); - std::pair<boost::shared_ptr<Image>, int> image ( + Result image ( boost::optional<dcp::Size> size = boost::optional<dcp::Size> () ) const; diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index 75479136f..bd643af60 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -132,31 +132,29 @@ PlayerVideo::make_image (function<AVPixelFormat (AVPixelFormat)> pixel_format, b _image_out_size = _out_size; _image_fade = _fade; - pair<shared_ptr<Image>, int> prox = _in->image (_inter_size); - shared_ptr<Image> im = prox.first; - int const reduce = prox.second; + ImageProxy::Result prox = _in->image (_inter_size); Crop total_crop = _crop; switch (_part) { case PART_LEFT_HALF: - total_crop.right += im->size().width / 2; + total_crop.right += prox.image->size().width / 2; break; case PART_RIGHT_HALF: - total_crop.left += im->size().width / 2; + total_crop.left += prox.image->size().width / 2; break; case PART_TOP_HALF: - total_crop.bottom += im->size().height / 2; + total_crop.bottom += prox.image->size().height / 2; break; case PART_BOTTOM_HALF: - total_crop.top += im->size().height / 2; + total_crop.top += prox.image->size().height / 2; break; default: break; } - if (reduce > 0) { + if (prox.log2_scaling > 0) { /* Scale the crop down to account for the scaling that has already happened in ImageProxy::image */ - int const r = pow(2, reduce); + int const r = pow(2, prox.log2_scaling); total_crop.left /= r; total_crop.right /= r; total_crop.top /= r; @@ -168,8 +166,8 @@ PlayerVideo::make_image (function<AVPixelFormat (AVPixelFormat)> pixel_format, b yuv_to_rgb = _colour_conversion.get().yuv_to_rgb(); } - _image = im->crop_scale_window ( - total_crop, _inter_size, _out_size, yuv_to_rgb, _video_range, pixel_format (im->pixel_format()), aligned, fast + _image = prox.image->crop_scale_window ( + total_crop, _inter_size, _out_size, yuv_to_rgb, _video_range, pixel_format (prox.image->pixel_format()), aligned, fast ); if (_text) { diff --git a/src/lib/raw_image_proxy.cc b/src/lib/raw_image_proxy.cc index 21201faa6..5bd8c4811 100644 --- a/src/lib/raw_image_proxy.cc +++ b/src/lib/raw_image_proxy.cc @@ -54,10 +54,10 @@ RawImageProxy::RawImageProxy (shared_ptr<cxml::Node> xml, shared_ptr<Socket> soc _image->read_from_socket (socket); } -pair<shared_ptr<Image>, int> +ImageProxy::Result RawImageProxy::image (optional<dcp::Size>) const { - return make_pair (_image, 0); + return Result (_image, 0); } void @@ -83,7 +83,7 @@ RawImageProxy::same (shared_ptr<const ImageProxy> other) const return false; } - return (*_image.get()) == (*rp->image().first.get()); + return (*_image.get()) == (*rp->image().image.get()); } size_t diff --git a/src/lib/raw_image_proxy.h b/src/lib/raw_image_proxy.h index dcd107a9e..a247d7610 100644 --- a/src/lib/raw_image_proxy.h +++ b/src/lib/raw_image_proxy.h @@ -29,7 +29,7 @@ public: explicit RawImageProxy (boost::shared_ptr<Image>); RawImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket); - std::pair<boost::shared_ptr<Image>, int> image ( + Result image ( boost::optional<dcp::Size> size = boost::optional<dcp::Size> () ) const; diff --git a/src/lib/util.cc b/src/lib/util.cc index e4f552c4d..d04bbdf24 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -927,7 +927,7 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size { /* XXX: this is rather inefficient; decoding the image just to get its size */ FFmpegImageProxy proxy (sub.png_image()); - shared_ptr<Image> image = proxy.image().first; + shared_ptr<Image> image = proxy.image().image; /* set up rect with height and width */ dcpomatic::Rect<double> rect(0, 0, image->size().width / double(size.width), image->size().height / double(size.height)); |
