diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-07-22 00:18:32 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-08-12 17:16:07 +0200 |
| commit | 9b73c143ce568bd8694e3a50f2fefc1ee3a03515 (patch) | |
| tree | b6774c68129ccc687c34a8271fa5e1361b93d3d0 /src/lib | |
| parent | 0114987c5d6040d8fe07a719d7f97b0a5e200458 (diff) | |
Replace AVPixelFormat parameter to PlayerVideo::image with a functor.
This was removed in df9b4676aba8b941f124b174393988cad21677e1 and
surrounding commits, but it turns out we need it after all.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/dcp_video.cc | 9 | ||||
| -rw-r--r-- | src/lib/ffmpeg_file_encoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/mpeg2_encoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/player_video.cc | 10 | ||||
| -rw-r--r-- | src/lib/player_video.h | 4 | ||||
| -rw-r--r-- | src/lib/util.cc | 7 | ||||
| -rw-r--r-- | src/lib/util.h | 1 |
7 files changed, 22 insertions, 13 deletions
diff --git a/src/lib/dcp_video.cc b/src/lib/dcp_video.cc index f07801c03..823325c3e 100644 --- a/src/lib/dcp_video.cc +++ b/src/lib/dcp_video.cc @@ -41,6 +41,7 @@ #include "log.h" #include "player_video.h" #include "rng.h" +#include "util.h" #include <libcxml/cxml.h> #include <dcp/openjpeg_image.h> #include <dcp/rgb_xyz.h> @@ -101,7 +102,7 @@ DCPVideo::convert_to_xyz(shared_ptr<const PlayerVideo> frame) shared_ptr<dcp::OpenJPEGImage> xyz; if (frame->colour_conversion()) { - auto image = frame->image(AV_PIX_FMT_RGB48LE, VideoRange::FULL, false); + auto image = frame->image(force(AV_PIX_FMT_RGB48LE), VideoRange::FULL, false); xyz = dcp::rgb_to_xyz( image->data()[0], image->size(), @@ -109,7 +110,7 @@ DCPVideo::convert_to_xyz(shared_ptr<const PlayerVideo> frame) frame->colour_conversion().get() ); } else { - auto image = frame->image(AV_PIX_FMT_XYZ12LE, VideoRange::FULL, false); + auto image = frame->image(force(AV_PIX_FMT_RGB48LE), VideoRange::FULL, false); xyz = make_shared<dcp::OpenJPEGImage>(image->data()[0], image->size(), image->stride()[0]); } @@ -119,7 +120,7 @@ DCPVideo::convert_to_xyz(shared_ptr<const PlayerVideo> frame) dcp::Size DCPVideo::get_size() const { - auto image = _frame->image(AV_PIX_FMT_RGB48LE, VideoRange::FULL, false); + auto image = _frame->image(force(AV_PIX_FMT_RGB48LE), VideoRange::FULL, false); return image->size(); } @@ -129,7 +130,7 @@ DCPVideo::convert_to_xyz(uint16_t* dst) const { DCPOMATIC_ASSERT(_frame->colour_conversion()); - auto image = _frame->image(AV_PIX_FMT_RGB48LE, VideoRange::FULL, false); + auto image = _frame->image(force(AV_PIX_FMT_RGB48LE), VideoRange::FULL, false); dcp::rgb_to_xyz( image->data()[0], dst, diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc index 3355c2ac8..9df078ad4 100644 --- a/src/lib/ffmpeg_file_encoder.cc +++ b/src/lib/ffmpeg_file_encoder.cc @@ -416,7 +416,7 @@ void FFmpegFileEncoder::video (shared_ptr<PlayerVideo> video, DCPTime time) { /* All our output formats are video range at the moment */ - auto image = video->image(_pixel_format, VideoRange::VIDEO, false); + auto image = video->image(force(_pixel_format), VideoRange::VIDEO, false); auto frame = av_frame_alloc (); DCPOMATIC_ASSERT (frame); diff --git a/src/lib/mpeg2_encoder.cc b/src/lib/mpeg2_encoder.cc index 73f3d57e7..38388431d 100644 --- a/src/lib/mpeg2_encoder.cc +++ b/src/lib/mpeg2_encoder.cc @@ -43,7 +43,7 @@ MPEG2Encoder::encode(shared_ptr<PlayerVideo> pv, dcpomatic::DCPTime time) { VideoEncoder::encode(pv, time); - auto image = pv->image(AV_PIX_FMT_YUV420P, VideoRange::VIDEO, false); + auto image = pv->image(force(AV_PIX_FMT_YUV420P), VideoRange::VIDEO, false); dcp::FFmpegImage ffmpeg_image(time.get() * _film->video_frame_rate() / dcpomatic::DCPTime::HZ); diff --git a/src/lib/player_video.cc b/src/lib/player_video.cc index b304d60df..63811fb69 100644 --- a/src/lib/player_video.cc +++ b/src/lib/player_video.cc @@ -116,7 +116,7 @@ PlayerVideo::set_text(PositionImage image) shared_ptr<Image> -PlayerVideo::image(AVPixelFormat pixel_format, VideoRange video_range, bool fast) const +PlayerVideo::image(function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const { /* XXX: this assumes that image() and prepare() are only ever called with the same parameters (except crop, inter size, out size, fade) */ @@ -136,11 +136,11 @@ PlayerVideo::raw_image() const /** Create an image for this frame. A lock must be held on _mutex. - * @param pixel_format Output image pixel format. + * @param pixel_format Functor returning output image pixel format for a given input pixel format. * @param fast true to be fast at the expense of quality. */ void -PlayerVideo::make_image(AVPixelFormat pixel_format, VideoRange video_range, bool fast) const +PlayerVideo::make_image(function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const { _image_crop = _crop; _image_inter_size = _inter_size; @@ -183,7 +183,7 @@ PlayerVideo::make_image(AVPixelFormat pixel_format, VideoRange video_range, bool } _image = prox.image->crop_scale_window( - total_crop, _inter_size, _out_size, yuv_to_rgb, _video_range, pixel_format, video_range, Image::Alignment::COMPACT, fast + total_crop, _inter_size, _out_size, yuv_to_rgb, _video_range, pixel_format(prox.image->pixel_format()), video_range, Image::Alignment::COMPACT, fast ); if (_text) { @@ -301,7 +301,7 @@ PlayerVideo::prepare(AVPixelFormat pixel_format, VideoRange video_range, Image:: _in->prepare(alignment, _inter_size); boost::mutex::scoped_lock lm(_mutex); if (!_image && !proxy_only) { - make_image(pixel_format, video_range, fast); + make_image(force(pixel_format), video_range, fast); } } diff --git a/src/lib/player_video.h b/src/lib/player_video.h index df0ef6d15..48c927f85 100644 --- a/src/lib/player_video.h +++ b/src/lib/player_video.h @@ -76,7 +76,7 @@ public: } void prepare(AVPixelFormat pixel_format, VideoRange video_range, Image::Alignment alignment, bool fast, bool proxy_only); - std::shared_ptr<Image> image(AVPixelFormat pixel_format, VideoRange video_range, bool fast) const; + std::shared_ptr<Image> image(std::function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const; std::shared_ptr<const Image> raw_image() const; void add_metadata(xmlpp::Element* element) const; @@ -128,7 +128,7 @@ public: } private: - void make_image(AVPixelFormat pixel_format, VideoRange video_range, bool fast) const; + void make_image(std::function<AVPixelFormat (AVPixelFormat)> pixel_format, VideoRange video_range, bool fast) const; std::shared_ptr<const ImageProxy> _in; Crop _crop; diff --git a/src/lib/util.cc b/src/lib/util.cc index 12ea8c0eb..fb9c1bb2d 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1171,3 +1171,10 @@ paths_exist(vector<boost::filesystem::path> const& paths) return std::all_of(paths.begin(), paths.end(), [](boost::filesystem::path const& path) { return dcp::filesystem::exists(path); }); } + +std::function<AVPixelFormat (AVPixelFormat)> +force(AVPixelFormat format) +{ + return [format](AVPixelFormat) { return format; }; +} + diff --git a/src/lib/util.h b/src/lib/util.h index 79ac87db1..846059e1a 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -101,6 +101,7 @@ extern void setup_grok_library_path(); extern std::string join_strings(std::vector<std::string> const& in, std::string const& separator = " "); extern std::string rfc_2822_date(time_t time); bool paths_exist(std::vector<boost::filesystem::path> const& paths); +std::function<AVPixelFormat (AVPixelFormat)> force(AVPixelFormat format); template <class T> |
