Add has_alpha() flag to VideoContent.
authorCarl Hetherington <cth@carlh.net>
Sat, 12 Apr 2025 09:32:55 +0000 (11:32 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 12 Apr 2025 09:32:55 +0000 (11:32 +0200)
src/lib/dcp_examiner.h
src/lib/ffmpeg_examiner.h
src/lib/image_examiner.cc
src/lib/image_examiner.h
src/lib/video_content.cc
src/lib/video_content.h
src/lib/video_examiner.h
src/lib/video_mxf_examiner.h

index 381afdaed0d3546291f7599e8000431fa3b4709d..ca3cae76ed85a24cbfb27fc45e57759d2c6eaee9 100644 (file)
@@ -68,6 +68,10 @@ public:
                return {};
        }
 
+       bool has_alpha() const override {
+               return false;
+       }
+
        std::string name() const {
                return _name;
        }
index ad64f349d81f950590362b8c095a10880977b3f9..c85a76d40d5df61b1e754d32a6cf219c9f79fd42 100644 (file)
@@ -59,6 +59,8 @@ public:
 
        PixelQuanta pixel_quanta () const override;
 
+       bool has_alpha() const override;
+
        AVColorRange color_range () const {
                return video_codec_context()->color_range;
        }
@@ -77,7 +79,6 @@ public:
 
        boost::optional<int> bits_per_pixel () const;
 
-       bool has_alpha() const;
 
        boost::optional<double> rotation () const {
                return _rotation;
index 15a0b043d56543c8451cfd243c27204afc336f16..16258aed5919436da3eab8ea796b084733a324fa 100644 (file)
@@ -66,7 +66,9 @@ ImageExaminer::ImageExaminer (shared_ptr<const Film> film, shared_ptr<const Imag
                }
        } else {
                FFmpegImageProxy proxy(content->path(0));
-               _video_size = proxy.image(Image::Alignment::COMPACT).image->size();
+               auto image = proxy.image(Image::Alignment::COMPACT);
+               _video_size = image.image->size();
+               _has_alpha = image.image->has_alpha();
        }
 
        if (content->still ()) {
index 54fca7ed1c2e6ce10efe02d04877bec6e0424f4e..d6cdfac53961fb81892cb923fe07eb72928ae375 100644 (file)
@@ -43,10 +43,14 @@ public:
                /* See ::yuv - we're assuming the image is not YUV and so not subsampled */
                return {};
        }
+       bool has_alpha() const override {
+               return _has_alpha;
+       }
 
 private:
        std::weak_ptr<const Film> _film;
        std::shared_ptr<const ImageContent> _image_content;
        boost::optional<dcp::Size> _video_size;
        Frame _video_length;
+       bool _has_alpha = false;
 };
index 4203d6640373f9313d3ef40a1dfff5725dd19994..a5f65de24845d60e718763eb79aa6ac9dd4feeb9 100644 (file)
@@ -199,6 +199,7 @@ VideoContent::VideoContent(Content* parent, cxml::ConstNodePtr node, int version
                _burnt_subtitle_language = dcp::LanguageTag(*burnt);
        }
 
+       _has_alpha = node->optional_bool_child("HasAlpha").get_value_or(false);
 }
 
 
@@ -255,6 +256,7 @@ VideoContent::VideoContent(Content* parent, vector<shared_ptr<Content> > c)
                }
 
                _pixel_quanta = max(_pixel_quanta, c[i]->video->_pixel_quanta);
+               _has_alpha = _has_alpha | c[i]->video->_has_alpha;
        }
 
        _use = ref->use();
@@ -303,6 +305,7 @@ VideoContent::as_xml(xmlpp::Element* element) const
        if (_burnt_subtitle_language) {
                cxml::add_text_child(element, "BurntSubtitleLanguage", _burnt_subtitle_language->as_string());
        }
+       cxml::add_text_child(element, "HasAlpha", _has_alpha ? "1" : "0");
 }
 
 void
@@ -315,6 +318,7 @@ VideoContent::take_from_examiner(shared_ptr<const Film> film, shared_ptr<VideoEx
        auto const yuv = d->yuv();
        auto const range = d->range();
        auto const pixel_quanta = d->pixel_quanta();
+       auto const has_alpha = d->has_alpha();
 
        ContentChangeSignaller cc1(_parent, VideoContentProperty::SIZE);
        ContentChangeSignaller cc2(_parent, ContentProperty::LENGTH);
@@ -328,6 +332,7 @@ VideoContent::take_from_examiner(shared_ptr<const Film> film, shared_ptr<VideoEx
                _yuv = yuv;
                _range = range;
                _pixel_quanta = pixel_quanta;
+               _has_alpha = has_alpha;
        }
 
        LOG_GENERAL("Video length obtained from header as %1 frames", _length);
index c6fce70d55d78e979bf11d9ed5812e2dcb6514be..db46f06ebe7cdc4789d1c9b6f129d458540b061c 100644 (file)
@@ -192,6 +192,11 @@ public:
                return _pixel_quanta;
        }
 
+       bool has_alpha() const {
+               boost::mutex::scoped_lock lm(_mutex);
+               return _has_alpha;
+       }
+
        bool use() const {
                boost::mutex::scoped_lock lm(_mutex);
                return _use;
@@ -261,6 +266,7 @@ private:
        VideoRange _range;
        PixelQuanta _pixel_quanta;
        boost::optional<dcp::LanguageTag> _burnt_subtitle_language;
+       bool _has_alpha = false;
 };
 
 
index 471537f7a63399b8845ae7e160427586bfd5f5f2..e13241885a12c9ab1f26ac1258df7229a603384b 100644 (file)
@@ -53,4 +53,5 @@ public:
        virtual bool yuv() const = 0;
        virtual VideoRange range() const = 0;
        virtual PixelQuanta pixel_quanta() const = 0;
+       virtual bool has_alpha() const = 0;
 };
index e4cd98f0730681c7df7a60065e3985d4af80eea8..2dad09c089fec887a51f0ed831d22b15b2f6b09c 100644 (file)
@@ -45,6 +45,9 @@ public:
        PixelQuanta pixel_quanta () const override {
                return {};
        }
+       bool has_alpha() const override {
+               return false;
+       }
 
 private:
        std::shared_ptr<dcp::PictureAsset> _asset;