From c127bebae4661b15ccfb3b3f20cfa122c5d18eff Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 23 Jul 2021 17:08:42 -0700 Subject: [PATCH] renderer/viewer: more flexibility regarding alpha association --- app/render/renderer.cpp | 26 ++++++------------------ app/render/renderer.h | 18 ++++++++-------- app/render/renderprocessor.cpp | 14 +++++++++++-- app/widget/scope/scopebase/scopebase.cpp | 2 +- app/widget/viewer/viewerdisplay.cpp | 2 +- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/app/render/renderer.cpp b/app/render/renderer.cpp index 3cc41aa2e..a27553fae 100644 --- a/app/render/renderer.cpp +++ b/app/render/renderer.cpp @@ -52,14 +52,14 @@ TexturePtr Renderer::CreateTexture(const VideoParams ¶ms, const void *data, return CreateTexture(params, Texture::k2D, data, linesize); } -void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, Texture *destination, bool clear_destination, const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix) +void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, Texture *destination, bool clear_destination, const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix) { - BlitColorManagedInternal(color_processor, source, source_is_premultiplied, destination, destination->params(), clear_destination, matrix, crop_matrix); + BlitColorManagedInternal(color_processor, source, source_alpha_association, destination, destination->params(), clear_destination, matrix, crop_matrix); } -void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, VideoParams params, bool clear_destination, const QMatrix4x4& matrix, const QMatrix4x4 &crop_matrix) +void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, VideoParams params, bool clear_destination, const QMatrix4x4& matrix, const QMatrix4x4 &crop_matrix) { - BlitColorManagedInternal(color_processor, source, source_is_premultiplied, nullptr, params, clear_destination, matrix, crop_matrix); + BlitColorManagedInternal(color_processor, source, source_alpha_association, nullptr, params, clear_destination, matrix, crop_matrix); } TexturePtr Renderer::InterlaceTexture(TexturePtr top, TexturePtr bottom, const VideoParams ¶ms) @@ -257,7 +257,7 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo } void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source, - bool source_is_premultiplied, Texture *destination, + AlphaAssociated source_alpha_association, Texture *destination, VideoParams params, bool clear_destination, const QMatrix4x4& matrix, const QMatrix4x4& crop_matrix) { @@ -271,21 +271,7 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(source))); job.InsertValue(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, matrix)); job.InsertValue(QStringLiteral("ove_cropmatrix"), NodeValue(NodeValue::kMatrix, crop_matrix.inverted())); - - AlphaAssociated associated; - if (source->channel_count() == VideoParams::kRGBAChannelCount) { - if (source_is_premultiplied) { - // De-assoc/re-assoc required for color management - associated = kAlphaAssociated; - } else { - // Just assoc at the end - associated = kAlphaUnassociated; - } - } else { - // No assoc/deassoc required - associated = kAlphaNone; - } - job.InsertValue(QStringLiteral("ove_maintex_alpha"), NodeValue(NodeValue::kInt, associated)); + job.InsertValue(QStringLiteral("ove_maintex_alpha"), NodeValue(NodeValue::kInt, source_alpha_association)); foreach (const ColorContext::LUT& l, color_ctx.lut3d_textures) { job.InsertValue(l.name, NodeValue(NodeValue::kTexture, QVariant::fromValue(l.texture))); diff --git a/app/render/renderer.h b/app/render/renderer.h index 628212c13..977fc98ce 100644 --- a/app/render/renderer.h +++ b/app/render/renderer.h @@ -63,8 +63,14 @@ public: Blit(shader, job, nullptr, params, clear_destination); } - void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, Texture* destination, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4()); - void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, VideoParams params, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4()); + enum AlphaAssociated { + kAlphaNone, + kAlphaUnassociated, + kAlphaAssociated + }; + + void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, Texture* destination, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4()); + void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, VideoParams params, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4()); TexturePtr InterlaceTexture(TexturePtr top, TexturePtr bottom, const VideoParams ¶ms); @@ -120,16 +126,10 @@ private: }; - enum AlphaAssociated { - kAlphaNone, - kAlphaUnassociated, - kAlphaAssociated - }; - bool GetColorContext(ColorProcessorPtr color_processor, ColorContext* ctx); void BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source, - bool source_is_premultiplied, + AlphaAssociated source_alpha_association, Texture* destination, VideoParams params, bool clear_destination, const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix); diff --git a/app/render/renderprocessor.cpp b/app/render/renderprocessor.cpp index 47c981263..34a1b8760 100644 --- a/app/render/renderprocessor.cpp +++ b/app/render/renderprocessor.cpp @@ -95,7 +95,7 @@ FramePtr RenderProcessor::GenerateFrame(TexturePtr texture, const rational& time if (output_color_transform) { // Yes color transform, blit color managed - render_ctx_->BlitColorManaged(output_color_transform, texture, true, blit_tex.get(), true, matrix); + render_ctx_->BlitColorManaged(output_color_transform, texture, Renderer::kAlphaAssociated, blit_tex.get(), true, matrix); } else { // No color transform, just blit ShaderJob job; @@ -439,8 +439,18 @@ QVariant RenderProcessor::ProcessVideoFootage(const FootageJob &stream, const ra using_colorspace, color_manager->GetReferenceColorSpace()); + Renderer::AlphaAssociated alpha_assoc; + if (stream_data.channel_count() != VideoParams::kRGBAChannelCount + || stream_data.colorspace() == color_manager->GetReferenceColorSpace()) { + alpha_assoc = Renderer::kAlphaNone; + } else if (stream_data.premultiplied_alpha()) { + alpha_assoc = Renderer::kAlphaAssociated; + } else { + alpha_assoc = Renderer::kAlphaUnassociated; + } + render_ctx_->BlitColorManaged(processor, unmanaged_texture, - stream_data.premultiplied_alpha(), + alpha_assoc, value.get()); still_image_cache_->mutex()->lock(); diff --git a/app/widget/scope/scopebase/scopebase.cpp b/app/widget/scope/scopebase/scopebase.cpp index 2e6875872..8e6074e74 100644 --- a/app/widget/scope/scopebase/scopebase.cpp +++ b/app/widget/scope/scopebase/scopebase.cpp @@ -74,7 +74,7 @@ void ScopeBase::OnPaint() if (!managed_tex_ || !managed_tex_up_to_date_ || managed_tex_->params() != texture_->params()) { managed_tex_ = renderer()->CreateTexture(texture_->params()); - renderer()->BlitColorManaged(color_service(), texture_, true, managed_tex_.get()); + renderer()->BlitColorManaged(color_service(), texture_, Renderer::kAlphaNone, managed_tex_.get()); } DrawScope(managed_tex_, pipeline_); diff --git a/app/widget/viewer/viewerdisplay.cpp b/app/widget/viewer/viewerdisplay.cpp index 46ab98c55..3bae651b8 100644 --- a/app/widget/viewer/viewerdisplay.cpp +++ b/app/widget/viewer/viewerdisplay.cpp @@ -390,7 +390,7 @@ void ViewerDisplayWidget::OnPaint() texture_to_draw = deinterlace_texture_; } - renderer()->BlitColorManaged(color_service(), texture_to_draw, true, device_params, false, + renderer()->BlitColorManaged(color_service(), texture_to_draw, Renderer::kAlphaNone, device_params, false, combined_matrix_flipped_, crop_matrix_); } }