implemented alpha dis/re/assoc functions for offline pathway
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#ifndef OLIVECOMMONDEFINE_H
|
||||
#define OLIVECOMMONDEFINE_H
|
||||
|
||||
const int kRGBChannels = 3;
|
||||
const int kRGBAChannels = 4;
|
||||
|
||||
#endif // OLIVECOMMONDEFINE_H
|
||||
|
||||
@@ -23,15 +23,12 @@
|
||||
#include <QDebug>
|
||||
#include <QOpenGLPixelTransferOptions>
|
||||
|
||||
#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<ColorService>("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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "colorservice.h"
|
||||
|
||||
#include <QFloat16>
|
||||
|
||||
#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<olive::PixelFormat>(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<qfloat16>(action, reinterpret_cast<qfloat16*>(f->data()), pixel_count);
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
{
|
||||
AssociateAlphaInternal<float>(action, reinterpret_cast<float*>(f->data()), pixel_count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ColorService::AssociateAlphaInternal(ColorService::AlphaAction action, T *data, int pix_count)
|
||||
{
|
||||
for (int i=0;i<pix_count;i+=kRGBAChannels) {
|
||||
T alpha = data[i+kRGBChannels];
|
||||
|
||||
// FIXME: Is qIsNull the correct approach here or should it literally be an != 0?
|
||||
if (action == kAssociate || !qIsNull(alpha)) {
|
||||
for (int j=0;j<kRGBChannels;j++) {
|
||||
if (action == kDisassociate) {
|
||||
data[i+j] /= alpha;
|
||||
} else {
|
||||
data[i+j] *= alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,27 @@ public:
|
||||
|
||||
void ConvertFrame(FramePtr f);
|
||||
|
||||
static void DisassociateAlpha(FramePtr f);
|
||||
|
||||
static void AssociateAlpha(FramePtr f);
|
||||
|
||||
static void ReassociateAlpha(FramePtr f);
|
||||
|
||||
OCIO::ConstProcessorRcPtr GetProcessor();
|
||||
|
||||
private:
|
||||
OCIO::ConstProcessorRcPtr processor;
|
||||
|
||||
enum AlphaAction {
|
||||
kAssociate,
|
||||
kDisassociate,
|
||||
kReassociate
|
||||
};
|
||||
|
||||
static void AssociateAlphaPixFmtFilter(AlphaAction action, FramePtr f);
|
||||
|
||||
template<typename T>
|
||||
static void AssociateAlphaInternal(AlphaAction action, T* data, int pix_count);
|
||||
};
|
||||
|
||||
#endif // COLORSERVICE_H
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user