prizm 0.1.0.4 → 0.2.0.0
raw patch · 7 files changed
+67/−2 lines, 7 files
Files
- CHANGES +11/−0
- prizm.cabal +2/−1
- src/Data/Prizm/Color.hs +47/−0
- src/Data/Prizm/Color/CIE.hs +2/−1
- src/Data/Prizm/Color/SRGB.hs +1/−0
- src/Data/Prizm/Types.hs +2/−0
- tests/QC.hs +2/−0
CHANGES view
@@ -1,3 +1,14 @@+0.2.0.0+=======++- Adding in Weighted Blending, Darkening, Lightening, Shading, and+ Tinting functions.++0.1.0.4+=======++- Adding toHex and fromHex functions.+ 0.1.0.3 =======
prizm.cabal view
@@ -1,5 +1,5 @@ Name: prizm-Version: 0.1.0.4+Version: 0.2.0.0 Synopsis: A haskell library for computing with colors Description: Prizm can convert between many different color@@ -35,6 +35,7 @@ default-language: Haskell2010 exposed-modules: Data.Prizm.Types+ Data.Prizm.Color Data.Prizm.Color.Transform Data.Prizm.Color.SRGB Data.Prizm.Color.CIE
+ src/Data/Prizm/Color.hs view
@@ -0,0 +1,47 @@+module Data.Prizm.Color where++import Control.Applicative+import Data.Prizm.Types+import Data.Prizm.Color.CIE as C++pct :: Integer -> Double+pct = (/100) . fromIntegral . (max 0) . (min 100)++pctClamp :: Integer -> Integer+pctClamp i = max (min i 100) 0++-- | Blend two colors using a 50% weighted average.+blend :: (CIEXYZ Double, CIEXYZ Double) -> CIEXYZ Double+blend = blendWeighted 50++-- | Shade a color by blending it using a weight and the color black.+shade :: CIEXYZ Double -> Percent -> CIEXYZ Double+shade c w = blendWeighted (pctClamp w) (CIEXYZ 0.0 0.0 0.0, c)++-- | Tint a color by blending it using a weight and the color white.+tint :: CIEXYZ Double -> Percent -> CIEXYZ Double+tint c w = blendWeighted (pctClamp w) ((CIEXYZ 95.047 100.0 108.883), c)++darken :: CIEXYZ Double -> Percent -> CIEXYZ Double+darken c w =+ let (CIELAB l a b) = C.toLAB c+ l' = l - (l*(pct (pctClamp w)))+ in C.toXYZ (CIELAB l' a b)++lighten :: CIEXYZ Double -> Percent -> CIEXYZ Double+lighten c w =+ let (CIELAB l a b) = C.toLAB c+ l' = l + (l*(pct (pctClamp w)))+ in C.toXYZ (CIELAB l' a b)++-- | Blend using a weighted average for two XYZ colors.+-- +-- Weight are applied left to right, so if a weight of 25% is+-- supplied, then the color on the left will be multiplied by 25% and+-- the second color will be multiplied by 75%.+blendWeighted :: Percent -> (CIEXYZ Double, CIEXYZ Double) -> CIEXYZ Double+blendWeighted w (a,b) =+ let w' = (pct (pctClamp w))+ a1 = (*w') <$> a+ b1 = (*(1.0 - w')) <$> b+ in (+) <$> a1 <*> b1
src/Data/Prizm/Color/CIE.hs view
@@ -9,6 +9,7 @@ import Control.Applicative import Data.Prizm.Types+import Data.Prizm.Color.SRGB (clamp) import Data.Prizm.Color.Transform import Data.Prizm.Color.Matrices.XYZ @@ -52,7 +53,7 @@ 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+ in (clamp) <$> RGB r g b toLAB :: CIEXYZ Double -> CIELAB Double toLAB (CIEXYZ x y z) =
src/Data/Prizm/Color/SRGB.hs view
@@ -4,6 +4,7 @@ , toXYZMatrix , toHex , fromHex+, clamp ) where import Numeric (showHex)
src/Data/Prizm/Types.hs view
@@ -7,6 +7,8 @@ type Hex = String +type Percent = Integer+ data RGB a = RGB !a !a !a deriving (Eq, Ord, Show)
tests/QC.hs view
@@ -4,6 +4,7 @@ import qualified QC.SRGB as SRGB import qualified QC.CIE as CIE+--import qualified QC.Color as Color import Test.Framework (defaultMain, testGroup) @@ -12,4 +13,5 @@ tests = [ testGroup "srgb" SRGB.tests , testGroup "cie" CIE.tests+-- , testGroup "color" Color.tests ]