module Data.Colour
(
Colour
,colourConvert
,black
,AlphaColour
,opaque, withOpacity
,transparent
,alphaColourConvert
,alphaChannel
,AffineSpace(..), blend
,ColourOps(..)
,dissolve, atop
)
where
import Data.Char (isAlphaNum, isSpace)
import Data.Colour.Internal
import qualified Data.Colour.SRGB.Linear
import Data.Colour.CIE.Chromaticity (app_prec, infix_prec)
instance (Fractional a, Show a) => Show (Colour a) where
showsPrec :: Int -> Colour a -> ShowS
showsPrec Int
d Colour a
c = Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
app_prec) ShowS
showStr
where
showStr :: ShowS
showStr = String -> ShowS
showString String
linearConstructorQualifiedName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Show a => Int -> a -> ShowS
showsPrec (Int
app_precforall a. Num a => a -> a -> a
+Int
1) a
r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Show a => Int -> a -> ShowS
showsPrec (Int
app_precforall a. Num a => a -> a -> a
+Int
1) a
g)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Show a => Int -> a -> ShowS
showsPrec (Int
app_precforall a. Num a => a -> a -> a
+Int
1) a
b)
Data.Colour.SRGB.Linear.RGB a
r a
g a
b = forall a. Fractional a => Colour a -> RGB a
Data.Colour.SRGB.Linear.toRGB Colour a
c
instance (Fractional a, Read a) => Read (Colour a) where
readsPrec :: Int -> ReadS (Colour a)
readsPrec Int
d String
r = forall a. Bool -> ReadS a -> ReadS a
readParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
app_prec)
(\String
r -> [(forall a. Fractional a => a -> a -> a -> Colour a
Data.Colour.SRGB.Linear.rgb a
r0 a
g0 a
b0,String
t)
|(String
name,String
s) <- String -> [(String, String)]
mylex String
r
,String
name forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String
linearConstructorName
,String
linearConstructorQualifiedName]
,(a
r0,String
s0) <- forall a. Read a => Int -> ReadS a
readsPrec (Int
app_precforall a. Num a => a -> a -> a
+Int
1) String
s
,(a
g0,String
s1) <- forall a. Read a => Int -> ReadS a
readsPrec (Int
app_precforall a. Num a => a -> a -> a
+Int
1) String
s0
,(a
b0,String
t) <- forall a. Read a => Int -> ReadS a
readsPrec (Int
app_precforall a. Num a => a -> a -> a
+Int
1) String
s1]) String
r
where
mylex :: String -> [(String, String)]
mylex = forall (m :: * -> *) a. Monad m => a -> m a
return
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> ([a], [a])
span (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
"._'")
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace
linearConstructorQualifiedName :: String
linearConstructorQualifiedName = String
"Data.Colour.SRGB.Linear.rgb"
linearConstructorName :: String
linearConstructorName = String
"rgb"
instance (Fractional a, Show a, Eq a) => Show (AlphaColour a) where
showsPrec :: Int -> AlphaColour a -> ShowS
showsPrec Int
d AlphaColour a
ac | a
a forall a. Eq a => a -> a -> Bool
== a
0 = String -> ShowS
showString String
"transparent"
| Bool
otherwise = Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
infix_prec) ShowS
showStr
where
showStr :: ShowS
showStr = forall a. Show a => Int -> a -> ShowS
showsPrec (Int
infix_precforall a. Num a => a -> a -> a
+Int
1) Colour a
c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" `withOpacity` "
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec (Int
infix_precforall a. Num a => a -> a -> a
+Int
1) a
a
a :: a
a = forall a. AlphaColour a -> a
alphaChannel AlphaColour a
ac
c :: Colour a
c = forall a. Fractional a => AlphaColour a -> Colour a
colourChannel AlphaColour a
ac
instance (Fractional a, Read a) => Read (AlphaColour a) where
readsPrec :: Int -> ReadS (AlphaColour a)
readsPrec Int
d String
r = [(forall a. Num a => AlphaColour a
transparent,String
s)|(String
"transparent",String
s) <- String -> [(String, String)]
lex String
r]
forall a. [a] -> [a] -> [a]
++ forall a. Bool -> ReadS a -> ReadS a
readParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
infix_prec)
(\String
r -> [(Colour a
c forall a. Num a => Colour a -> a -> AlphaColour a
`withOpacity` a
o,String
s)
|(Colour a
c,String
r0) <- forall a. Read a => Int -> ReadS a
readsPrec (Int
infix_precforall a. Num a => a -> a -> a
+Int
1) String
r
,(String
"`",String
r1) <- String -> [(String, String)]
lex String
r0
,(String
"withOpacity",String
r2) <- String -> [(String, String)]
lex String
r1
,(String
"`",String
r3) <- String -> [(String, String)]
lex String
r2
,(a
o,String
s) <- forall a. Read a => Int -> ReadS a
readsPrec (Int
infix_precforall a. Num a => a -> a -> a
+Int
1) String
r3]) String
r