コード例 #1
0
    void apply_threshold(const double threshold, Image& image)
    {
        const CanvasProperties& props = image.properties();

        for (size_t y = 0; y < props.m_canvas_height; ++y)
        {
            for (size_t x = 0; x < props.m_canvas_width; ++x)
            {
                Color3f color;
                image.get_pixel(x, y, color);

                if (color[0] < threshold)
                    color.set(0.0f);
                else color.set(1.0f);

                image.set_pixel(x, y, color);
            }
        }
    }
コード例 #2
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;
}