Merge 1.0 and some subtitling fixes.
authorCarl Hetherington <cth@carlh.net>
Tue, 24 Dec 2013 01:12:40 +0000 (01:12 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 24 Dec 2013 01:12:40 +0000 (01:12 +0000)
src/lib/decoded.h
src/lib/ffmpeg_decoder.cc
src/lib/image.cc
src/lib/player.cc
src/lib/player.h
src/lib/subtitle_decoder.cc
src/lib/subtitle_decoder.h
src/lib/video_decoder.cc

index a9b9227691c0ee258c1a3053fc6c26b6b85560da..1de2ff79e5222e76156c368f10f263e3c3cf158a 100644 (file)
@@ -94,13 +94,12 @@ public:
                , dcp_time_to (0)
        {}
 
-       /* XXX: content/dcp time here */
-       DecodedSubtitle (boost::shared_ptr<Image> im, dcpomatic::Rect<double> r, DCPTime f, DCPTime t)
+       DecodedSubtitle (boost::shared_ptr<Image> im, dcpomatic::Rect<double> r, ContentTime f, ContentTime t)
                : Decoded (f)
                , image (im)
                , rect (r)
                , content_time_to (t)
-               , dcp_time_to (t)
+               , dcp_time_to (0)
        {}
 
        void set_dcp_times (float speed_up, DCPTime offset) {
index c6e4217b6740959dc2ac23cf3dd2cfb91d2fc2e6..298284512371b87c53ba21edee018434f218d009 100644 (file)
@@ -562,8 +562,8 @@ FFmpegDecoder::decode_subtitle_packet ()
        double const packet_time = static_cast<double> (sub.pts) / AV_TIME_BASE;
        
        /* hence start time for this sub */
-       DCPTime const from = (packet_time + (double (sub.start_display_time) / 1e3)) * TIME_HZ;
-       DCPTime const to = (packet_time + (double (sub.end_display_time) / 1e3)) * TIME_HZ;
+       ContentTime const from = (packet_time + (double (sub.start_display_time) / 1e3)) * TIME_HZ;
+       ContentTime const to = (packet_time + (double (sub.end_display_time) / 1e3)) * TIME_HZ;
 
        AVSubtitleRect const * rect = sub.rects[0];
 
index 18ddbc98dc7bdbffa64a9f9f55185e1a5ab948a8..5b5491101b7835b3453a935e9c61fdbc55cf64f2 100644 (file)
@@ -376,8 +376,11 @@ Image::make_black ()
 void
 Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
 {
-       /* Only implemented for RGBA onto RGB24 so far */
-       assert (_pixel_format == PIX_FMT_RGB24 && other->pixel_format() == PIX_FMT_RGBA);
+       /* Only implemented for RGBA onto BGRA so far */
+       assert (_pixel_format == PIX_FMT_BGRA && other->pixel_format() == PIX_FMT_RGBA);
+
+       int const this_bpp = 4;
+       int const other_bpp = 4;
 
        int start_tx = position.x;
        int start_ox = 0;
@@ -396,15 +399,15 @@ Image::alpha_blend (shared_ptr<const Image> other, Position<int> position)
        }
 
        for (int ty = start_ty, oy = start_oy; ty < size().height && oy < other->size().height; ++ty, ++oy) {
-               uint8_t* tp = data()[0] + ty * stride()[0] + position.x * 3;
+               uint8_t* tp = data()[0] + ty * stride()[0] + position.x * this_bpp;
                uint8_t* op = other->data()[0] + oy * other->stride()[0];
                for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) {
                        float const alpha = float (op[3]) / 255;
                        tp[0] = (tp[0] * (1 - alpha)) + op[0] * alpha;
                        tp[1] = (tp[1] * (1 - alpha)) + op[1] * alpha;
                        tp[2] = (tp[2] * (1 - alpha)) + op[2] * alpha;
-                       tp += 3;
-                       op += 4;
+                       tp += this_bpp;
+                       op += other_bpp;
                }
        }
 }
