Skip to content

Commit

Permalink
Add channelRgbColors
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Nov 29, 2024
1 parent 4cac25c commit c9f0d68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Color/src/Graphics/Color/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
--
module Graphics.Color.Model
( ColorModel(..)
, channelRgbColors
-- * Alpha
, Alpha
, Opaque
Expand Down Expand Up @@ -50,3 +51,13 @@ import Graphics.Color.Model.Internal
import Graphics.Color.Model.RGB
import Graphics.Color.Model.X
import Graphics.Color.Model.YCbCr
import Data.Coerce
import Data.Proxy
import Data.List.NonEmpty

-- | Uses `channelColors` to produce actual `RGB` colors for each
-- channel. Useful for plotting.
--
-- @0.4.0
channelRgbColors :: ColorModel cs e => Proxy (Color cs e) -> NonEmpty (Color RGB Word8)
channelRgbColors = coerce . channelColors
12 changes: 7 additions & 5 deletions Color/src/Graphics/Color/Space/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ class (Illuminant i, ColorModel (BaseModel cs) e, ColorModel cs e) =>
-- @since 0.1.0
luminance :: (Elevator a, RealFloat a) => Color cs e -> Color (Y i) a

-- | Drop chromatic information and get only the grayscale information from the
-- color. Without knowledge of the source color the produced value is inconsequential.
-- | Drop chromatic information and get only the grayscale information from
-- the color. Without knowledge of the source color the produced value is
-- inconsequential, becaus each class of color spaces has its own notion of
-- grayscale (luma, luminocity, in linear or non-linear form, etc.)
--
-- @since 0.3.1
-- @since 0.4.0
grayscale :: Color cs e -> Color X e

-- | Replace the grayscale information, leaving the chromatic portion of the coloer
Expand All @@ -119,7 +121,7 @@ class (Illuminant i, ColorModel (BaseModel cs) e, ColorModel cs e) =>
--
-- > replaceGrayscale c y = applyGrayscale c (const y)
--
-- @since 0.3.1
-- @since 0.4.0
replaceGrayscale :: Color cs e -> Color X e -> Color cs e
replaceGrayscale c y = applyGrayscale c (const y)
{-# INLINE replaceGrayscale #-}
Expand All @@ -132,7 +134,7 @@ class (Illuminant i, ColorModel (BaseModel cs) e, ColorModel cs e) =>
--
-- > applyGrayscale c f = replaceGrayscale c (f (grayscale c))
--
-- @since 0.3.1
-- @since 0.4.0
applyGrayscale :: Color cs e -> (Color X e -> Color X e) -> Color cs e
applyGrayscale c f = replaceGrayscale c (f (grayscale c))
{-# INLINE applyGrayscale #-}
Expand Down

0 comments on commit c9f0d68

Please sign in to comment.