{"id":16341184,"url":"https://github.com/lehins/color","last_synced_at":"2025-03-16T15:30:46.699Z","repository":{"id":43651782,"uuid":"208487477","full_name":"lehins/Color","owner":"lehins","description":"Extensive collection of color spaces and color models","archived":false,"fork":false,"pushed_at":"2022-11-29T11:03:02.000Z","size":689,"stargazers_count":57,"open_issues_count":4,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-21T12:41:59.998Z","etag":null,"topics":["cielab","ciexyz","color","color-spaces","colour","colour-spaces","hsi","hsl","hsv","pixel","rgb","srgb","ycbcr"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lehins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-14T18:46:59.000Z","updated_at":"2023-12-19T07:31:04.000Z","dependencies_parsed_at":"2023-01-23T17:45:49.803Z","dependency_job_id":null,"html_url":"https://github.com/lehins/Color","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lehins%2FColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lehins%2FColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lehins%2FColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lehins%2FColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lehins","download_url":"https://codeload.github.com/lehins/Color/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243819103,"owners_count":20352812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cielab","ciexyz","color","color-spaces","colour","colour-spaces","hsi","hsl","hsv","pixel","rgb","srgb","ycbcr"],"created_at":"2024-10-10T23:58:55.796Z","updated_at":"2025-03-16T15:30:46.692Z","avatar_url":"https://github.com/lehins.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Color\n\nA library for dealing with Colors and pixels. It implements arbitrary color space\nconversion, chromatic adaptation and other color manipulations.\n\n## Status\n\n| Language | Github Actions | Coveralls |Gitter.im |\n|:--------:|:--------------:|:---------:|:--------:|\n| ![GitHub top language](https://img.shields.io/github/languages/top/lehins/Color.svg) | [![Build Status](https://github.com/lehins/Color/workflows/Color-CI/badge.svg)](https://github.com/lehins/Color/actions) | [![Coverage Status](https://coveralls.io/repos/github/lehins/Color/badge.svg?branch=master)](https://coveralls.io/github/lehins/Color?branch=master) | [![Join the chat at https://gitter.im/haskell-massiv/Lobby](https://badges.gitter.im/haskell-massiv/Lobby.svg)](https://gitter.im/haskell-massiv/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n|      Package       | Hackage | Nightly | LTS |\n|:-------------------|:-------:|:-------:|:---:|\n|  [`Color`](https://github.com/lehins/Color/tree/master/Color)|                                       [![Hackage](https://img.shields.io/hackage/v/Color.svg)](https://hackage.haskell.org/package/Color)|                                                                                                        [![Nightly](https://www.stackage.org/package/Color/badge/nightly)](https://www.stackage.org/nightly/package/Color)|                                                                                         [![Nightly](https://www.stackage.org/package/Color/badge/lts)](https://www.stackage.org/lts/package/Color)|\n\n## Description\n\nThere is a clear separation between color models, color spaces and alternative\nrepresentations of color spaces. All are distinct at the type level. The goal is to\nprevent mixups of incompatible color types as well as utilize type information for\nconversion between them.\n\nCurrently supported:\n\n* Color models:\n\n  * `Y`\n  * `RGB`\n  * `HSI`\n  * `HSL`\n  * `HSV`\n  * `YCbCr`\n  * `CMYK`\n\n* Color spaces and arbitrary conversions between them:\n\n  * `Y` - luminance\n  * `Y'` - luma\n  * `CIE XYZ`\n  * `CIE L*a*b*`\n  * `DIN99`\n  * `RGB`:\n\n    * `sRGB` - both standardized and derived\n    * `AdobeRGB` - both standardized and derived\n    * ITU: `Rec470`, `Rec601` and `Rec709`\n    * Alternative representations:\n\n      * `HSI`\n      * `HSL`\n      * `HSV`\n      * `YCbCr`\n      * `CMYK`\n\n* Illuminants:\n\n  * CIE1931 - 2 degree observer\n  * CIE1964 - 10 degree observer\n  * Some common alternatives\n\n* Chromatic adaptation:\n\n  * VonKries adaptation with transformations:\n\n      * `VonKries`\n      * `Bradford` (default)\n      * `Fairchild`\n      * `CIECAM02`\n      * `CMCCAT2000`\n\n* Color Standards:\n\n  * RAL\n  * SVG\n\n## Example\n\nHere is a short example how this library can be used. Here we assume a GHCi session that\ncan be started like so:\n\n```shell\n$ stack ghci --package Color\n```\n\n### Perceived lightness\n\nLet's say we need find the perceived lightness as described in [this StackOverflow\nanswer](https://stackoverflow.com/questions/596216/formula-to-determine-perceived-brightness-of-rgb-color/56678483#56678483)\nfor an RGB triple `(128, 255, 65) :: (Word8, Word8, Word8)`.\n\nBefore we can attempt getting the lightness we need to do these two things:\n\n1. Figure out what is the color space of the `RGB` triplet? In particular the `Illuminant`\n   and the `Linearity` of the `RGB` color space.\n2. Convert your `RGB` color to [`CIE\n   L*a*b*`](https://en.wikipedia.org/wiki/CIELAB_color_space) and then we can get the `L*`\n   out, which is the perceived lightness.\n\nMore often than not an RGB image will be encoded in non-linear sRGB color space with 8 bits\nper channel, so we'll use that for this example:\n\n```haskell\nghci\u003e :set -XDataKinds\nghci\u003e import Graphics.Color.Space\nghci\u003e let rgb8 = ColorSRGB 128 255 65 :: Color (SRGB 'NonLinear) Word8\nghci\u003e print rgb8\n\u003cSRGB 'NonLinear:(128,255, 65)\u003e\n```\n\nBefore we convert `sRGB` to `CIE L*a*b*` color space we need to increase the precision to\n`Double`, because for now `Word8` is not supported by the `LAB` color space implementation:\n\n```haskell\nghci\u003e let rgb = toDouble \u003c$\u003e rgb8\nghci\u003e print rgb\n\u003cSRGB 'NonLinear:( 0.5019607843137255, 1.0000000000000000, 0.2549019607843137)\u003e\n```\n\nIn order to convert to another color space without changing the `Illuminant` we can use\n`convertColor` function. So here is how we convert to CIELAB and extract the perceived\nlightness `L*`:\n\n```haskell\nghci\u003e let lab@(ColorLAB l _ _) = convertColor rgb :: Color (LAB D65) Double\nghci\u003e lab\n\u003cLAB * D65:(90.0867507593648500,-65.7999116680496000,74.4643898323530600)\u003e\nghci\u003e l\n90.08675075936485\n```\n\n### Color adaptation\n\nWhen a change of `Illuminant` is also needed during color space conversion we can use\n`convert` function\n\n```haskell\nghci\u003e import Graphics.Color.Adaptation (convert)\nghci\u003e import qualified Graphics.Color.Illuminant.CIE1964 as CIE1964\nghci\u003e let lab@(ColorLAB l _ _) = convert rgb :: Color (LAB 'CIE1964.D50) Double\nghci\u003e lab\n\u003cLAB CIE1964 'D50:(90.2287735564601500,-59.3846969983265500,72.9304679742930800)\u003e\n```\n\n## External resources\n\n* `Color` is on a list of curated [Awesome Colour](https://awesome-colour.org/#haskell)\n  resources.\n\n* While working on this library the [colour-science.org](https://www.colour-science.org/)\n  and their Python implementation of [colour](https://github.com/colour-science/colour)\n  was used extensively as a reference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flehins%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flehins%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flehins%2Fcolor/lists"}