implemented conversions between internal pixel formats
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
// FIXME: Test code only
|
||||
#include "decoder/ffmpeg/ffmpegdecoder.h"
|
||||
#include "render/colorservice.h"
|
||||
#include "render/pixelservice.h"
|
||||
// End test code
|
||||
|
||||
@@ -112,6 +113,10 @@ void MediaInput::Process(const rational &time)
|
||||
return;
|
||||
}
|
||||
|
||||
// Use OCIO
|
||||
frame = PixelService::ConvertPixelFormat(frame, olive::PIX_FMT_RGBA32F);
|
||||
ColorService::ConvertFrame(frame);
|
||||
|
||||
// FIXME: Test code
|
||||
if (tex_buf_.IsCreated()) {
|
||||
tex_buf_.Upload(frame->data());
|
||||
|
||||
@@ -18,6 +18,8 @@ add_subdirectory(gl)
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
render/colorservice.h
|
||||
render/colorservice.cpp
|
||||
#render/imagecache.h
|
||||
#render/imagecache.cpp
|
||||
#render/memorybuffer.h
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "colorservice.h"
|
||||
|
||||
const int kRGBAChannels = 4;
|
||||
|
||||
ColorService::ColorService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ColorService::ConvertFrame(FramePtr f)
|
||||
{
|
||||
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
|
||||
|
||||
OCIO::ConstProcessorRcPtr processor = config->getProcessor("srgb",
|
||||
OCIO::ROLE_SCENE_LINEAR);
|
||||
|
||||
OCIO::PackedImageDesc img(reinterpret_cast<float*>(f->data()), f->width(), f->height(), kRGBAChannels);
|
||||
|
||||
processor->apply(img);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef COLORSERVICE_H
|
||||
#define COLORSERVICE_H
|
||||
|
||||
#include <OpenColorIO/OpenColorIO.h>
|
||||
namespace OCIO = OCIO_NAMESPACE;
|
||||
|
||||
#include "decoder/frame.h"
|
||||
|
||||
class ColorService
|
||||
{
|
||||
public:
|
||||
ColorService();
|
||||
|
||||
static void ConvertFrame(FramePtr f);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // COLORSERVICE_H
|
||||
@@ -21,9 +21,13 @@
|
||||
#include "pixelservice.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QFloat16>
|
||||
|
||||
const int kRGBAChannels = 4;
|
||||
|
||||
PixelService olive::pixel_service;
|
||||
|
||||
PixelService::PixelService()
|
||||
{
|
||||
}
|
||||
@@ -87,3 +91,180 @@ int PixelService::BytesPerChannel(const olive::PixelFormat &format)
|
||||
qFatal("Invalid pixel format requested");
|
||||
}
|
||||
}
|
||||
|
||||
FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelFormat &dest_format)
|
||||
{
|
||||
if (frame->format() == dest_format) {
|
||||
return frame;
|
||||
}
|
||||
|
||||
FramePtr converted = std::make_shared<Frame>();
|
||||
|
||||
// Copy parameters
|
||||
converted->set_width(frame->width());
|
||||
converted->set_height(frame->height());
|
||||
converted->set_timestamp(frame->timestamp());
|
||||
converted->set_format(dest_format);
|
||||
converted->allocate();
|
||||
|
||||
int pix_count = frame->width() * frame->height() * kRGBAChannels;
|
||||
|
||||
bool valid = true;
|
||||
|
||||
switch (static_cast<olive::PixelFormat>(frame->format())) {
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
{
|
||||
uint8_t* source = frame->data();
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA16: // 8-bit Integer -> 16-bit Integer
|
||||
{
|
||||
uint16_t* destination = reinterpret_cast<uint16_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = static_cast<uint16_t>(source[i] * 257);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F: // 8-bit Integer -> 16-bit Float
|
||||
{
|
||||
qfloat16* destination = reinterpret_cast<qfloat16*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = source[i] / 255.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F: // 8-bit Integer -> 32-bit Float
|
||||
{
|
||||
float* destination = reinterpret_cast<float*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = source[i] / 255.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16:
|
||||
{
|
||||
uint16_t* source = reinterpret_cast<uint16_t*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8: // 16-bit Integer -> 8-bit Integer
|
||||
{
|
||||
uint8_t* destination = converted->data();
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = static_cast<uint8_t>(source[i] / 257);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F: // 16-bit Integer -> 16-bit Integer
|
||||
{
|
||||
qfloat16* destination = reinterpret_cast<qfloat16*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = source[i] / 65535.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F: // 16-bit Integer -> 16-bit Integer
|
||||
{
|
||||
float* destination = reinterpret_cast<float*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = source[i] / 65535.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA16:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
{
|
||||
qfloat16* source = reinterpret_cast<qfloat16*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8: // 16-bit Float -> 8-bit Integer
|
||||
{
|
||||
uint8_t* destination = converted->data();
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = static_cast<uint8_t>(source[i] * 255.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16: // 16-bit Float -> 16-bit Integer
|
||||
{
|
||||
uint16_t* destination = reinterpret_cast<uint16_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = static_cast<uint16_t>(source[i] * 65535.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F: // 16-bit Float -> 32-bit Float
|
||||
{
|
||||
float* destination = reinterpret_cast<float*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = source[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
{
|
||||
float* source = reinterpret_cast<float*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8: // 32-bit Float -> 8-bit Integer
|
||||
{
|
||||
uint8_t* destination = converted->data();
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = static_cast<uint8_t>(source[i] * 255.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16: // 32-bit Float -> 16-bit Integer
|
||||
{
|
||||
uint16_t* destination = reinterpret_cast<uint16_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = static_cast<uint16_t>(source[i] * 255.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F: // 32-bit Float -> 16-bit Float
|
||||
{
|
||||
qfloat16* destination = reinterpret_cast<qfloat16*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
destination[i] = source[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
return converted;
|
||||
}
|
||||
|
||||
qWarning() << tr("Invalid parameters called for pixel format conversion");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QString>
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
#include "decoder/frame.h"
|
||||
#include "pixelformat.h"
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,13 @@ public:
|
||||
*/
|
||||
static int BytesPerChannel(const olive::PixelFormat& format);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Convert a frame to a pixel format
|
||||
*
|
||||
* If the frame's pixel format == the destination format, this just returns `frame`.
|
||||
*/
|
||||
static FramePtr ConvertPixelFormat(FramePtr frame, const olive::PixelFormat &dest_format);
|
||||
|
||||
};
|
||||
|
||||
#endif // PIXELSERVICE_H
|
||||
|
||||
Reference in New Issue
Block a user