prizm 0.1.0.2 → 0.1.0.3
raw patch · 7 files changed
+65/−28 lines, 7 files
Files
- CHANGES +8/−0
- README.md +10/−6
- prizm.cabal +1/−1
- src/Data/Prizm/Color/CIE.hs +9/−12
- src/Data/Prizm/Color/SRGB.hs +3/−3
- src/Data/Prizm/Types.hs +31/−5
- tests/QC/SRGB.hs +3/−1
CHANGES view
@@ -1,3 +1,11 @@+0.1.0.3+=======++- Re-defined the CIE types so they are their own separate types+ instead of branch types.+- Implemented instances of Functor and Applicative for all color+ types.+ 0.1.0.2 =======
README.md view
@@ -10,22 +10,26 @@ ## Colour Module There is some overlap with the Haskell Colour Module that already exists; however, this library is filling a couple of-needs the other doesn't satisfy. I also want to have a cleaner API to work with.+needs the other doesn't satisfy. ## Supported Algorithms -- sRGB -> CIE XYZ-- CIE XYZ -> sRGB+- sRGB <-> CIE XYZ+- CIE XYZ <-> CIE L\*a\*b\* ## Roadmap ### 0.1.0.2 Make sure all of the conversion formulas convert losslessly at an acceptable level of precision. -### 1.0.0.0-Implementation of conversions for all the CIE color representations and a converter for HEX to SRGB (trivial).+### 0.1.0.3+All color types should have instances for Functor so fmap can work over their values.+All color types should have instances for Applicative to make computations cleaner. -### 1.1.0.0+### 0.1.0.4+Conversion functions for sRGB to HEX.++### 1.0.0.0 Implementations for - color mixing
prizm.cabal view
@@ -1,5 +1,5 @@ Name: prizm-Version: 0.1.0.2+Version: 0.1.0.3 Synopsis: A haskell library for computing with colors Description: Prizm can convert between many different color
src/Data/Prizm/Color/CIE.hs view
@@ -45,32 +45,29 @@ -- Once I've implemented CIE L*a*b -> XYZ and vice-versa functions -- then I'll introduce the type exhaustively here to handle any CIE -- color -> SRGB conversion.-toRGB :: CIE -> RGB+toRGB :: CIEXYZ Double -> RGB Integer toRGB = (toRGBMatrix d65SRGB) -toRGBMatrix :: XYZtoRGB -> CIE -> RGB-toRGBMatrix m (LAB l a b) = toRGBMatrix m (toXYZ (LAB l a b))-toRGBMatrix m (XYZ x y z) =+toRGBMatrix :: XYZtoRGB -> CIEXYZ Double -> RGB Integer+toRGBMatrix m (CIEXYZ x y z) = let t = ZipList ((/100) <$> [x,y,z]) [r,g,b] = (transformRGB) <$> ((zipTransform t) <$> m) in RGB r g b -toLAB :: CIE -> CIE-toLAB (LAB l a b) = LAB l a b-toLAB (XYZ x y z) =+toLAB :: CIEXYZ Double -> CIELAB Double+toLAB (CIEXYZ x y z) = let v = getZipList $ ZipList ((/) <$> [x,y,z]) <*> ZipList refWhite [tx,ty,tz] = (transformLAB) <$> v l = (116 * ty) - 16 a = 500 * (tx - ty) b = 200 * (ty - tz)- in LAB l a b+ in CIELAB l a b -toXYZ :: CIE -> CIE-toXYZ (XYZ x y z) = XYZ x y z-toXYZ (LAB l a b) =+toXYZ :: CIELAB Double -> CIEXYZ Double+toXYZ (CIELAB l a b) = let y = (l + 16) / 116 x = a / 500 + y z = y - b / 200 [nx,ny,nz] = getZipList $ ((*) <$> ZipList ((transformXYZ) <$> [x,y,z])) <*> ZipList refWhite- in XYZ nx ny nz+ in CIEXYZ nx ny nz
src/Data/Prizm/Color/SRGB.hs view
@@ -19,11 +19,11 @@ ap = 1.0 + 0.055 -- | @toXYZ@ convert an sRGB value to a CIE XYZ value.-toXYZ :: RGB -> CIE+toXYZ :: RGB Integer -> CIEXYZ Double toXYZ = (toXYZMatrix d65SRGB) -toXYZMatrix :: RGBtoXYZ -> RGB -> CIE+toXYZMatrix :: RGBtoXYZ -> RGB Integer -> CIEXYZ Double toXYZMatrix m (RGB r g b) = let t = ZipList (transform <$> [r,g,b]) [x,y,z] = (roundN 3) <$> ((zipTransform t) <$> m)- in XYZ x y z+ in CIEXYZ x y z
src/Data/Prizm/Types.hs view
@@ -1,13 +1,39 @@ module Data.Prizm.Types where +import Control.Applicative+ type RGBtoXYZ = [[Double]] type XYZtoRGB = [[Double]] -data RGB- = RGB Integer Integer Integer+data RGB a = RGB !a !a !a deriving (Eq, Ord, Show) -data CIE- = XYZ Double Double Double- | LAB Double Double Double+data CIEXYZ a = CIEXYZ !a !a !a deriving (Eq, Ord, Show)++data CIELAB a = CIELAB !a !a !a+ deriving (Eq, Ord, Show)++-- | Functor instances+instance Functor RGB where+ fmap f (RGB r g b) = (RGB (f r) (f g) (f b))++instance Functor CIEXYZ where+ fmap f (CIEXYZ x y z) = (CIEXYZ (f x) (f y) (f z))++instance Functor CIELAB where+ fmap f (CIELAB l a b) = (CIELAB (f l) (f a) (f b))++-- | Applicative instances++instance Applicative RGB where+ pure t = RGB t t t+ (RGB f1 f2 f3) <*> (RGB r g b) = (RGB (f1 r) (f2 g) (f3 b))++instance Applicative CIEXYZ where+ pure t = CIEXYZ t t t+ CIEXYZ f1 f2 f3 <*> CIEXYZ x y z = CIEXYZ (f1 x) (f2 y) (f3 z)++instance Applicative CIELAB where+ pure t = CIELAB t t t+ CIELAB f1 f2 f3 <*> CIELAB l a b = CIELAB (f1 l) (f2 a) (f3 b)
tests/QC/SRGB.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE FlexibleInstances #-}+ module QC.SRGB (tests) where import Test.Framework.Providers.QuickCheck2 (testProperty)@@ -9,7 +11,7 @@ import Data.Prizm.Color.CIE as C import Data.Prizm.Types -instance Arbitrary RGB where+instance Arbitrary (RGB Integer) where arbitrary = liftM3 RGB (choose (0, 255)) (choose (0, 255)) (choose (0, 255)) rgb2XYZ v = C.toRGB(S.toXYZ v) == v