From f6db7b68932616e7192ec45d3510c8329a295852 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 30 Aug 2019 19:38:09 +1000 Subject: [PATCH] implemented alpha dis/re/assoc functions for offline pathway --- app/common/define.h | 1 + app/node/input/media/media.cpp | 17 ++++---- app/render/colorservice.cpp | 72 ++++++++++++++++++++++++++++++++-- app/render/colorservice.h | 17 ++++++++ app/widget/viewer/viewer.cpp | 2 +- 5 files changed, 97 insertions(+), 12 deletions(-) diff --git a/app/common/define.h b/app/common/define.h index 37ff4cc5d..967a5e878 100644 --- a/app/common/define.h +++ b/app/common/define.h @@ -21,6 +21,7 @@ #ifndef OLIVECOMMONDEFINE_H #define OLIVECOMMONDEFINE_H +const int kRGBChannels = 3; const int kRGBAChannels = 4; #endif // OLIVECOMMONDEFINE_H diff --git a/app/node/input/media/media.cpp b/app/node/input/media/media.cpp index f2d0981c0..b549ed639 100644 --- a/app/node/input/media/media.cpp +++ b/app/node/input/media/media.cpp @@ -23,15 +23,12 @@ #include #include -#include "project/item/footage/footage.h" - -// FIXME: Test code only #include "decoder/ffmpeg/ffmpegdecoder.h" #include "node/processor/renderer/renderer.h" +#include "project/item/footage/footage.h" #include "render/pixelservice.h" #include "render/gl/shadergenerators.h" #include "render/gl/functions.h" -// End test code MediaInput::MediaInput() : decoder_(nullptr), @@ -102,6 +99,7 @@ void MediaInput::SetFootage(Footage *f) QVariant MediaInput::Value(NodeOutput *output, const rational &time) { + // FIXME: Hardcoded value bool alpha_is_associated = false; if (output == texture_output_) { @@ -142,7 +140,7 @@ QVariant MediaInput::Value(NodeOutput *output, const rational &time) } if (color_service_ == nullptr) { - // FIXME: Hardcoded values for texting + // FIXME: Hardcoded values for testing color_service_ = std::make_shared("srgb", OCIO::ROLE_SCENE_LINEAR); } @@ -154,16 +152,19 @@ QVariant MediaInput::Value(NodeOutput *output, const rational &time) frame = PixelService::ConvertPixelFormat(frame, olive::PIX_FMT_RGBA32F); if (alpha_is_associated) { - // FIXME: Unassociate alpha here if associated + // Unassociate alpha here if associated + ColorService::DisassociateAlpha(frame); } // Transform color to reference space color_service_->ConvertFrame(frame); if (alpha_is_associated) { - // FIXME: Reassociate alpha here + // If alpha was associated, reassociate here + ColorService::ReassociateAlpha(frame); } else { - // FIXME: Associate alpha here + // If alpha was not associated, associate here + ColorService::AssociateAlpha(frame); } } diff --git a/app/render/colorservice.cpp b/app/render/colorservice.cpp index 0df81d32c..d2e23b1d3 100644 --- a/app/render/colorservice.cpp +++ b/app/render/colorservice.cpp @@ -1,5 +1,7 @@ #include "colorservice.h" +#include + #include "common/define.h" ColorService::ColorService(const char* source_space, const char* dest_space) @@ -12,10 +14,14 @@ ColorService::ColorService(const char* source_space, const char* dest_space) void ColorService::Init() { - // FIXME: Hardcoded values for testing purposes - OCIO::ConstConfigRcPtr config = OCIO::Config::CreateFromFile("/run/media/matt/Home/OpenColorIO/ocio.configs.0.7v4/nuke-default/config.ocio"); + try { + // FIXME: Hardcoded values for testing purposes + OCIO::ConstConfigRcPtr config = OCIO::Config::CreateFromFile("/run/media/matt/Home/OpenColorIO/ocio.configs.0.7v4/nuke-default/config.ocio"); - OCIO::SetCurrentConfig(config); + OCIO::SetCurrentConfig(config); + } catch (OCIO::Exception& exception) { + qWarning() << "OpenColorIO Error:" << exception.what(); + } } ColorServicePtr ColorService::Create(const char *source_space, const char *dest_space) @@ -30,7 +36,67 @@ void ColorService::ConvertFrame(FramePtr f) processor->apply(img); } +void ColorService::DisassociateAlpha(FramePtr f) +{ + AssociateAlphaPixFmtFilter(kDisassociate, f); +} + +void ColorService::AssociateAlpha(FramePtr f) +{ + AssociateAlphaPixFmtFilter(kAssociate, f); +} + +void ColorService::ReassociateAlpha(FramePtr f) +{ + AssociateAlphaPixFmtFilter(kReassociate, f); +} + OpenColorIO::v1::ConstProcessorRcPtr ColorService::GetProcessor() { return processor; } + +void ColorService::AssociateAlphaPixFmtFilter(ColorService::AlphaAction action, FramePtr f) +{ + int pixel_count = f->width() * f->height() * kRGBAChannels; + + switch (static_cast(f->format())) { + case olive::PIX_FMT_INVALID: + case olive::PIX_FMT_COUNT: + qWarning() << "Alpha association functions received an invalid pixel format"; + break; + case olive::PIX_FMT_RGBA8: + case olive::PIX_FMT_RGBA16: + qWarning() << "Alpha association functions only works on float-based pixel formats at this time"; + break; + case olive::PIX_FMT_RGBA16F: + { + AssociateAlphaInternal(action, reinterpret_cast(f->data()), pixel_count); + break; + } + case olive::PIX_FMT_RGBA32F: + { + AssociateAlphaInternal(action, reinterpret_cast(f->data()), pixel_count); + break; + } + } +} + +template +void ColorService::AssociateAlphaInternal(ColorService::AlphaAction action, T *data, int pix_count) +{ + for (int i=0;i + static void AssociateAlphaInternal(AlphaAction action, T* data, int pix_count); }; #endif // COLORSERVICE_H diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 1e7af8d03..446c79dc8 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -41,7 +41,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) : sizer->SetWidget(gl_widget_); // FIXME: Hardcoded values - sizer->SetSize(1920, 1080); + sizer->SetChildSize(1920, 1080); // Create time ruler ruler_ = new TimeRuler(false, this);