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