Skip to content

Commit

Permalink
Merge pull request #149 from diagrams/color
Browse files Browse the repository at this point in the history
Improved `colorToSRGBA` - avoids calls to matrix inverse and multiply.
  • Loading branch information
jeffreyrosenbluth committed Jan 27, 2014
2 parents f80484d + b261900 commit e3a4d37
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/Diagrams/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Diagrams.Attributes (
, Opacity, getOpacity, opacity

-- ** Converting colors
, toRGBAUsingSpace, colorToSRGBA, colorToRGBA
, colorToSRGBA, colorToRGBA

-- * Lines
-- ** Width
Expand All @@ -59,8 +59,8 @@ module Diagrams.Attributes (

import Control.Lens (Setter, sets)
import Data.Colour
import Data.Colour.RGBSpace
import Data.Colour.SRGB (sRGBSpace)
import Data.Colour.RGBSpace (RGB(..))
import Data.Colour.SRGB (toSRGB)
import Data.Default.Class
import Data.Maybe (fromMaybe)
import Data.Monoid.Recommend
Expand Down Expand Up @@ -226,20 +226,14 @@ instance Color FillColor where
toAlphaColour (FillColor c) = toAlphaColour . getLast . getRecommend $ c
fromAlphaColour = FillColor . Commit . Last . fromAlphaColour

-- | Convert to an RGB space while preserving the alpha channel.
toRGBAUsingSpace :: Color c => RGBSpace Double -> c
-> (Double, Double, Double, Double)
toRGBAUsingSpace s col = (r,g,b,a)
where c' = toAlphaColour col
c = toRGBUsingSpace s (alphaToColour c')
a = alphaChannel c'
r = channelRed c
g = channelGreen c
b = channelBlue c

-- | Convert to sRGBA.
colorToSRGBA, colorToRGBA :: Color c => c -> (Double, Double, Double, Double)
colorToSRGBA = toRGBAUsingSpace sRGBSpace
colorToSRGBA col = (r, g, b, a)
where
c' = toAlphaColour col
c = alphaToColour c'
a = alphaChannel c'
RGB r g b = toSRGB c

colorToRGBA = colorToSRGBA
{-# DEPRECATED colorToRGBA "Renamed to colorToSRGBA." #-}
Expand Down

0 comments on commit e3a4d37

Please sign in to comment.