Beispiel #1
0
ColorProcessor*
ColorConfig::createFileTransform (string_view name, bool inverse) const
{
#ifdef USE_OCIO
    // Ask OCIO to make a Processor that can handle the requested
    // transformation.
    if (getImpl()->config_) {
        OCIO::ConstConfigRcPtr config = getImpl()->config_;
        OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create();
        transform->setSrc (name.c_str());
        transform->setInterpolation (OCIO::INTERP_BEST);
        OCIO::TransformDirection dir = inverse ? OCIO::TRANSFORM_DIR_INVERSE
                                               : OCIO::TRANSFORM_DIR_FORWARD;
        OCIO::ConstContextRcPtr context = config->getCurrentContext();
        OCIO::ConstProcessorRcPtr p;
        try {
            // Get the processor corresponding to this transform.
            p = getImpl()->config_->getProcessor (context, transform, dir);
        }
        catch(OCIO::Exception &e) {
            getImpl()->error_ = e.what();
            return NULL;
        }
        catch(...) {
            getImpl()->error_ = "An unknown error occurred in OpenColorIO, getProcessor";
            return NULL;
        }
    
        getImpl()->error_ = "";
        return new ColorProcessor_OCIO(p);
    }
#endif

    return NULL;    // if we get this far, we've failed
}
OCIO_ADD_GPU_TEST(Lut1DOp, scale_lut1d_4_generic_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_4.spi1d");

    OCIO::GpuShaderDescRcPtr shaderDesc = OCIO::GpuShaderDesc::CreateShaderDesc();

    test.setContext(file->createEditableCopy(), shaderDesc);
    test.setErrorThreshold(1e-4f);
}
OCIO_ADD_GPU_TEST(Lut1DOp, not_linear_lut1d_5_generic_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_5.spi1d");

    OCIO::GpuShaderDescRcPtr shaderDesc = OCIO::GpuShaderDesc::CreateShaderDesc();

    test.setContext(file->createEditableCopy(), shaderDesc);
    test.setErrorThreshold(1e-3f);
    test.setRelativeComparison(true);
}
OCIO_ADD_GPU_TEST(Lut1DOp, lut1d_3_big_nearest_generic_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_3.spi1d");
    file->setInterpolation(OCIO::INTERP_NEAREST);

    OCIO::GpuShaderDescRcPtr shaderDesc = OCIO::GpuShaderDesc::CreateShaderDesc();

    test.setContext(file->createEditableCopy(), shaderDesc);
    test.setErrorThreshold(1e-4f);
}
OCIO_ADD_GPU_TEST(Lut1DOp, lut1d_3_big_inverse_generic_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_3.spi1d");
    file->setDirection(OCIO::TRANSFORM_DIR_INVERSE);

    OCIO::GpuShaderDescRcPtr shaderDesc = OCIO::GpuShaderDesc::CreateShaderDesc();

    test.setContext(file->createEditableCopy(), shaderDesc);
    test.setErrorThreshold(1e-4f);
}
OCIO_ADD_GPU_TEST(Lut1DOp, lut1d_3_big_legacy_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_3.spi1d");

    OCIO::GpuShaderDescRcPtr shaderDesc 
        = OCIO::GpuShaderDesc::CreateLegacyShaderDesc(2*LUT3D_EDGE_SIZE);

    test.setContext(file->createEditableCopy(), shaderDesc);
    test.setErrorThreshold(1e-4f);
}
OCIO_ADD_GPU_TEST(Lut1DOp, lut1d_2_inverse_legacy_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_2.spi1d");
    file->setDirection(OCIO::TRANSFORM_DIR_INVERSE);

    OCIO::GpuShaderDescRcPtr shaderDesc 
        = OCIO::GpuShaderDesc::CreateLegacyShaderDesc(2*LUT3D_EDGE_SIZE);

    test.setContext(file->createEditableCopy(), shaderDesc);
    test.setErrorThreshold(5e-4f);
}
OCIO_ADD_GPU_TEST(Lut1DOp, lut1d_1_small_legacy_shader)
{
    OCIO::FileTransformRcPtr file = GetFileTransform("lut1d_1.spi1d");

    OCIO::GpuShaderDescRcPtr shaderDesc 
        = OCIO::GpuShaderDesc::CreateLegacyShaderDesc(2*LUT3D_EDGE_SIZE);

    test.setContext(file->createEditableCopy(), shaderDesc);

    // TODO: Investigate why the test needs such a threshold
    test.setErrorThreshold(3e-3f);
}
void OCIOFileTransform::_validate(bool for_real)
{
    if(!m_file)
    {
        error("The source file must be specified.");
        return;
    }
    
    try
    {
        OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
        
        OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create();
        transform->setSrc(m_file);
        
        transform->setCCCId(m_cccid.c_str());
        
        if(m_dirindex == 0) transform->setDirection(OCIO::TRANSFORM_DIR_FORWARD);
        else transform->setDirection(OCIO::TRANSFORM_DIR_INVERSE);
        
        if(m_interpindex == 0) transform->setInterpolation(OCIO::INTERP_NEAREST);
        else if(m_interpindex == 1) transform->setInterpolation(OCIO::INTERP_LINEAR);
        else if(m_interpindex == 2) transform->setInterpolation(OCIO::INTERP_TETRAHEDRAL);
        else if(m_interpindex == 3) transform->setInterpolation(OCIO::INTERP_BEST);
        else
        {
            // Should never happen
            error("Interpolation value out of bounds");
            return;
        }
        
        m_processor = config->getProcessor(transform, OCIO::TRANSFORM_DIR_FORWARD);
    }
    catch(OCIO::Exception &e)
    {
        error(e.what());
        return;
    }
    
    if(m_processor->isNoOp())
    {
        set_out_channels(DD::Image::Mask_None); // prevents engine() from being called
    } else {    
        set_out_channels(DD::Image::Mask_All);
    }

    DD::Image::PixelIop::_validate(for_real);
}
void OCIOFileTransform::_validate(bool for_real)
{
    input0().validate(for_real);
    
    if(!src)
    {
        error("The source file must be specified.");
        return;
    }
    
    try
    {
        OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
        config->sanityCheck();
        
        OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create();
        transform->setSrc(src);
        
        // TODO: For some reason, cccid is NOT incorporated in this node's hash.
        // Until then, cccid is considered broken. Figure out why.
        transform->setCCCId(cccid.c_str());
        
        if(dirindex == 0) transform->setDirection(OCIO::TRANSFORM_DIR_FORWARD);
        else transform->setDirection(OCIO::TRANSFORM_DIR_INVERSE);
        
        if(interpindex == 0) transform->setInterpolation(OCIO::INTERP_NEAREST);
        else transform->setInterpolation(OCIO::INTERP_LINEAR);
        
        processor = config->getProcessor(transform, OCIO::TRANSFORM_DIR_FORWARD);
    }
    catch(OCIO::Exception &e)
    {
        error(e.what());
        return;
    }
    
    if(processor->isNoOp())
    {
        // TODO or call disable() ?
        set_out_channels(DD::Image::Mask_None); // prevents engine() from being called
        copy_info();
        return;
    }
    
    set_out_channels(DD::Image::Mask_All);

    DD::Image::PixelIop::_validate(for_real);
}
Beispiel #11
0
OCIO::GroupTransformRcPtr
parse_luts(int argc, const char *argv[])
{
    OCIO::GroupTransformRcPtr groupTransform = OCIO::GroupTransform::Create();
    const char *lastCCCId = NULL; // Ugly to use this but using GroupTransform::getTransform()
                                  // returns a const object so we must set this
                                  // prior to using --lut for now.
    
    for(int i=0; i<argc; ++i)
    {
        std::string arg(argv[i]);
        
        if(arg == "--lut" || arg == "-lut")
        {
            if(i+1>=argc)
            {
                throw OCIO::Exception("Error parsing --lut. Invalid num args");
            }
            
            OCIO::FileTransformRcPtr t = OCIO::FileTransform::Create();
            t->setSrc(argv[i+1]);
            t->setInterpolation(OCIO::INTERP_BEST);
            if (lastCCCId)
            {
                t->setCCCId(lastCCCId);
            }
            groupTransform->push_back(t);
            
            i += 1;
        }
        else if(arg == "--cccid" || arg == "-cccid")
        {
            if(i+1>=argc)
            {
                throw OCIO::Exception("Error parsing --cccid. Invalid num args");
            }
            
            lastCCCId = argv[i+1];
            
            i += 1;
        }
        else if(arg == "--invlut" || arg == "-invlut")
        {
            if(i+1>=argc)
            {
                throw OCIO::Exception("Error parsing --invlut. Invalid num args");
            }
            
            OCIO::FileTransformRcPtr t = OCIO::FileTransform::Create();
            t->setSrc(argv[i+1]);
            t->setInterpolation(OCIO::INTERP_BEST);
            t->setDirection(OCIO::TRANSFORM_DIR_INVERSE);
            groupTransform->push_back(t);
            
            i += 1;
        }
        else if(arg == "--slope" || arg == "-slope")
        {
            if(i+3>=argc)
            {
                throw OCIO::Exception("Error parsing --slope. Invalid num args");
            }
            
            OCIO::CDLTransformRcPtr t = OCIO::CDLTransform::Create();
            
            float scale[3];
            scale[0] = (float) atof(argv[i+1]);
            scale[1] = (float) atof(argv[i+2]);
            scale[2] = (float) atof(argv[i+3]);
            t->setSlope(scale);
            groupTransform->push_back(t);
            
            i += 3;
        }
        else if(arg == "--offset" || arg == "-offset")
        {
            if(i+3>=argc)
            {
                throw OCIO::Exception("Error parsing --offset. Invalid num args");
            }
            
            OCIO::CDLTransformRcPtr t = OCIO::CDLTransform::Create();
            
            float offset[3];
            offset[0] = (float) atof(argv[i+1]);
            offset[1] = (float) atof(argv[i+2]);
            offset[2] = (float) atof(argv[i+3]);
            t->setOffset(offset);
            groupTransform->push_back(t);
            
            i += 3;
        }
        else if(arg == "--offset10" || arg == "-offset10")
        {
            if(i+3>=argc)
            {
                throw OCIO::Exception("Error parsing --offset10. Invalid num args");
            }
            
            OCIO::CDLTransformRcPtr t = OCIO::CDLTransform::Create();
            
            float offset[3];
            offset[0] = (float) atof(argv[i+1]) / 1023.0f;
            offset[1] = (float) atof(argv[i+2]) / 1023.0f;
            offset[2] = (float) atof(argv[i+3]) / 1023.0f;
            t->setOffset(offset);
            groupTransform->push_back(t);
            i += 3;
        }
        else if(arg == "--power" || arg == "-power")
        {
            if(i+3>=argc)
            {
                throw OCIO::Exception("Error parsing --power. Invalid num args");
            }
            
            OCIO::CDLTransformRcPtr t = OCIO::CDLTransform::Create();
            
            float power[3];
            power[0] = (float) atof(argv[i+1]);
            power[1] = (float) atof(argv[i+2]);
            power[2] = (float) atof(argv[i+3]);
            t->setPower(power);
            groupTransform->push_back(t);
            
            i += 3;
        }
        else if(arg == "--sat" || arg == "-sat")
        {
            if(i+1>=argc)
            {
                throw OCIO::Exception("Error parsing --sat. Invalid num args");
            }
            
            OCIO::CDLTransformRcPtr t = OCIO::CDLTransform::Create();
            t->setSat((float) atof(argv[i+1]));
            groupTransform->push_back(t);
            
            i += 1;
        }
    }
    
    return groupTransform;
}