Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color representation #20

Open
p0nce opened this issue Aug 25, 2022 · 5 comments
Open

Color representation #20

p0nce opened this issue Aug 25, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@p0nce
Copy link
Collaborator

p0nce commented Aug 25, 2022

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

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

@p0nce p0nce added the enhancement New feature or request label Oct 19, 2022
@p0nce
Copy link
Collaborator Author

p0nce commented Jan 10, 2023

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
Copy link
Collaborator Author

p0nce commented Mar 26, 2023

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

@p0nce
Copy link
Collaborator Author

p0nce commented Jul 21, 2023

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
Copy link
Collaborator Author

p0nce commented Aug 5, 2023

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
Copy link
Collaborator Author

p0nce commented Oct 13, 2024

Separated into a color package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant