Content-Length: 43694 | pFad | http://hackage.haskell.org/package/Color

Color: Color spaces and conversions between them

Color: Color spaces and conversions between them

[ bsd3, graphics, library ] [ Propose Tags ] [ Report a vulnerability ]

Please see the README on GitHub at https://github.com/lehins/Color#readme


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.3.1, 0.1.4, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.4.0 (info)
Change log CHANGELOG.md
Dependencies base (>=4.11 && <5), data-default-class, deepseq, vector (>=0.11) [details]
Tested with ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.6, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.6, ghc ==9.8.4, ghc ==9.10.1, ghc ==9.12.1
License BSD-3-Clause
Copyright 2019-2025 Alexey Kuleshevich
Author Alexey Kuleshevich
Maintainer alexey@kuleshevi.ch
Category Graphics
Home page https://github.com/lehins/Color
Source repo head: git clone https://github.com/lehins/Color(Color)
Uploaded by lehins at 2025-01-13T01:23:22Z
Distributions LTSHaskell:0.3.3, NixOS:0.3.3, Stackage:0.3.3
Reverse Dependencies 2 direct, 9 indirect [details]
Downloads 4181 total (71 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-01-13 [all 1 reports]

Readme for Color-0.4.0

[back to package description]

Color

A library for dealing with Colors and pixels. It implements arbitrary color space conversion, chromatic adaptation and other color manipulations.

Status

Language Github Actions Coveralls Gitter.im
GitHub top language Build Status Coverage Status Join the chat at https://gitter.im/haskell-massiv/Lobby
Package Hackage Nightly LTS
Color Hackage Nightly Nightly

Description

There is a clear separation between color models, color spaces and alternative representations of color spaces. All are distinct at the type level. The goal is to prevent mixups of incompatible color types as well as utilize type information for conversion between them.

Currently supported:

  • Color models:

    • Y
    • RGB
    • HSI
    • HSL
    • HSV
    • YCbCr
    • CMYK
  • Color spaces and arbitrary conversions between them:

    • Y - luminance

    • Y' - luma

    • CIE XYZ

    • CIE L*a*b*

    • DIN99

    • RGB:

      • sRGB - both standardized and derived

      • AdobeRGB - both standardized and derived

      • ITU: Rec470, Rec601 and Rec709

      • Alternative representations:

        • HSI
        • HSL
        • HSV
        • YCbCr
        • CMYK
  • Illuminants:

    • CIE1931 - 2 degree observer
    • CIE1964 - 10 degree observer
    • Some common alternatives
  • Chromatic adaptation:

    • VonKries adaptation with transformations:

      • VonKries
      • Bradford (default)
      • Fairchild
      • CIECAM02
      • CMCCAT2000
  • Color Standards:

    • RAL
    • SVG

Example

Here is a short example how this library can be used. Here we assume a GHCi session that can be started like so:

$ stack ghci --package Color

Perceived lightness

Let's say we need find the perceived lightness as described in this StackOverflow answer for an RGB triple (128, 255, 65) :: (Word8, Word8, Word8).

Before we can attempt getting the lightness we need to do these two things:

  1. Figure out what is the color space of the RGB triplet? In particular the Illuminant and the Linearity of the RGB color space.
  2. Convert your RGB color to CIE L*a*b* and then we can get the L* out, which is the perceived lightness.

More often than not an RGB image will be encoded in non-linear sRGB color space with 8 bits per channel, so we'll use that for this example:

ghci> :set -XDataKinds
ghci> import Graphics.Color.Space
ghci> let rgb8 = ColorSRGB 128 255 65 :: Color (SRGB 'NonLinear) Word8
ghci> print rgb8
<SRGB 'NonLinear:(128,255, 65)>

Before we convert sRGB to CIE L*a*b* color space we need to increase the precision to Double, because for now Word8 is not supported by the LAB color space implementation:

ghci> let rgb = toDouble <$> rgb8
ghci> print rgb
<SRGB 'NonLinear:( 0.5019607843137255, 1.0000000000000000, 0.2549019607843137)>

In order to convert to another color space without changing the Illuminant we can use convertColor function. So here is how we convert to CIELAB and extract the perceived lightness L*:

ghci> let lab@(ColorLAB l _ _) = convertColor rgb :: Color (LAB D65) Double
ghci> lab
<LAB * D65:(90.0867507593648500,-65.7999116680496000,74.4643898323530600)>
ghci> l
90.08675075936485

Color adaptation

When a change of Illuminant is also needed during color space conversion we can use convert function

ghci> import Graphics.Color.Adaptation (convert)
ghci> import qualified Graphics.Color.Illuminant.CIE1964 as CIE1964
ghci> let lab@(ColorLAB l _ _) = convert rgb :: Color (LAB 'CIE1964.D50) Double
ghci> lab
<LAB CIE1964 'D50:(90.2287735564601500,-59.3846969983265500,72.9304679742930800)>

External resources









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://hackage.haskell.org/package/Color

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy