various small code cleanups and improvements
Largely refactoring work to make the code somewhat nicer to work with.
This commit is contained in:
@@ -117,8 +117,8 @@ void Exporter::FrameRendered(const rational &time, QVariant value)
|
||||
FramePtr frame = TextureToFrame(value);
|
||||
|
||||
// OCIO conversion requires a frame in 32F format
|
||||
if (frame->format() != olive::PIX_FMT_RGBA32F) {
|
||||
frame = PixelService::ConvertPixelFormat(frame, olive::PIX_FMT_RGBA32F);
|
||||
if (frame->format() != PixelFormat::PIX_FMT_RGBA32F) {
|
||||
frame = PixelService::ConvertPixelFormat(frame, PixelFormat::PIX_FMT_RGBA32F);
|
||||
}
|
||||
|
||||
// Color conversion must be done with unassociated alpha, and the pipeline is always associated
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
render/backend/opengl/functions.h
|
||||
render/backend/opengl/functions.cpp
|
||||
render/backend/opengl/openglbackend.h
|
||||
render/backend/opengl/openglbackend.cpp
|
||||
render/backend/opengl/openglcolorprocessor.h
|
||||
@@ -26,6 +24,8 @@ set(OLIVE_SOURCES
|
||||
render/backend/opengl/openglexporter.cpp
|
||||
render/backend/opengl/openglframebuffer.h
|
||||
render/backend/opengl/openglframebuffer.cpp
|
||||
render/backend/opengl/openglrenderfunctions.h
|
||||
render/backend/opengl/openglrenderfunctions.cpp
|
||||
render/backend/opengl/openglshader.h
|
||||
render/backend/opengl/openglshader.cpp
|
||||
render/backend/opengl/openglshadercache.h
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <QEventLoop>
|
||||
#include <QThread>
|
||||
|
||||
#include "functions.h"
|
||||
#include "openglrenderfunctions.h"
|
||||
|
||||
OpenGLBackend::OpenGLBackend(QObject *parent) :
|
||||
VideoRenderBackend(parent),
|
||||
@@ -168,7 +168,7 @@ OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input)
|
||||
copy_buffer_.Bind();
|
||||
input->Bind();
|
||||
|
||||
olive::gl::Blit(copy_pipeline_);
|
||||
OpenGLRenderFunctions::Blit(copy_pipeline_);
|
||||
|
||||
input->Release();
|
||||
copy_buffer_.Release();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFunctions>
|
||||
|
||||
#include "functions.h"
|
||||
#include "openglrenderfunctions.h"
|
||||
|
||||
void OpenGLColorProcessor::Enable(QOpenGLContext *context, bool alpha_is_associated)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ OpenGLShaderPtr OpenGLColorProcessor::pipeline() const
|
||||
|
||||
void OpenGLColorProcessor::ProcessOpenGL()
|
||||
{
|
||||
olive::gl::OCIOBlit(pipeline_, ocio_lut_);
|
||||
OpenGLRenderFunctions::OCIOBlit(pipeline_, ocio_lut_);
|
||||
}
|
||||
|
||||
OpenGLColorProcessor::OpenGLColorProcessor(OCIO::ConstConfigRcPtr config, const QString &source_space, const QString &dest_space) :
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "openglexporter.h"
|
||||
|
||||
#include "render/backend/opengl/functions.h"
|
||||
#include "render/backend/opengl/openglrenderfunctions.h"
|
||||
#include "render/pixelservice.h"
|
||||
|
||||
OpenGLExporter::OpenGLExporter(ViewerOutput* viewer, const VideoRenderingParams& video_params, const AudioRenderingParams &audio_params, const QMatrix4x4 &transform, ColorProcessorPtr color_processor, Encoder *encoder, QObject* parent) :
|
||||
@@ -55,7 +55,7 @@ FramePtr OpenGLExporter::TextureToFrame(const QVariant& texture)
|
||||
buffer_.Bind();
|
||||
input_tex->Bind();
|
||||
|
||||
olive::gl::Blit(pipeline_, false, transform_);
|
||||
OpenGLRenderFunctions::Blit(pipeline_, false, transform_);
|
||||
|
||||
input_tex->Release();
|
||||
buffer_.Release();
|
||||
@@ -65,7 +65,7 @@ FramePtr OpenGLExporter::TextureToFrame(const QVariant& texture)
|
||||
buffer_.Attach(texture_);
|
||||
buffer_.Bind();
|
||||
|
||||
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(video_params_.format());
|
||||
PixelFormat::Info format_info = PixelService::GetPixelFormatInfo(video_params_.format());
|
||||
|
||||
f->glReadPixels(0,
|
||||
0,
|
||||
|
||||
+5
-5
@@ -18,7 +18,7 @@
|
||||
|
||||
***/
|
||||
|
||||
#include "functions.h"
|
||||
#include "openglrenderfunctions.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QOpenGLVertexArrayObject>
|
||||
@@ -63,7 +63,7 @@ const GLfloat flipped_blit_texcoords[] = {
|
||||
*
|
||||
* Currently active QOpenGLFunctions object (use context()->functions() if unsure).
|
||||
*/
|
||||
void olive::gl::PrepareToDraw(QOpenGLFunctions* f) {
|
||||
void OpenGLRenderFunctions::PrepareToDraw(QOpenGLFunctions* f) {
|
||||
f->glGenerateMipmap(GL_TEXTURE_2D);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
@@ -71,7 +71,7 @@ void olive::gl::PrepareToDraw(QOpenGLFunctions* f) {
|
||||
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
void olive::gl::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix4x4 matrix) {
|
||||
void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix4x4 matrix) {
|
||||
// FIXME: is currentContext() reliable here?
|
||||
QOpenGLFunctions* func = QOpenGLContext::currentContext()->functions();
|
||||
|
||||
@@ -123,7 +123,7 @@ void olive::gl::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix4x4 matrix)
|
||||
func->glFinish();
|
||||
}
|
||||
|
||||
void olive::gl::OCIOBlit(OpenGLShaderPtr pipeline,
|
||||
void OpenGLRenderFunctions::OCIOBlit(OpenGLShaderPtr pipeline,
|
||||
GLuint lut,
|
||||
bool flipped,
|
||||
QMatrix4x4 matrix)
|
||||
@@ -139,7 +139,7 @@ void olive::gl::OCIOBlit(OpenGLShaderPtr pipeline,
|
||||
|
||||
pipeline->setUniformValue("ove_ociolut", 2);
|
||||
|
||||
olive::gl::Blit(pipeline, flipped, matrix);
|
||||
OpenGLRenderFunctions::Blit(pipeline, flipped, matrix);
|
||||
|
||||
pipeline->release();
|
||||
|
||||
+21
-24
@@ -26,31 +26,28 @@
|
||||
|
||||
#include "openglshader.h"
|
||||
|
||||
namespace olive {
|
||||
namespace gl {
|
||||
class OpenGLRenderFunctions {
|
||||
public:
|
||||
/**
|
||||
* @brief Draw texture on screen
|
||||
*
|
||||
* @param pipeline
|
||||
*
|
||||
* Shader to use for the texture drawing
|
||||
*
|
||||
* @param flipped
|
||||
*
|
||||
* Draw the texture vertically flipped (defaults to FALSE)
|
||||
*
|
||||
* @param matrix
|
||||
*
|
||||
* Transformation matrix to use when drawing (defaults to no transform)
|
||||
*/
|
||||
static void Blit(OpenGLShaderPtr pipeline, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
|
||||
|
||||
/**
|
||||
* @brief Draw texture on screen
|
||||
*
|
||||
* @param pipeline
|
||||
*
|
||||
* Shader to use for the texture drawing
|
||||
*
|
||||
* @param flipped
|
||||
*
|
||||
* Draw the texture vertically flipped (defaults to FALSE)
|
||||
*
|
||||
* @param matrix
|
||||
*
|
||||
* Transformation matrix to use when drawing (defaults to no transform)
|
||||
*/
|
||||
void Blit(OpenGLShaderPtr pipeline, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
|
||||
static void OCIOBlit(OpenGLShaderPtr pipeline, GLuint lut, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
|
||||
|
||||
void OCIOBlit(OpenGLShaderPtr pipeline, GLuint lut, bool flipped = false, QMatrix4x4 matrix = QMatrix4x4());
|
||||
|
||||
void PrepareToDraw(QOpenGLFunctions* f);
|
||||
|
||||
}
|
||||
}
|
||||
static void PrepareToDraw(QOpenGLFunctions* f);
|
||||
};
|
||||
|
||||
#endif // OPENGLFUNCTIONS_H
|
||||
@@ -30,7 +30,7 @@ OpenGLTexture::OpenGLTexture() :
|
||||
texture_(0),
|
||||
width_(0),
|
||||
height_(0),
|
||||
format_(olive::PIX_FMT_INVALID)
|
||||
format_(PixelFormat::PIX_FMT_INVALID)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ bool OpenGLTexture::IsCreated() const
|
||||
return (texture_);
|
||||
}
|
||||
|
||||
void OpenGLTexture::Create(QOpenGLContext *ctx, int width, int height, const olive::PixelFormat &format, const void* data)
|
||||
void OpenGLTexture::Create(QOpenGLContext *ctx, int width, int height, const PixelFormat::Format &format, const void* data)
|
||||
{
|
||||
if (!ctx) {
|
||||
qWarning() << "OpenGLTexture::Create was passed an invalid context";
|
||||
@@ -115,7 +115,7 @@ const int &OpenGLTexture::height() const
|
||||
return height_;
|
||||
}
|
||||
|
||||
const olive::PixelFormat &OpenGLTexture::format() const
|
||||
const PixelFormat::Format &OpenGLTexture::format() const
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void OpenGLTexture::Upload(const void *data)
|
||||
|
||||
Bind();
|
||||
|
||||
PixelFormatInfo info = PixelService::GetPixelFormatInfo(format_);
|
||||
PixelFormat::Info info = PixelService::GetPixelFormatInfo(format_);
|
||||
|
||||
context->functions()->glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
@@ -173,7 +173,7 @@ void OpenGLTexture::CreateInternal(QOpenGLContext* create_ctx, GLuint* tex, cons
|
||||
f->glBindTexture(GL_TEXTURE_2D, *tex);
|
||||
|
||||
// Allocate storage for texture
|
||||
const PixelFormatInfo& bit_depth = PixelService::GetPixelFormatInfo(format_);
|
||||
const PixelFormat::Info& bit_depth = PixelService::GetPixelFormatInfo(format_);
|
||||
|
||||
f->glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
DISABLE_COPY_MOVE(OpenGLTexture)
|
||||
|
||||
void Create(QOpenGLContext* ctx, int width, int height, const olive::PixelFormat &format, const void *data = nullptr);
|
||||
void Create(QOpenGLContext* ctx, int width, int height, const PixelFormat::Format &format, const void *data = nullptr);
|
||||
void Create(QOpenGLContext* ctx, FramePtr frame);
|
||||
|
||||
bool IsCreated() const;
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
const int& height() const;
|
||||
|
||||
const olive::PixelFormat &format() const;
|
||||
const PixelFormat::Format &format() const;
|
||||
|
||||
const GLuint& texture() const;
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
|
||||
int height_;
|
||||
|
||||
olive::PixelFormat format_;
|
||||
PixelFormat::Format format_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
#include "common/clamp.h"
|
||||
#include "core.h"
|
||||
#include "functions.h"
|
||||
#include "node/block/transition/transition.h"
|
||||
#include "node/node.h"
|
||||
#include "openglcolorprocessor.h"
|
||||
#include "openglrenderfunctions.h"
|
||||
#include "render/colormanager.h"
|
||||
#include "render/pixelservice.h"
|
||||
|
||||
@@ -72,14 +72,14 @@ void OpenGLWorker::FrameToValue(StreamPtr stream, FramePtr frame, NodeValueTable
|
||||
}
|
||||
|
||||
// OCIO's CPU conversion is more accurate, so for online we render on CPU but offline we render GPU
|
||||
if (video_params().mode() == olive::kOnline) {
|
||||
if (video_params().mode() == RenderMode::kOnline) {
|
||||
// If alpha is associated, disassociate for the color transform
|
||||
if (video_stream->premultiplied_alpha()) {
|
||||
ColorManager::DisassociateAlpha(frame);
|
||||
}
|
||||
|
||||
// Convert frame to float for OCIO
|
||||
frame = PixelService::ConvertPixelFormat(frame, olive::PIX_FMT_RGBA32F);
|
||||
frame = PixelService::ConvertPixelFormat(frame, PixelFormat::PIX_FMT_RGBA32F);
|
||||
|
||||
// Perform color transform
|
||||
color_processor->ConvertFrame(frame);
|
||||
@@ -96,7 +96,7 @@ void OpenGLWorker::FrameToValue(StreamPtr stream, FramePtr frame, NodeValueTable
|
||||
|
||||
OpenGLTextureCache::ReferencePtr footage_tex_ref = texture_cache_->Get(ctx_, footage_params, frame->data());
|
||||
|
||||
if (video_params().mode() == olive::kOffline) {
|
||||
if (video_params().mode() == RenderMode::kOffline) {
|
||||
if (!color_processor->IsEnabled()) {
|
||||
color_processor->Enable(ctx_, video_stream->premultiplied_alpha());
|
||||
}
|
||||
@@ -238,7 +238,7 @@ void OpenGLWorker::RunNodeAccelerated(const Node *node, const TimeRange &range,
|
||||
iterative_input = input_texture_count;
|
||||
}
|
||||
|
||||
olive::gl::PrepareToDraw(functions_);
|
||||
OpenGLRenderFunctions::PrepareToDraw(functions_);
|
||||
|
||||
input_texture_count++;
|
||||
break;
|
||||
@@ -322,7 +322,7 @@ void OpenGLWorker::RunNodeAccelerated(const Node *node, const TimeRange &range,
|
||||
buffer_.Bind();
|
||||
|
||||
// Blit this texture through this shader
|
||||
olive::gl::Blit(shader);
|
||||
OpenGLRenderFunctions::Blit(shader);
|
||||
|
||||
buffer_.Release();
|
||||
buffer_.Detach();
|
||||
@@ -353,7 +353,7 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
|
||||
{
|
||||
OpenGLTextureCache::ReferencePtr texture = tex_in.value<OpenGLTextureCache::ReferencePtr>();
|
||||
|
||||
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(video_params().format());
|
||||
PixelFormat::Info format_info = PixelService::GetPixelFormatInfo(video_params().format());
|
||||
|
||||
QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
|
||||
buffer_.Attach(texture->texture());
|
||||
|
||||
@@ -136,7 +136,7 @@ void VideoRenderWorker::CloseInternal()
|
||||
|
||||
void VideoRenderWorker::Download(NodeDependency dep, QByteArray hash, QVariant texture, QString filename)
|
||||
{
|
||||
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(video_params().format());
|
||||
PixelFormat::Info format_info = PixelService::GetPixelFormatInfo(video_params().format());
|
||||
|
||||
// Set up OIIO::ImageSpec for compressing cached images on disk
|
||||
OIIO::ImageSpec spec(video_params().effective_width(), video_params().effective_height(), kRGBAChannels, format_info.oiio_desc);
|
||||
|
||||
@@ -114,21 +114,21 @@ void ColorManager::AssociateAlphaPixFmtFilter(ColorManager::AlphaAction action,
|
||||
{
|
||||
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:
|
||||
switch (static_cast<PixelFormat::Format>(f->format())) {
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
qWarning() << "Alpha association functions received an invalid pixel format";
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
case olive::PIX_FMT_RGBA16U:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
qWarning() << "Alpha association functions only works on float-based pixel formats at this time";
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
{
|
||||
AssociateAlphaInternal<qfloat16>(action, reinterpret_cast<qfloat16*>(f->data()), pixel_count);
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
{
|
||||
AssociateAlphaInternal<float>(action, reinterpret_cast<float*>(f->data()), pixel_count);
|
||||
break;
|
||||
|
||||
+35
-13
@@ -21,22 +21,44 @@
|
||||
#ifndef BITDEPTHS_H
|
||||
#define BITDEPTHS_H
|
||||
|
||||
namespace olive {
|
||||
#include <OpenImageIO/imageio.h>
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* @brief Olive's internal supported pixel formats.
|
||||
*/
|
||||
enum PixelFormat {
|
||||
PIX_FMT_INVALID = -1,
|
||||
class PixelFormat {
|
||||
public:
|
||||
/**
|
||||
* @brief Olive's internal supported pixel formats.
|
||||
*/
|
||||
enum Format {
|
||||
PIX_FMT_INVALID = -1,
|
||||
|
||||
PIX_FMT_RGBA8,
|
||||
PIX_FMT_RGBA16U,
|
||||
PIX_FMT_RGBA16F,
|
||||
PIX_FMT_RGBA32F,
|
||||
PIX_FMT_RGBA8,
|
||||
PIX_FMT_RGBA16U,
|
||||
PIX_FMT_RGBA16F,
|
||||
PIX_FMT_RGBA32F,
|
||||
|
||||
PIX_FMT_COUNT
|
||||
PIX_FMT_COUNT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A struct of information pertaining to each enum PixelFormat.
|
||||
*
|
||||
* Primarily this is a means of retrieving OpenGL texture information for different pixel formats/bit depths. Both
|
||||
* RAM and VRAM buffers will need a PixelFormat. To keep consistency between the OpenGL code and CPU code when using
|
||||
* a given PixelFormat, the PixelFormatInfo struct contains all necessary variables that you'll need to plug into
|
||||
* OpenGL.
|
||||
*
|
||||
* Use the static function PixelService::GetPixelFormatInfo to generate a PixelFormatInfo object.
|
||||
*/
|
||||
struct Info {
|
||||
QString name;
|
||||
GLint internal_format;
|
||||
GLenum pixel_format;
|
||||
GLenum gl_pixel_type;
|
||||
int bytes_per_pixel;
|
||||
OIIO::TypeDesc oiio_desc;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BITDEPTHS_H
|
||||
|
||||
+56
-56
@@ -30,37 +30,37 @@ PixelService::PixelService()
|
||||
{
|
||||
}
|
||||
|
||||
PixelFormatInfo PixelService::GetPixelFormatInfo(const olive::PixelFormat &format)
|
||||
PixelFormat::Info PixelService::GetPixelFormatInfo(const PixelFormat::Format &format)
|
||||
{
|
||||
PixelFormatInfo info;
|
||||
PixelFormat::Info info;
|
||||
|
||||
switch (format) {
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
info.name = tr("8-bit");
|
||||
info.internal_format = GL_RGBA8;
|
||||
info.gl_pixel_type = GL_UNSIGNED_BYTE;
|
||||
info.oiio_desc = OIIO::TypeDesc::UINT8;
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA16U:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
info.name = tr("16-bit Integer");
|
||||
info.internal_format = GL_RGBA16;
|
||||
info.gl_pixel_type = GL_UNSIGNED_SHORT;
|
||||
info.oiio_desc = OIIO::TypeDesc::UINT16;
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
info.name = tr("Half-Float (16-bit)");
|
||||
info.internal_format = GL_RGBA16F;
|
||||
info.gl_pixel_type = GL_HALF_FLOAT;
|
||||
info.oiio_desc = OIIO::TypeDesc::HALF;
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
info.name = tr("Full-Float (32-bit)");
|
||||
info.internal_format = GL_RGBA32F;
|
||||
info.gl_pixel_type = GL_FLOAT;
|
||||
info.oiio_desc = OIIO::TypeDesc::FLOAT;
|
||||
break;
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
qFatal("Invalid pixel format requested");
|
||||
}
|
||||
|
||||
@@ -70,28 +70,28 @@ PixelFormatInfo PixelService::GetPixelFormatInfo(const olive::PixelFormat &forma
|
||||
return info;
|
||||
}
|
||||
|
||||
int PixelService::GetBufferSize(const olive::PixelFormat &format, const int &width, const int &height)
|
||||
int PixelService::GetBufferSize(const PixelFormat::Format &format, const int &width, const int &height)
|
||||
{
|
||||
return BytesPerPixel(format) * width * height;
|
||||
}
|
||||
|
||||
int PixelService::BytesPerPixel(const olive::PixelFormat &format)
|
||||
int PixelService::BytesPerPixel(const PixelFormat::Format &format)
|
||||
{
|
||||
return BytesPerChannel(format) * kRGBAChannels;
|
||||
}
|
||||
|
||||
int PixelService::BytesPerChannel(const olive::PixelFormat &format)
|
||||
int PixelService::BytesPerChannel(const PixelFormat::Format &format)
|
||||
{
|
||||
switch (format) {
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
return 1;
|
||||
case olive::PIX_FMT_RGBA16U:
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
return 2;
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
return 4;
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ int PixelService::BytesPerChannel(const olive::PixelFormat &format)
|
||||
return 0;
|
||||
}
|
||||
|
||||
FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelFormat &dest_format)
|
||||
FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const PixelFormat::Format &dest_format)
|
||||
{
|
||||
if (frame->format() == dest_format) {
|
||||
return frame;
|
||||
@@ -122,13 +122,13 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
|
||||
bool valid = true;
|
||||
|
||||
switch (static_cast<olive::PixelFormat>(frame->format())) {
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
switch (static_cast<PixelFormat::Format>(frame->format())) {
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
{
|
||||
uint8_t* source = reinterpret_cast<uint8_t*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA16U: // 8-bit Integer -> 16-bit Integer
|
||||
case PixelFormat::PIX_FMT_RGBA16U: // 8-bit Integer -> 16-bit Integer
|
||||
{
|
||||
uint16_t* destination = reinterpret_cast<uint16_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -136,7 +136,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F: // 8-bit Integer -> 16-bit Float
|
||||
case PixelFormat::PIX_FMT_RGBA16F: // 8-bit Integer -> 16-bit Float
|
||||
{
|
||||
qfloat16* destination = reinterpret_cast<qfloat16*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -144,7 +144,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F: // 8-bit Integer -> 32-bit Float
|
||||
case PixelFormat::PIX_FMT_RGBA32F: // 8-bit Integer -> 32-bit Float
|
||||
{
|
||||
float* destination = reinterpret_cast<float*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -152,19 +152,19 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16U:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
{
|
||||
uint16_t* source = reinterpret_cast<uint16_t*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8: // 16-bit Integer -> 8-bit Integer
|
||||
case PixelFormat::PIX_FMT_RGBA8: // 16-bit Integer -> 8-bit Integer
|
||||
{
|
||||
uint8_t* destination = reinterpret_cast<uint8_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -172,7 +172,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F: // 16-bit Integer -> 16-bit Float
|
||||
case PixelFormat::PIX_FMT_RGBA16F: // 16-bit Integer -> 16-bit Float
|
||||
{
|
||||
qfloat16* destination = reinterpret_cast<qfloat16*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -180,7 +180,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F: // 16-bit Integer -> 32-bit Float
|
||||
case PixelFormat::PIX_FMT_RGBA32F: // 16-bit Integer -> 32-bit Float
|
||||
{
|
||||
float* destination = reinterpret_cast<float*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -188,19 +188,19 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA16U:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
{
|
||||
qfloat16* source = reinterpret_cast<qfloat16*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8: // 16-bit Float -> 8-bit Integer
|
||||
case PixelFormat::PIX_FMT_RGBA8: // 16-bit Float -> 8-bit Integer
|
||||
{
|
||||
uint8_t* destination = reinterpret_cast<uint8_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -208,7 +208,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16U: // 16-bit Float -> 16-bit Integer
|
||||
case PixelFormat::PIX_FMT_RGBA16U: // 16-bit Float -> 16-bit Integer
|
||||
{
|
||||
uint16_t* destination = reinterpret_cast<uint16_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -216,7 +216,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F: // 16-bit Float -> 32-bit Float
|
||||
case PixelFormat::PIX_FMT_RGBA32F: // 16-bit Float -> 32-bit Float
|
||||
{
|
||||
float* destination = reinterpret_cast<float*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -224,19 +224,19 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
{
|
||||
float* source = reinterpret_cast<float*>(frame->data());
|
||||
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8: // 32-bit Float -> 8-bit Integer
|
||||
case PixelFormat::PIX_FMT_RGBA8: // 32-bit Float -> 8-bit Integer
|
||||
{
|
||||
uint8_t* destination = reinterpret_cast<uint8_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -244,7 +244,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16U: // 32-bit Float -> 16-bit Integer
|
||||
case PixelFormat::PIX_FMT_RGBA16U: // 32-bit Float -> 16-bit Integer
|
||||
{
|
||||
uint16_t* destination = reinterpret_cast<uint16_t*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -252,7 +252,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_RGBA16F: // 32-bit Float -> 16-bit Float
|
||||
case PixelFormat::PIX_FMT_RGBA16F: // 32-bit Float -> 16-bit Float
|
||||
{
|
||||
qfloat16* destination = reinterpret_cast<qfloat16*>(converted->data());
|
||||
for (int i=0;i<pix_count;i++) {
|
||||
@@ -260,15 +260,15 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
valid = false;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ FramePtr PixelService::ConvertPixelFormat(FramePtr frame, const olive::PixelForm
|
||||
|
||||
void PixelService::ConvertRGBtoRGBA(FramePtr frame)
|
||||
{
|
||||
olive::PixelFormat dest_format = static_cast<olive::PixelFormat>(frame->format());
|
||||
PixelFormat::Format dest_format = static_cast<PixelFormat::Format>(frame->format());
|
||||
|
||||
int rgb_pixel_size = BytesPerChannel(dest_format) * kRGBChannels;
|
||||
int rgb_frame_size = frame->width() * frame->height() * rgb_pixel_size;
|
||||
@@ -300,20 +300,20 @@ void PixelService::ConvertRGBtoRGBA(FramePtr frame)
|
||||
|
||||
// Write a full alpha value according to the format
|
||||
switch (dest_format) {
|
||||
case olive::PIX_FMT_RGBA8:
|
||||
case PixelFormat::PIX_FMT_RGBA8:
|
||||
*alpha_ptr = UINT8_MAX;
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA16U:
|
||||
case PixelFormat::PIX_FMT_RGBA16U:
|
||||
*reinterpret_cast<uint16_t*>(alpha_ptr) = UINT16_MAX;
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA16F:
|
||||
case PixelFormat::PIX_FMT_RGBA16F:
|
||||
*reinterpret_cast<qfloat16*>(alpha_ptr) = 1.0f;
|
||||
break;
|
||||
case olive::PIX_FMT_RGBA32F:
|
||||
case PixelFormat::PIX_FMT_RGBA32F:
|
||||
*reinterpret_cast<float*>(alpha_ptr) = 1.0f;
|
||||
break;
|
||||
case olive::PIX_FMT_INVALID:
|
||||
case olive::PIX_FMT_COUNT:
|
||||
case PixelFormat::PIX_FMT_INVALID:
|
||||
case PixelFormat::PIX_FMT_COUNT:
|
||||
qFatal("Invalid pixel format requested");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,31 +22,10 @@
|
||||
#define PIXELSERVICE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <OpenImageIO/imageio.h>
|
||||
|
||||
#include "codec/frame.h"
|
||||
#include "pixelformat.h"
|
||||
|
||||
/**
|
||||
* @brief A struct of information pertaining to each enum PixelFormat.
|
||||
*
|
||||
* Primarily this is a means of retrieving OpenGL texture information for different pixel formats/bit depths. Both
|
||||
* RAM and VRAM buffers will need a PixelFormat. To keep consistency between the OpenGL code and CPU code when using
|
||||
* a given PixelFormat, the PixelFormatInfo struct contains all necessary variables that you'll need to plug into
|
||||
* OpenGL.
|
||||
*
|
||||
* Use the static function PixelService::GetPixelFormatInfo to generate a PixelFormatInfo object.
|
||||
*/
|
||||
struct PixelFormatInfo {
|
||||
QString name;
|
||||
GLint internal_format;
|
||||
GLenum pixel_format;
|
||||
GLenum gl_pixel_type;
|
||||
int bytes_per_pixel;
|
||||
OIIO::TypeDesc oiio_desc;
|
||||
};
|
||||
|
||||
class PixelService : public QObject {
|
||||
public:
|
||||
|
||||
@@ -57,7 +36,7 @@ public:
|
||||
*
|
||||
* \see PixelFormatInfo
|
||||
*/
|
||||
static PixelFormatInfo GetPixelFormatInfo(const olive::PixelFormat& format);
|
||||
static PixelFormat::Info GetPixelFormatInfo(const PixelFormat::Format& format);
|
||||
|
||||
/**
|
||||
* @brief Returns the minimum buffer size (in bytes) necessary for a given format, width, and height.
|
||||
@@ -74,7 +53,7 @@ public:
|
||||
*
|
||||
* The height (in pixels) of the buffer.
|
||||
*/
|
||||
static int GetBufferSize(const olive::PixelFormat &format, const int& width, const int& height);
|
||||
static int GetBufferSize(const PixelFormat::Format &format, const int& width, const int& height);
|
||||
|
||||
/**
|
||||
* @brief Returns the number of bytes per pixel for a certain format
|
||||
@@ -83,19 +62,19 @@ public:
|
||||
* requires for a certain format. The number of bytes will always be a multiple of 4 since all formats use RGBA and
|
||||
* are at least 1 bpc.
|
||||
*/
|
||||
static int BytesPerPixel(const olive::PixelFormat& format);
|
||||
static int BytesPerPixel(const PixelFormat::Format &format);
|
||||
|
||||
/**
|
||||
* @brief Returns the number of bytes per channel for a certain format
|
||||
*/
|
||||
static int BytesPerChannel(const olive::PixelFormat& format);
|
||||
static int BytesPerChannel(const PixelFormat::Format& format);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
static FramePtr ConvertPixelFormat(FramePtr frame, const PixelFormat::Format &dest_format);
|
||||
|
||||
/**
|
||||
* @brief Convert an RGB image to an RGBA image
|
||||
|
||||
+15
-16
@@ -1,25 +1,24 @@
|
||||
#ifndef RENDERMODE_H
|
||||
#define RENDERMODE_H
|
||||
|
||||
namespace olive {
|
||||
|
||||
/**
|
||||
* @brief The primary different "modes" the renderer can function in
|
||||
*/
|
||||
enum RenderMode {
|
||||
class RenderMode {
|
||||
public:
|
||||
/**
|
||||
* This render is for realtime preview ONLY and does not need to be "perfect". Nodes can use lower-accuracy functions
|
||||
* to save performance when possible.
|
||||
* @brief The primary different "modes" the renderer can function in
|
||||
*/
|
||||
kOffline,
|
||||
enum Mode {
|
||||
/**
|
||||
* This render is for realtime preview ONLY and does not need to be "perfect". Nodes can use lower-accuracy functions
|
||||
* to save performance when possible.
|
||||
*/
|
||||
kOffline,
|
||||
|
||||
/**
|
||||
* This render is some sort of export or master copy and Nodes should take time/bandwidth/system resources to produce
|
||||
* a higher accuracy version.
|
||||
*/
|
||||
kOnline
|
||||
/**
|
||||
* This render is some sort of export or master copy and Nodes should take time/bandwidth/system resources to produce
|
||||
* a higher accuracy version.
|
||||
*/
|
||||
kOnline
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // RENDERMODE_H
|
||||
|
||||
@@ -30,11 +30,11 @@ const rational &VideoParams::time_base() const
|
||||
}
|
||||
|
||||
VideoRenderingParams::VideoRenderingParams() :
|
||||
format_(olive::PIX_FMT_INVALID)
|
||||
format_(PixelFormat::PIX_FMT_INVALID)
|
||||
{
|
||||
}
|
||||
|
||||
VideoRenderingParams::VideoRenderingParams(const int &width, const int &height, const rational &time_base, const olive::PixelFormat &format, const olive::RenderMode& mode, const int ÷r) :
|
||||
VideoRenderingParams::VideoRenderingParams(const int &width, const int &height, const rational &time_base, const PixelFormat::Format &format, const RenderMode::Mode& mode, const int ÷r) :
|
||||
VideoParams(width, height, time_base),
|
||||
format_(format),
|
||||
mode_(mode),
|
||||
@@ -43,7 +43,7 @@ VideoRenderingParams::VideoRenderingParams(const int &width, const int &height,
|
||||
calculate_effective_size();
|
||||
}
|
||||
|
||||
VideoRenderingParams::VideoRenderingParams(const VideoParams ¶ms, const olive::PixelFormat &format, const olive::RenderMode& mode, const int& divider) :
|
||||
VideoRenderingParams::VideoRenderingParams(const VideoParams ¶ms, const PixelFormat::Format &format, const RenderMode::Mode& mode, const int& divider) :
|
||||
VideoParams(params),
|
||||
format_(format),
|
||||
mode_(mode),
|
||||
@@ -67,12 +67,12 @@ const int& VideoRenderingParams::effective_height() const
|
||||
return effective_height_;
|
||||
}
|
||||
|
||||
const olive::PixelFormat &VideoRenderingParams::format() const
|
||||
const PixelFormat::Format &VideoRenderingParams::format() const
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
|
||||
const olive::RenderMode &VideoRenderingParams::mode() const
|
||||
const RenderMode::Mode &VideoRenderingParams::mode() const
|
||||
{
|
||||
return mode_;
|
||||
}
|
||||
@@ -88,6 +88,6 @@ bool VideoRenderingParams::is_valid() const
|
||||
return (width() > 0
|
||||
&& height() > 0
|
||||
&& !time_base().isNull()
|
||||
&& format_ != olive::PIX_FMT_INVALID
|
||||
&& format_ != olive::PIX_FMT_COUNT);
|
||||
&& format_ != PixelFormat::PIX_FMT_INVALID
|
||||
&& format_ != PixelFormat::PIX_FMT_COUNT);
|
||||
}
|
||||
|
||||
@@ -25,22 +25,22 @@ private:
|
||||
class VideoRenderingParams : public VideoParams {
|
||||
public:
|
||||
VideoRenderingParams();
|
||||
VideoRenderingParams(const int& width, const int& height, const rational& time_base, const olive::PixelFormat& format, const olive::RenderMode& mode, const int& divider = 1);
|
||||
VideoRenderingParams(const VideoParams& params, const olive::PixelFormat& format, const olive::RenderMode& mode, const int& divider = 1);
|
||||
VideoRenderingParams(const int& width, const int& height, const rational& time_base, const PixelFormat::Format& format, const RenderMode::Mode& mode, const int& divider = 1);
|
||||
VideoRenderingParams(const VideoParams& params, const PixelFormat::Format& format, const RenderMode::Mode& mode, const int& divider = 1);
|
||||
|
||||
const int& divider() const;
|
||||
const int& effective_width() const;
|
||||
const int& effective_height() const;
|
||||
|
||||
bool is_valid() const;
|
||||
const olive::PixelFormat& format() const;
|
||||
const olive::RenderMode& mode() const;
|
||||
const PixelFormat::Format& format() const;
|
||||
const RenderMode::Mode& mode() const;
|
||||
|
||||
private:
|
||||
void calculate_effective_size();
|
||||
|
||||
olive::PixelFormat format_;
|
||||
olive::RenderMode mode_;
|
||||
PixelFormat::Format format_;
|
||||
RenderMode::Mode mode_;
|
||||
|
||||
int divider_;
|
||||
int effective_width_;
|
||||
|
||||
Reference in New Issue
Block a user