Skip to content

Commit

Permalink
simplified colorToSRGBA
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Jan 26, 2014
1 parent 06382a3 commit d7b3ecc
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

This comment has been minimized.

Copy link
@jeffreyrosenbluth

jeffreyrosenbluth Jan 26, 2014

Author Member

I believe that this function basically duplicates functionality that already exists in Data.Colour.
My understanding is that toRGBUsingSpace is provided for custom color spaces, since Data.Colour provides toSRGB. Which is basically the same function specialized to the sRGB color space. The new version is simpler and equal to the existing one (at least as far as quickCheck can tell.

-- | 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 d7b3ecc

Please sign in to comment.