index a5f0006d99547cdf000ebad7b0b1e83aa53c6c27..0f2cc0365d642ca1489f07a757d143d7178e8583 100644 (file)
@@ -232,8 +232,8 @@ Player::emit_video (weak_ptr<Piece> weak_piece, shared_ptr<DecodedVideo> video)
        
        if (
                _film->with_subtitles () &&
-               _out_subtitle.subtitle->image &&
-               video->dcp_time >= _out_subtitle.subtitle->dcp_time && video->dcp_time <= _out_subtitle.subtitle->dcp_time_to
+               _out_subtitle.image &&
+               video->dcp_time >= _out_subtitle.from && video->dcp_time <= _out_subtitle.to
                ) {
 
                Position<int> const container_offset (
@@ -241,7 +241,7 @@ Player::emit_video (weak_ptr<Piece> weak_piece, shared_ptr<DecodedVideo> video)
                        (_video_container_size.height - image_size.width) / 2
                        );
 
-               pi->set_subtitle (_out_subtitle.subtitle->image, _out_subtitle.position + container_offset);
+               pi->set_subtitle (_out_subtitle.image, _out_subtitle.position + container_offset);
        }
                                            
 #ifdef DCPOMATIC_DEBUG
@@ -561,7 +561,7 @@ Player::update_subtitle ()
        }
 
        if (!_in_subtitle.subtitle->image) {
-               _out_subtitle.subtitle->image.reset ();
+               _out_subtitle.image.reset ();
                return;
        }
 
@@ -591,16 +591,16 @@ 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.subtitle->image = _in_subtitle.subtitle->image->scale (
+
+       _out_subtitle.image = _in_subtitle.subtitle->image->scale (
                scaled_size,
                Scaler::from_id ("bicubic"),
-               _in_subtitle.subtitle->image->pixel_format (),
+               PIX_FMT_RGBA,
                true
                );
-       
-       _out_subtitle.subtitle->dcp_time = _in_subtitle.subtitle->dcp_time;
-       _out_subtitle.subtitle->dcp_time = _in_subtitle.subtitle->dcp_time;
+
+       _out_subtitle.from = _in_subtitle.subtitle->dcp_time;
+       _out_subtitle.to = _in_subtitle.subtitle->dcp_time_to;
 }
 
 /** Re-emit the last frame that was emitted, using current settings for crop, ratio, scaler and subtitles.
index b4454b859d858e6d3736052c899c6c2f8f4114a0..ffc9cf3e3c3a1ecacc465d223a1a78d5ab9bcae1 100644 (file)
@@ -148,7 +148,9 @@ private:
 
        struct {
                Position<int> position;
-               boost::shared_ptr<DecodedSubtitle> subtitle;
+               boost::shared_ptr<Image> image;
+               DCPTime from;
+               DCPTime to;
        } _out_subtitle;
 
 #ifdef DCPOMATIC_DEBUG
index 389e4b13a18e0d106808927ae102028150a70cea..7ba969933d077717ed125546657767d8fcc1aeda 100644 (file)
@@ -34,7 +34,7 @@ SubtitleDecoder::SubtitleDecoder (shared_ptr<const Film> f)
  *  Image may be 0 to say that there is no current subtitle.
  */
 void
-SubtitleDecoder::subtitle (shared_ptr<Image> image, dcpomatic::Rect<double> rect, DCPTime from, DCPTime to)
+SubtitleDecoder::subtitle (shared_ptr<Image> image, dcpomatic::Rect<double> rect, ContentTime from, ContentTime to)
 {
        _pending.push_back (shared_ptr<DecodedSubtitle> (new DecodedSubtitle (image, rect, from, to)));
 }
index 4836e31fa980af02589b330eadddbddb8b45b16d..fd1d71f33fdef23b3ef8ed7b5d69140baa4ed2cb 100644 (file)
@@ -33,5 +33,5 @@ public:
        SubtitleDecoder (boost::shared_ptr<const Film>);
 
 protected:
-       void subtitle (boost::shared_ptr<Image>, dcpomatic::Rect<double>, DCPTime, DCPTime);
+       void subtitle (boost::shared_ptr<Image>, dcpomatic::Rect<double>, ContentTime, ContentTime);
 };
index 1503af955f7df8de4b6058038fac3142347c7b53..6a16557cdc65e8aac476eeb290a1f5b3c48d8c32 100644 (file)
@@ -51,8 +51,8 @@ VideoDecoder::video (shared_ptr<const Image> image, bool same, ContentTime time)
        case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
        {
                int const half = image->size().height / 2;
-               Video (image->crop (Crop (0, 0, 0, half), true), EYES_LEFT, same, frame);
-               Video (image->crop (Crop (0, 0, half, 0), true), EYES_RIGHT, same, frame);
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image->crop (Crop (0, 0, 0, half), true), EYES_LEFT, same, time)));
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image->crop (Crop (0, 0, half, 0), true), EYES_RIGHT, same, time)));
                break;
        }
        }