diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-06-16 14:53:35 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-06-16 14:53:35 +0100 |
| commit | 4699463e19b2a153d64aeb0e00c62be1157bfc1b (patch) | |
| tree | 971d505d0b5a8253a24eb95854effb5e34893c8c /src/lib | |
| parent | 12074b64d64c1fe76a9cf07a46683b7db96fc56e (diff) | |
Some work on cropping in the film viewer; also prevent player from always scaling up to DCP resolution.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/combiner.cc | 2 | ||||
| -rw-r--r-- | src/lib/filter_graph.cc | 7 | ||||
| -rw-r--r-- | src/lib/image.cc | 31 | ||||
| -rw-r--r-- | src/lib/image.h | 3 | ||||
| -rw-r--r-- | src/lib/player.cc | 12 | ||||
| -rw-r--r-- | src/lib/player.h | 3 | ||||
| -rw-r--r-- | src/lib/video_decoder.cc | 8 | ||||
| -rw-r--r-- | src/lib/video_decoder.h | 3 |
8 files changed, 47 insertions, 22 deletions
diff --git a/src/lib/combiner.cc b/src/lib/combiner.cc index ca68ef68a..44971d135 100644 --- a/src/lib/combiner.cc +++ b/src/lib/combiner.cc @@ -34,7 +34,7 @@ Combiner::Combiner () void Combiner::process_video (shared_ptr<const Image> image, bool, Time) { - _image.reset (new SimpleImage (image)); + _image.reset (new SimpleImage (image, true)); } /** Process video for the right half of the frame. diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc index 472480de3..b13b232a9 100644 --- a/src/lib/filter_graph.cc +++ b/src/lib/filter_graph.cc @@ -63,11 +63,8 @@ FilterGraph::FilterGraph (shared_ptr<const FFmpegContent> content, libdcp::Size filters += ","; } - Crop crop = content->crop (); - libdcp::Size cropped_size = _size; - cropped_size.width -= crop.left + crop.right; - cropped_size.height -= crop.top + crop.bottom; - filters += crop_string (Position (crop.left, crop.top), cropped_size); + /* XXX; remove */ + filters += crop_string (Position (), _size); AVFilterGraph* graph = avfilter_graph_alloc(); if (graph == 0) { diff --git a/src/lib/image.cc b/src/lib/image.cc index 17c969cf2..5f7d3f034 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -53,22 +53,28 @@ Image::swap (Image& other) std::swap (_pixel_format, other._pixel_format); } -/** @param n Component index. - * @return Number of lines in the image for the given component. - */ int -Image::lines (int n) const +Image::line_factor (int n) const { if (n == 0) { - return size().height; + return 1; } - + AVPixFmtDescriptor const * d = av_pix_fmt_desc_get(_pixel_format); if (!d) { throw PixelFormatError (N_("lines()"), _pixel_format); } - return size().height / pow(2.0f, d->log2_chroma_h); + return pow (2.0f, d->log2_chroma_h); +} + +/** @param n Component index. + * @return Number of lines in the image for the given component. + */ +int +Image::lines (int n) const +{ + return size().height / line_factor (n); } /** @return Number of components */ @@ -207,9 +213,9 @@ Image::crop (Crop crop, bool aligned) const for (int c = 0; c < components(); ++c) { int const crop_left_in_bytes = bytes_per_pixel(c) * crop.left; int const cropped_width_in_bytes = bytes_per_pixel(c) * cropped_size.width; - + /* Start of the source line, cropped from the top but not the left */ - uint8_t* in_p = data()[c] + crop.top * stride()[c]; + uint8_t* in_p = data()[c] + (crop.top / out->line_factor(c)) * stride()[c]; uint8_t* out_p = out->data()[c]; for (int y = 0; y < out->lines(c); ++y) { @@ -502,12 +508,11 @@ SimpleImage::SimpleImage (AVFrame* frame) } } -SimpleImage::SimpleImage (shared_ptr<const Image> other) +SimpleImage::SimpleImage (shared_ptr<const Image> other, bool aligned) : Image (*other.get()) + , _size (other->size()) + , _aligned (aligned) { - _size = other->size (); - _aligned = true; - allocate (); for (int i = 0; i < components(); ++i) { diff --git a/src/lib/image.h b/src/lib/image.h index f9bda7460..5407ce66e 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -69,6 +69,7 @@ public: virtual bool aligned () const = 0; int components () const; + int line_factor (int) const; int lines (int) const; boost::shared_ptr<Image> scale_and_convert_to_rgb (libdcp::Size, Scaler const *, bool) const; @@ -109,7 +110,7 @@ public: SimpleImage (AVPixelFormat, libdcp::Size, bool); SimpleImage (AVFrame *); SimpleImage (SimpleImage const &); - SimpleImage (boost::shared_ptr<const Image>); + SimpleImage (boost::shared_ptr<const Image>, bool); SimpleImage& operator= (SimpleImage const &); ~SimpleImage (); diff --git a/src/lib/player.cc b/src/lib/player.cc index 85b4cbd4f..1931ec0f5 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -382,3 +382,15 @@ Player::playlist_changed () { _have_valid_pieces = false; } + +void +Player::set_video_container_size (libdcp::Size s) +{ + _video_container_size = s; + for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { + shared_ptr<VideoDecoder> vd = dynamic_pointer_cast<VideoDecoder> ((*i)->decoder); + if (vd) { + vd->set_video_container_size (s); + } + } +} diff --git a/src/lib/player.h b/src/lib/player.h index b00454093..95f419b5e 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -61,6 +61,8 @@ public: return _position; } + void set_video_container_size (libdcp::Size); + private: void process_video (boost::weak_ptr<Content>, boost::shared_ptr<const Image>, bool, Time); @@ -86,6 +88,7 @@ private: Time _position; AudioBuffers _audio_buffers; Time _next_audio; + boost::optional<libdcp::Size> _video_container_size; }; #endif diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc index d1a8fc6e6..58aceb407 100644 --- a/src/lib/video_decoder.cc +++ b/src/lib/video_decoder.cc @@ -56,7 +56,7 @@ VideoDecoder::video (shared_ptr<Image> image, bool same, Time t) shared_ptr<const Film> film = _film.lock (); assert (film); - libdcp::Size const container_size = film->container()->size (film->full_frame ()); + libdcp::Size const container_size = _video_container_size.get_value_or (film->container()->size (film->full_frame ())); libdcp::Size const image_size = _video_content->ratio()->size (container_size); shared_ptr<Image> out = image->scale_and_convert_to_rgb (image_size, film->scaler(), true); @@ -144,4 +144,8 @@ VideoDecoder::seek_forward () _next_video += film->video_frames_to_time (1); } - +void +VideoDecoder::set_video_container_size (libdcp::Size s) +{ + _video_container_size = s; +} diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h index b47d7fc3a..f0d140d80 100644 --- a/src/lib/video_decoder.h +++ b/src/lib/video_decoder.h @@ -44,6 +44,8 @@ public: /** @return length according to our content's header */ virtual ContentVideoFrame video_length () const = 0; + void set_video_container_size (libdcp::Size); + protected: void video (boost::shared_ptr<Image>, bool, Time); @@ -57,6 +59,7 @@ private: boost::shared_ptr<TimedSubtitle> _timed_subtitle; FrameRateConversion _frame_rate_conversion; bool _odd; + boost::optional<libdcp::Size> _video_container_size; }; #endif |
