Esempio n. 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
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
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);
}
Esempio n. 4
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;
}