Example #1
0
bool
ColorConfig::reset (string_view filename)
{
    bool ok = true;
    delete m_impl;

    m_impl = new ColorConfig::Impl;
#ifdef USE_OCIO
    OCIO::SetLoggingLevel (OCIO::LOGGING_LEVEL_NONE);
    try {
        if (filename.empty()) {
            getImpl()->config_ = OCIO::GetCurrentConfig();
        } else {
            getImpl()->config_ = OCIO::Config::CreateFromFile (filename.c_str());
        }
    }
    catch(OCIO::Exception &e) {
        getImpl()->error_ = e.what();
        ok = false;
    }
    catch(...) {
        getImpl()->error_ = "An unknown error occurred in OpenColorIO creating the config";
        ok = false;
    }
#endif

    getImpl()->inventory ();

    // If we populated our own, remove any errors.
    if (getNumColorSpaces() && !getImpl()->error_.empty())
        getImpl()->error_.clear();

    return ok;
}
Example #2
0
int
ColorConfig::getNumViews(string_view display) const
{
#ifdef USE_OCIO
    if (getImpl()->config_)
        return getImpl()->config_->getNumViews(display.c_str());
#endif
    return 0;
}
Example #3
0
string_view
ColorConfig::parseColorSpaceFromString (string_view str) const
{
#ifdef USE_OCIO
    if (getImpl() && getImpl()->config_) {
        return getImpl()->config_->parseColorSpaceFromString (str.c_str());
    }
#endif
    return "";
}
Example #4
0
string_view
ColorConfig::parseColorSpaceFromString (string_view str) const
{
#ifdef USE_OCIO
    string_view result (getImpl()->config_->parseColorSpaceFromString (str.c_str()));
    return result;
#else
    return "";
#endif
}
/// Read the entire contents of the named file and place it in str,
/// returning true on success, false on failure.
inline bool
read_text_file (string_view filename, std::string &str)
{
    std::ifstream in (filename.c_str(), std::ios::in | std::ios::binary);
    if (in) {
        std::ostringstream contents;
        contents << in.rdbuf();
        in.close ();
        str = contents.str();
        return true;
    }
    return false;
}
Example #6
0
void
Filesystem::open(OIIO::ofstream& stream, string_view path,
                 std::ios_base::openmode mode)
{
#ifdef _WIN32
    // Windows std::ofstream accepts non-standard wchar_t*
    // On MingW, we use our own OIIO::ofstream
    std::wstring wpath = Strutil::utf8_to_utf16(path);
    stream.open(wpath.c_str(), mode);
#else
    stream.open(path.c_str(), mode);
#endif
}
Example #7
0
TypeDesc
ColorConfig::getColorSpaceDataType (string_view name, int *bits) const
{
#ifdef USE_OCIO
    OCIO::ConstColorSpaceRcPtr c = getImpl()->config_->getColorSpace (name.c_str());
    if (c) {
        OCIO::BitDepth b = c->getBitDepth();
        switch (b) {
        case OCIO::BIT_DEPTH_UNKNOWN : return TypeDesc::UNKNOWN;
        case OCIO::BIT_DEPTH_UINT8   : *bits =  8; return TypeDesc::UINT8;
        case OCIO::BIT_DEPTH_UINT10  : *bits = 10; return TypeDesc::UINT16;
        case OCIO::BIT_DEPTH_UINT12  : *bits = 12; return TypeDesc::UINT16;
        case OCIO::BIT_DEPTH_UINT14  : *bits = 14; return TypeDesc::UINT16;
        case OCIO::BIT_DEPTH_UINT16  : *bits = 16; return TypeDesc::UINT16;
        case OCIO::BIT_DEPTH_UINT32  : *bits = 32; return TypeDesc::UINT32;
        case OCIO::BIT_DEPTH_F16     : *bits = 16; return TypeDesc::HALF;
        case OCIO::BIT_DEPTH_F32     : *bits = 32; return TypeDesc::FLOAT;
        }
    }
#endif
    return TypeDesc::UNKNOWN;
}
Example #8
0
string_view
Sysutil::getenv (string_view name)
{
    return string_view (::getenv (name.c_str()));
}
bool
OSLCompilerImpl::compile (string_view filename,
                          const std::vector<std::string> &options,
                          string_view stdoslpath)
{
    if (! OIIO::Filesystem::exists (filename)) {
        error (ustring(), 0, "Input file \"%s\" not found", filename.c_str());
        return false;
    }

    std::vector<std::string> defines;
    std::vector<std::string> includepaths;
#if OIIO_VERSION >= 10604
    m_cwd = OIIO::Filesystem::current_path();
#else
    m_cwd = boost::filesystem::current_path().string();
#endif
    m_main_filename = filename;

    // Determine where the installed shader include directory is, and
    // look for ../shaders/stdosl.h and force it to include.
    if (stdoslpath.empty()) {
        // look in $OSLHOME/shaders
        const char *OSLHOME = getenv ("OSLHOME");
        if (OSLHOME && OSLHOME[0]) {
            std::string path = std::string(OSLHOME) + "/shaders";
            if (OIIO::Filesystem::exists (path)) {
                path = path + "/stdosl.h";
                if (OIIO::Filesystem::exists (path))
                    stdoslpath = ustring(path);
            }
        }
    }
    if (stdoslpath.empty() || ! OIIO::Filesystem::exists(stdoslpath))
        warning (ustring(filename), 0, "Unable to find \"stdosl.h\"");
    else {
        // Add the directory of stdosl.h to the include paths
        includepaths.push_back (OIIO::Filesystem::parent_path (stdoslpath));
    }

    read_compile_options (options, defines, includepaths);

    std::string preprocess_result;
    if (! preprocess_file (filename, stdoslpath,
                           defines, includepaths, preprocess_result)) {
        return false;
    } else if (m_preprocess_only) {
        std::cout << preprocess_result;
    } else {
        bool parseerr = osl_parse_buffer (preprocess_result);
        if (! parseerr) {
            if (shader())
                shader()->typecheck ();
            else
                error (ustring(), 0, "No shader function defined");
        }

        // Print the parse tree if there were no errors
        if (m_debug) {
            symtab().print ();
            if (shader())
                shader()->print (std::cout);
        }

        if (! error_encountered()) {
            shader()->codegen ();
            track_variable_dependencies ();
            track_variable_lifetimes ();
            check_for_illegal_writes ();
//            if (m_optimizelevel >= 1)
//                coalesce_temporaries ();
        }
 
        if (! error_encountered()) {
            if (m_output_filename.size() == 0)
                m_output_filename = default_output_filename ();

            std::ofstream oso_output (m_output_filename.c_str());
            if (! oso_output.good()) {
                error (ustring(), 0, "Could not open \"%s\"",
                       m_output_filename.c_str());
                return false;
            }
            ASSERT (m_osofile == NULL);
            m_osofile = &oso_output;

            write_oso_file (m_output_filename, OIIO::Strutil::join(options," "));
            ASSERT (m_osofile == NULL);
        }

        oslcompiler = NULL;
    }

    return ! error_encountered();
}