user613326
user613326

Reputation: 2180

RGB color to HSL bytes

I've seen some implementations for converting RGB to HSL. Most are accurate and work in both directions.

To me its not important that it will work in 2 directions (no need to put back to RGB) But i want code that returns values from 0 to 255 max, also for the Hue channel. And I wouldnt like to do devisions like Hue/360*250 i am searching for integer based math no Dwords (its for another system), nice would be some kind of boolean logix (and/or/xor)

It should not do any integer or real number based math, the goal is code working only using byte math.

Maybe someone already has found such math when he used code like

  1. c++ or
  2. c# or
  3. python

Which i would be able to translate to c++

Upvotes: 3

Views: 2149

Answers (2)

Ashwini Chaudhary
Ashwini Chaudhary

Reputation: 250881

Checkout the colorsys module, it has methods like:

colorsys.rgb_to_hls(r,g,b)

colorsys.hls_to_rgb(h,l,s)

Upvotes: 5

David Pointer
David Pointer

Reputation: 935

The easyrgb site has many code snippets for color space conversion. Here's the rgb->hsl code.

Upvotes: 1

Related Questions