gamut icon indicating copy to clipboard operation
gamut copied to clipboard

Color representation

Open p0nce opened this issue 3 years ago • 6 comments

a struct that represent a color, in various color spaces.

When we write image.fillWithColor(col);, col is converted to the right space.

p0nce avatar Aug 25 '22 08:08 p0nce

Will be hard to replace dplug:graphics without it since in dplug:graphics you can assign pixels with a RGBA() struct, but the image is monomorphic. Should the struct be there?

p0nce avatar Jan 10 '23 11:01 p0nce

The original code from Manu isn't bad at all... a bit templatey maybe

p0nce avatar Mar 26 '23 13:03 p0nce

But we need a ICC profile parser too. Could be basis for colorspace. ICC parsing and acting on it could bring support for XYB JPEGs.

p0nce avatar Jul 21 '23 08:07 p0nce

Color API out there:

raylib: (only sRGB)

    Color Fade(Color color, float alpha);                                 // Get color with alpha applied, alpha goes from 0.0f to 1.0f
    int ColorToInt(Color color);                                          // Get hexadecimal value for a Color
    Vector4 ColorNormalize(Color color);                                  // Get Color normalized as float [0..1]
    Color ColorFromNormalized(Vector4 normalized);                        // Get Color from normalized values [0..1]
    Vector3 ColorToHSV(Color color);                                      // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
    Color ColorFromHSV(float hue, float saturation, float value);         // Get a Color from HSV values, hue [0..360], saturation/value [0..1]
    Color ColorTint(Color color, Color tint);                             // Get color multiplied with another color
    Color ColorBrightness(Color color, float factor);                     // Get color with brightness correction, brightness factor goes from -1.0f to 1.0f
    Color ColorContrast(Color color, float contrast);                     // Get color with contrast correction, contrast values between -1.0f and 1.0f
    Color ColorAlpha(Color color, float alpha);                           // Get color with alpha applied, alpha goes from 0.0f to 1.0f
    Color ColorAlphaBlend(Color dst, Color src, Color tint);              // Get src alpha-blended into dst color with tint
    Color GetColor(unsigned int hexValue);                                // Get Color structure from hexadecimal value
    Color GetPixelColor(void *srcPtr, int format);                        // Get Color from a source pixel pointer of certain format
    void SetPixelColor(void *dstPtr, Color color, int format);            // Set color formatted into destination pixel pointer
    int GetPixelDataSize(int width, int height, int format);              // Get pixel data size in bytes for certain format

CSS color-mod CSS defines and allows all kinds of colorspaces, such as sRGB, Lch, oklab, Rec2020...

.box {
  color: color-mod(purple lightness(62%) red(218) blue(202) whiteness(25%));
  color: color-mod(hotpink blend(yellow 59%));
}

Here’s a list of available color adjusters:

alpha: A value for the alpha-transparency between 0% and 100%.
red, green & blue: A value between 0 and 255. Given a starting color of rgb(140, 254, 255), the starting red value would be 140, so anything higher than 140 increases the amount of red in the color and anything lower than 140 decreases the amount of red in color. Green and blue work the same way, with affecting their respective color.
blackness & whiteness: A value between 0% and 100%.
contrast: A value between 0% and 100%.
saturation: A value between 0% and 100%. 0% is gray.
lightness: A value between 0% and 100%. 0% is black, and 100% is white.
tint: A value between 0% and 100%.
hue: A value between 0 and 360.
shade: A value between 0% and 100%. 100% is black.
blend: Blend makes it easy to blend a color with another color. Here’s an example if it’s usage:

p0nce avatar Aug 05 '23 13:08 p0nce