コード例 #1
0
void ColorSource::initialize_from_spectrum(const ColorEntity& color_entity)
{
    const ColorValueArray& values = color_entity.get_values();

    if (values.empty())
    {
        m_scalar = ScalarInput(0.0);
        m_linear_rgb.set(0.0f);
        m_spectrum.set(0.0f);
        return;
    }

    m_scalar = static_cast<ScalarInput>(values[0]);

    m_spectrum.resize(Spectrum::Samples);
    spectral_values_to_spectrum(
        color_entity.get_wavelength_range()[0],
        color_entity.get_wavelength_range()[1],
        values.size(),
        &values[0],
        &m_spectrum[0]);

    // todo: this should be user-settable.
    const LightingConditions lighting_conditions(
        IlluminantCIED65,
        XYZCMFCIE196410Deg);

    m_linear_rgb = m_spectrum.convert_to_rgb(lighting_conditions);
}
コード例 #2
0
void ColorSource::initialize_from_spectrum(
    const ColorEntity&      color_entity)
{
    const ColorValueArray& values = color_entity.get_values();

    if (values.size() > 0)
    {
        // todo: this should be user-settable.
        const LightingConditions lighting_conditions(
            IlluminantCIED65,
            XYZCMFCIE196410Deg);

        m_scalar = static_cast<double>(values[0]);

        m_spectrum =
            spectral_values_to_spectrum(
                color_entity.get_wavelength_range(),
                values);

        m_linear_rgb =
            ciexyz_to_linear_rgb(
                spectrum_to_ciexyz<float>(lighting_conditions, m_spectrum));
    }
    else
    {
        m_scalar = 0.0;
        m_linear_rgb.set(0.0f);
        m_spectrum.set(0.0f);
    }
}
コード例 #3
0
void ColorSource::initialize_from_3d_color(
    const ColorEntity&      color_entity,
    const InputFormat       input_format)
{
    const ColorValueArray& values = color_entity.get_values();

    if (values.size() == 1)
        m_linear_rgb.set(values[0]);
    else if (values.size() == 3)
        m_linear_rgb = Color3f(values[0], values[1], values[2]);
    else m_linear_rgb.set(0.0f);

    m_scalar = static_cast<double>(m_linear_rgb[0]);

    if (input_format == InputFormatSpectralIlluminance || input_format == InputFormatSpectralReflectance)
    {
        switch (color_entity.get_color_space())
        {
          case ColorSpaceLinearRGB:
            linear_rgb_to_spectrum(
                input_format,
                m_linear_rgb,
                m_spectrum);
            break;

          case ColorSpaceSRGB:
            linear_rgb_to_spectrum(
                input_format,
                srgb_to_linear_rgb(m_linear_rgb),
                m_spectrum);
            break;

          case ColorSpaceCIEXYZ:
            linear_rgb_to_spectrum(
                input_format,
                ciexyz_to_linear_rgb(m_linear_rgb),
                m_spectrum);
            break;

          default:
            assert(!"Invalid color space.");
            break;
        }
    }
    else m_spectrum.set(0.0f);
}
コード例 #4
0
void ColorSource::initialize_from_color3(const ColorEntity& color_entity)
{
    Color3f color;

    const ColorValueArray& values = color_entity.get_values();
    if (values.size() == 1)
        color.set(values[0]);
    else if (values.size() == 3)
        color = Color3f(values[0], values[1], values[2]);
    else
    {
        m_scalar = ScalarInput(0.0);
        m_linear_rgb.set(0.0f);
        m_spectrum.set(0.0f);
        return;
    }

    m_scalar = static_cast<double>(color[0]);

    switch (color_entity.get_color_space())
    {
      case ColorSpaceLinearRGB:
        m_linear_rgb = color;
        break;

      case ColorSpaceSRGB:
        m_linear_rgb = srgb_to_linear_rgb(color);
        break;

      case ColorSpaceCIEXYZ:
        m_linear_rgb = ciexyz_to_linear_rgb(color);
        break;

      default:
        assert(!"Invalid color space.");
        break;
    }

    m_spectrum = m_linear_rgb;
}