diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-08-23 11:17:03 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-08-23 11:17:03 +0100 |
| commit | d6be9f27147113dc6355ed0de7c99d1312aaeebd (patch) | |
| tree | 5df043ccf1a56938f256976cc1f5ce7f2fea6057 | |
| parent | 57796599a3acc10feebcbc87da70daf4d0af04f6 (diff) | |
Tidy up duplicated code.
| -rw-r--r-- | src/lib/image.cc | 40 | ||||
| -rw-r--r-- | src/lib/image.h | 3 | ||||
| -rw-r--r-- | src/lib/player.cc | 9 | ||||
| -rw-r--r-- | test/image_test.cc | 2 | ||||
| -rw-r--r-- | test/make_black_test.cc | 2 |
5 files changed, 13 insertions, 43 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc index bdf7fd173..5c04f70e6 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -79,7 +79,7 @@ Image::components () const } shared_ptr<Image> -Image::scale (libdcp::Size out_size, Scaler const * scaler, bool result_aligned) const +Image::scale (libdcp::Size out_size, Scaler const * scaler, AVPixelFormat result_format, bool result_aligned) const { assert (scaler); /* Empirical testing suggests that sws_scale() will crash if @@ -87,11 +87,11 @@ Image::scale (libdcp::Size out_size, Scaler const * scaler, bool result_aligned) */ assert (aligned ()); - shared_ptr<Image> scaled (new Image (pixel_format(), out_size, result_aligned)); + shared_ptr<Image> scaled (new Image (result_format, out_size, result_aligned)); struct SwsContext* scale_context = sws_getContext ( size().width, size().height, pixel_format(), - out_size.width, out_size.height, pixel_format(), + out_size.width, out_size.height, result_format, scaler->ffmpeg_id (), 0, 0, 0 ); @@ -107,40 +107,6 @@ Image::scale (libdcp::Size out_size, Scaler const * scaler, bool result_aligned) return scaled; } -/** Scale this image to a given size and convert it to RGB. - * @param out_size Output image size in pixels. - * @param scaler Scaler to use. - */ -shared_ptr<Image> -Image::scale_and_convert_to_rgb (libdcp::Size out_size, Scaler const * scaler, bool result_aligned) const -{ - assert (scaler); - /* Empirical testing suggests that sws_scale() will crash if - the input image is not aligned. - */ - assert (aligned ()); - - shared_ptr<Image> rgb (new Image (PIX_FMT_RGB24, out_size, result_aligned)); - - struct SwsContext* scale_context = sws_getContext ( - size().width, size().height, pixel_format(), - out_size.width, out_size.height, PIX_FMT_RGB24, - scaler->ffmpeg_id (), 0, 0, 0 - ); - - /* Scale and convert to RGB from whatever its currently in (which may be RGB) */ - sws_scale ( - scale_context, - data(), stride(), - 0, size().height, - rgb->data(), rgb->stride() - ); - - sws_freeContext (scale_context); - - return rgb; -} - /** Run a FFmpeg post-process on this image and return the processed version. * @param pp Flags for the required set of post processes. * @return Post-processed image. diff --git a/src/lib/image.h b/src/lib/image.h index cc0baf921..6af74a8c5 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -57,8 +57,7 @@ public: int line_factor (int) const; int lines (int) const; - boost::shared_ptr<Image> scale_and_convert_to_rgb (libdcp::Size, Scaler const *, bool) const; - boost::shared_ptr<Image> scale (libdcp::Size, Scaler const *, bool aligned) const; + boost::shared_ptr<Image> scale (libdcp::Size, Scaler const *, AVPixelFormat, bool aligned) const; boost::shared_ptr<Image> post_process (std::string, bool aligned) const; void alpha_blend (boost::shared_ptr<const Image> image, Position<int> pos); void copy (boost::shared_ptr<const Image> image, Position<int> pos); diff --git a/src/lib/player.cc b/src/lib/player.cc index bae00d348..84589ce39 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -255,7 +255,7 @@ Player::process_video (weak_ptr<Piece> weak_piece, shared_ptr<const Image> image libdcp::Size const image_size = content->ratio()->size (_video_container_size); - work_image = work_image->scale_and_convert_to_rgb (image_size, _film->scaler(), true); + work_image = work_image->scale (image_size, _film->scaler(), PIX_FMT_RGB24, true); Time time = content->position() + relative_time - content->trim_start (); @@ -640,7 +640,12 @@ Player::update_subtitle () _out_subtitle.position.x = rint (_video_container_size.width * (in_rect.x + (in_rect.width * (1 - sc->subtitle_scale ()) / 2))); _out_subtitle.position.y = rint (_video_container_size.height * (in_rect.y + (in_rect.height * (1 - sc->subtitle_scale ()) / 2))); - _out_subtitle.image = _in_subtitle.image->scale (libdcp::Size (scaled_size.width, scaled_size.height), Scaler::from_id ("bicubic"), true); + _out_subtitle.image = _in_subtitle.image->scale ( + scaled_size, + Scaler::from_id ("bicubic"), + _in_subtitle.image->pixel_format (), + true + ); _out_subtitle.from = _in_subtitle.from + piece->content->position (); _out_subtitle.to = _in_subtitle.to + piece->content->position (); } diff --git a/test/image_test.cc b/test/image_test.cc index 4205e5f48..82ebe0b1f 100644 --- a/test/image_test.cc +++ b/test/image_test.cc @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE (crop_image_test2) image = image->crop (crop, true); /* Convert it back to RGB to make comparison to black easier */ - image = image->scale_and_convert_to_rgb (image->size(), Scaler::from_id ("bicubic"), true); + image = image->scale (image->size(), Scaler::from_id ("bicubic"), PIX_FMT_RGB24, true); /* Check that its still black after the crop */ uint8_t* p = image->data()[0]; diff --git a/test/make_black_test.cc b/test/make_black_test.cc index 78c7fbbcb..17c78d231 100644 --- a/test/make_black_test.cc +++ b/test/make_black_test.cc @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE (make_black_test) for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) { boost::shared_ptr<Image> foo (new Image (*i, in_size, true)); foo->make_black (); - boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, Scaler::from_id ("bicubic"), true); + boost::shared_ptr<Image> bar = foo->scale (out_size, Scaler::from_id ("bicubic"), PIX_FMT_RGB24, true); uint8_t* p = bar->data()[0]; for (int y = 0; y < bar->size().height; ++y) { |
