Skip to content

feat(stdlib): add colorsys module — color space conversions #758

Description

@antonsynd

Summary

Add a colorsys module for converting between color systems (RGB, HSV, HLS, YIQ), matching Python's colorsys module API. Pure math, no dependencies.

Proposed Sharpy API

import colorsys

h, s, v = colorsys.rgb_to_hsv(0.2, 0.4, 0.6)
r, g, b = colorsys.hsv_to_rgb(h, s, v)

h, l, s = colorsys.rgb_to_hls(0.2, 0.4, 0.6)
r, g, b = colorsys.hls_to_rgb(h, l, s)

y, i, q = colorsys.rgb_to_yiq(0.2, 0.4, 0.6)
r, g, b = colorsys.yiq_to_rgb(y, i, q)

Key Decisions

  • All values are floats in [0.0, 1.0] range (matching Python)
  • Hue is in [0.0, 1.0] (not degrees — matching Python)
  • Pure functions, no classes needed
  • Smallest possible module — 6 functions, ~100 lines
  • Match Python's exact formulas for bit-perfect compatibility

Test Plan

  • RGB to HSV roundtrip
  • RGB to HLS roundtrip
  • RGB to YIQ roundtrip
  • Edge cases (black, white, pure colors)
  • Boundary values (0.0, 1.0)
  • Match Python output for known inputs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or requeststdlibStandard library modules

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions