From: Carl Hetherington Date: Tue, 14 Apr 2020 19:38:26 +0000 (+0200) Subject: Use a struct rather than a std::pair as the return type from ImageProxy::image. X-Git-Tag: v2.15.52~21 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=3b31d2d8a129ae6d8d267427bd6b5bc444b40b2a Use a struct rather than a std::pair as the return type from ImageProxy::image. --- 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, int> + +ImageProxy::Result FFmpegImageProxy::image (optional) const { boost::mutex::scoped_lock lm (_mutex); if (_image) { - return make_pair (_image, 0); + return Result (_image, 0); } uint8_t* avio_buffer = static_cast (wrapped_av_malloc(4096)); @@ -192,7 +193,7 @@ FFmpegImageProxy::image (optional) 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 xml, boost::shared_ptr socket); - std::pair, int> image ( + Result image ( boost::optional size = boost::optional () ) 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 film, shared_ptrpath(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_, int log2_scaling_) + : image (image_) + , log2_scaling (log2_scaling_) + {} + + /** Image (which will be aligned) */ + boost::shared_ptr 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, int> image ( + virtual Result image ( boost::optional size = boost::optional () ) 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 target_size) const return reduce; } -pair, int> + +ImageProxy::Result J2KImageProxy::image (optional 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 xml, boost::shared_ptr socket); - std::pair, int> image ( + Result image ( boost::optional size = boost::optional () ) 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 pixel_format, b _image_out_size = _out_size; _image_fade = _fade; - pair, int> prox = _in->image (_inter_size); - shared_ptr 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 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 xml, shared_ptr soc _image->read_from_socket (socket); } -pair, int> +ImageProxy::Result RawImageProxy::image (optional) const { - return make_pair (_image, 0); + return Result (_image, 0); } void @@ -83,7 +83,7 @@ RawImageProxy::same (shared_ptr 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); RawImageProxy (boost::shared_ptr xml, boost::shared_ptr socket); - std::pair, int> image ( + Result image ( boost::optional size = boost::optional () ) 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 = proxy.image().first; + shared_ptr image = proxy.image().image; /* set up rect with height and width */ dcpomatic::Rect rect(0, 0, image->size().width / double(size.width), image->size().height / double(size.height)); diff --git a/test/image_test.cc b/test/image_test.cc index e021322e0..5fccf6b9b 100644 --- a/test/image_test.cc +++ b/test/image_test.cc @@ -138,7 +138,7 @@ void alpha_blend_test_one (AVPixelFormat format, string suffix) { shared_ptr proxy (new FFmpegImageProxy (TestPaths::private_data / "prophet_frame.tiff")); - shared_ptr raw = proxy->image().first; + shared_ptr raw = proxy->image().image; shared_ptr background = raw->convert_pixel_format (dcp::YUV_TO_RGB_REC709, format, true, false); shared_ptr overlay (new Image (AV_PIX_FMT_BGRA, dcp::Size(431, 891), true)); @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE (merge_test2) BOOST_AUTO_TEST_CASE (crop_scale_window_test) { shared_ptr proxy(new FFmpegImageProxy("test/data/flat_red.png")); - shared_ptr raw = proxy->image().first; + shared_ptr raw = proxy->image().image; shared_ptr out = raw->crop_scale_window(Crop(), dcp::Size(1998, 836), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_YUV420P, true, false); shared_ptr save = out->scale(dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, false, false); write_image(save, "build/test/crop_scale_window_test.png", "RGB"); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test2) BOOST_AUTO_TEST_CASE (crop_scale_window_test3) { shared_ptr proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png")); - shared_ptr xyz = proxy->image().first->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false); + shared_ptr xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false); shared_ptr cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_RGB24, false, false); write_image(cropped, "build/test/crop_scale_window_test3.png", "RGB", MagickCore::CharPixel); check_image("test/data/crop_scale_window_test3.png", "build/test/crop_scale_window_test3.png"); @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test3) BOOST_AUTO_TEST_CASE (crop_scale_window_test4) { shared_ptr proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png")); - shared_ptr xyz = proxy->image().first->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false); + shared_ptr xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB24, true, false); shared_ptr cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_XYZ12LE, false, false); write_image(cropped, "build/test/crop_scale_window_test4.png", "RGB", MagickCore::ShortPixel); check_image("test/data/crop_scale_window_test4.png", "build/test/crop_scale_window_test4.png"); @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test4) BOOST_AUTO_TEST_CASE (crop_scale_window_test5) { shared_ptr proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png")); - shared_ptr xyz = proxy->image().first->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_XYZ12LE, true, false); + shared_ptr xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_XYZ12LE, true, false); shared_ptr cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_RGB24, false, false); write_image(cropped, "build/test/crop_scale_window_test5.png", "RGB", MagickCore::CharPixel); check_image("test/data/crop_scale_window_test5.png", "build/test/crop_scale_window_test5.png"); @@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test5) BOOST_AUTO_TEST_CASE (crop_scale_window_test6) { shared_ptr proxy(new FFmpegImageProxy("test/data/player_seek_test_0.png")); - shared_ptr xyz = proxy->image().first->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_XYZ12LE, true, false); + shared_ptr xyz = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_XYZ12LE, true, false); shared_ptr cropped = xyz->crop_scale_window(Crop(512, 0, 0, 0), dcp::Size(1486, 1080), dcp::Size(1998, 1080), dcp::YUV_TO_RGB_REC709, VIDEO_RANGE_FULL, AV_PIX_FMT_XYZ12LE, false, false); write_image(cropped, "build/test/crop_scale_window_test6.png", "RGB", MagickCore::ShortPixel); check_image("test/data/crop_scale_window_test6.png", "build/test/crop_scale_window_test6.png"); @@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE (crop_scale_window_test6) BOOST_AUTO_TEST_CASE (as_png_test) { shared_ptr proxy(new FFmpegImageProxy("test/data/3d_test/000001.png")); - shared_ptr image_rgb = proxy->image().first; + shared_ptr image_rgb = proxy->image().image; shared_ptr image_bgr = image_rgb->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_BGRA, true, false); image_rgb->as_png().write ("build/test/as_png_rgb.png"); image_bgr->as_png().write ("build/test/as_png_bgr.png"); @@ -340,7 +340,7 @@ static void fade_test_format_red (AVPixelFormat f, float amount, string name) { shared_ptr proxy(new FFmpegImageProxy("test/data/flat_red.png")); - shared_ptr red = proxy->image().first->convert_pixel_format(dcp::YUV_TO_RGB_REC709, f, true, false); + shared_ptr red = proxy->image().image->convert_pixel_format(dcp::YUV_TO_RGB_REC709, f, true, false); red->fade (amount); string const filename = "fade_test_red_" + name + ".png"; red->convert_pixel_format(dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGBA, true, false)->as_png().write("build/test/" + filename);