implemented alpha dis/re/assoc functions for offline pathway
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user