22#include <OpenColorIO/OpenColorIO.h>
25namespace OCIO = OCIO_NAMESPACE;
30 OCIO::ConstCPUProcessorRcPtr
cpu;
48 return OCIO::BIT_DEPTH_UINT8;
52 return OCIO::BIT_DEPTH_UINT16;
56 return OCIO::BIT_DEPTH_UINT10;
60 return OCIO::BIT_DEPTH_UINT12;
67 return OCIO::BIT_DEPTH_F16;
71 return OCIO::BIT_DEPTH_F32;
74 return OCIO::BIT_DEPTH_UNKNOWN;
81 OCIO::ConstContextRcPtr context = config->getCurrentContext();
87 OCIO::ContextRcPtr
ctx = context->createEditableCopy();
100 const char *input_color_space,
101 const char *output_color_space,
107 s->config = OCIO::Config::CreateFromEnv();
109 s->config = OCIO::Config::CreateFromFile(config_path);
111 if (!
s->config || !input_color_space || !output_color_space) {
121 OCIO::ColorSpaceTransformRcPtr cst = OCIO::ColorSpaceTransform::Create();
122 cst->setSrc(input_color_space);
123 cst->setDst(output_color_space);
125 s->processor =
s->config->getProcessor(context, cst, OCIO::TRANSFORM_DIR_FORWARD);
128 }
catch (OCIO::Exception &e) {
129 av_log(
ctx,
AV_LOG_ERROR,
"OCIO Filter: Error in create_output_colorspace_processor: %s\n", e.what());
138 const char *config_path,
139 const char *input_color_space,
148 s->config = OCIO::Config::CreateFromEnv();
150 s->config = OCIO::Config::CreateFromFile(config_path);
152 if (!
s->config || !input_color_space || !display || !view) {
163 OCIO::DisplayViewTransformRcPtr dv = OCIO::DisplayViewTransform::Create();
164 dv->setSrc(input_color_space);
165 dv->setDisplay(display);
167 OCIO::TransformDirection direction = OCIO::TRANSFORM_DIR_FORWARD;
169 direction = OCIO::TRANSFORM_DIR_INVERSE;
171 s->processor =
s->config->getProcessor(context, dv, direction);
174 }
catch (OCIO::Exception &e) {
184 const char *file_transform,
188 if (!file_transform) {
195 OCIO::FileTransformRcPtr ft = OCIO::FileTransform::Create();
196 ft->setSrc(file_transform);
197 OCIO::TransformDirection direction = OCIO::TRANSFORM_DIR_FORWARD;
199 direction = OCIO::TRANSFORM_DIR_INVERSE;
200 s->config = OCIO::Config::Create();
201 s->processor =
s->config->getProcessor(ft, direction);
204 }
catch (OCIO::Exception &e) {
219 if (!
s || !
s->processor)
222 s->cpu =
s->processor->getOptimizedCPUProcessor(
224 OCIO::OPTIMIZATION_DEFAULT);
227 }
catch (OCIO::Exception &e) {
240 if (ocio_bitdepth == OCIO::BIT_DEPTH_UNKNOWN) {
241 throw std::runtime_error(
"Unsupported pixel format for OCIO processing");
244 int stridex =
frame->linesize[0];
248 throw std::runtime_error(
"Invalid pixel format descriptor");
255 uint8_t *red =
frame->data[2] + y_start *
frame->linesize[2];
256 uint8_t *green =
frame->data[0] + y_start *
frame->linesize[0];
257 uint8_t *blue =
frame->data[1] + y_start *
frame->linesize[1];
258 uint8_t *
alpha = (
desc->nb_components == 4)
259 ? (
frame->data[3] + y_start *
frame->linesize[3])
262 return new OCIO::PlanarImageDesc(
263 (
void *)red, (
void *)green, (
void *)blue, (
void *)
alpha,
frame->width,
264 height, ocio_bitdepth,
desc->comp[0].step, stridex);
270 return new OCIO::PackedImageDesc(
272 desc->comp[0].depth / 8,
desc->comp[0].step,
frame->linesize[0]);
285 s->cpu->apply(*imgDesc);
292 s->cpu->apply(*input, *output);
297 }
catch (
const OCIO::Exception &ex) {
300 }
catch (
const std::exception &ex) {
SwsAArch64OpImplParams params
static const char *const format[]
static AVFormatContext * ctx
static char * output_format
reference-counted frame API
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const int16_t alpha[]
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
void ocio_destroy_processor(AVFilterContext *ctx, OCIOHandle handle)
OCIOHandle ocio_create_display_view_processor(AVFilterContext *ctx, const char *config_path, const char *input_color_space, const char *display, const char *view, int inverse, AVDictionary *params)
OCIOHandle ocio_create_output_colorspace_processor(AVFilterContext *ctx, const char *config_path, const char *input_color_space, const char *output_color_space, AVDictionary *params)
static OCIO::ImageDesc * AVFrame2ImageDescSlice(AVFrame *frame, int y_start, int height)
static OCIO::BitDepth get_ocio_depth(int format)
static OCIO::ConstContextRcPtr add_context_params(OCIO::ConstConfigRcPtr config, AVDictionary *params)
int ocio_finalize_processor(AVFilterContext *ctx, OCIOHandle handle, int input_format, int output_format)
OCIOHandle ocio_create_file_transform_processor(AVFilterContext *ctx, const char *file_transform, int inverse)
int ocio_apply(AVFilterContext *ctx, OCIOHandle handle, AVFrame *input_frame, AVFrame *output_frame, int y_start, int height)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRAPF16
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_PIX_FMT_GBRPF16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAPF32
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
OCIO::ConstCPUProcessorRcPtr cpu
OCIO::ConstConfigRcPtr config
OCIO::ConstProcessorRcPtr processor