How to use the colorio.HSL function in colorio

To help you get started, we’ve selected a few colorio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / colorio / test / test_hsl.py View on Github external
def test_reference_srgb(vals, ref):
    hsl = colorio.HSL()
    assert numpy.all(abs(hsl.from_srgb256(vals) - ref) < 1.0e-14 * numpy.array(ref))
    return
github nschloe / colorio / test / test_hsl.py View on Github external
def test_conversion(vals):
    hsl = colorio.HSL()
    out = hsl.to_srgb1(hsl.from_srgb1(vals))
    assert numpy.all(abs(vals - out) < 1.0e-14)
    return
github nschloe / cplot / cplot / main.py View on Github external
100 * absval_scaled,
                rd * numpy.cos(angle + offset),
                rd * numpy.sin(angle + offset),
            ]
        )
        # now just translate to srgb
        srgb_vals = srgb.to_srgb1(srgb.from_xyz100(cielab.to_xyz100(lab_pts)))
        # Cut off the outliers. This restriction makes the representation less perfect,
        # but that's what it is with the SRGB color space.
        srgb_vals[srgb_vals > 1] = 1.0
        srgb_vals[srgb_vals < 0] = 0.0
    else:
        assert (
            colorspace.upper() == "HSL"
        ), f"Illegal colorspace {colorspace}. Pick one of CAM16, CIELAB, HSL."
        hsl = colorio.HSL()
        # rotate by 120 degrees to have green (0, 1, 0) for real positive numbers
        offset = 120
        hsl_vals = numpy.array(
            [
                numpy.mod(angle / (2 * numpy.pi) * 360 + offset, 360),
                numpy.ones(angle.shape),
                absval_scaled,
            ]
        )
        srgb_vals = hsl.to_srgb1(hsl_vals)
        # iron out the -1.82131e-17 round-offs
        srgb_vals[srgb_vals < 0] = 0

    return numpy.moveaxis(srgb_vals, 0, -1)