prizm 0.1.0.0 → 0.1.0.1
raw patch · 11 files changed
+99/−99 lines, 11 files
Files
- prizm.cabal +6/−6
- src/Data/Prizm.hs +12/−0
- src/Data/Prizm/Color/CIE.hs +33/−0
- src/Data/Prizm/Color/SRGB.hs +30/−0
- src/Data/Prizm/Color/Transform.hs +8/−0
- src/Data/Prizm/Types.hs +10/−0
- src/Prizm.hs +0/−12
- src/Prizm/Color/CIE.hs +0/−33
- src/Prizm/Color/SRGB.hs +0/−30
- src/Prizm/Color/Transform.hs +0/−8
- src/Prizm/Types.hs +0/−10
prizm.cabal view
@@ -1,5 +1,5 @@ Name: prizm-Version: 0.1.0.0+Version: 0.1.0.1 Synopsis: A haskell library for computing with colors Description: Prizm can convert between many different color@@ -33,11 +33,11 @@ hs-source-dirs: src default-language: Haskell2010 exposed-modules:- Prizm- Prizm.Types- Prizm.Color.Transform- Prizm.Color.SRGB- Prizm.Color.CIE+ Data.Prizm+ Data.Prizm.Types+ Data.Prizm.Color.Transform+ Data.Prizm.Color.SRGB+ Data.Prizm.Color.CIE ghc-options: -Wall
+ src/Data/Prizm.hs view
@@ -0,0 +1,12 @@+module Data.Prizm+(+ module Data.Prizm.Types+, module Data.Prizm.Color.Transform+, module Data.Prizm.Color.SRGB+, module Data.Prizm.Color.CIE+) where++import Data.Prizm.Types+import Data.Prizm.Color.Transform+import Data.Prizm.Color.CIE+import Data.Prizm.Color.SRGB
+ src/Data/Prizm/Color/CIE.hs view
@@ -0,0 +1,33 @@+module Data.Prizm.Color.CIE+(+ toRGB+) where++import Data.Prizm.Types+import Data.Prizm.Color.Transform++import Control.Applicative++matrix :: [[Double]]+matrix = [+ [3.2406, (-1.5372), (-0.4986)],+ [(-0.9689), 1.8758, 0.0415],+ [0.0557, (-0.2040), 1.0570]]++-- | @transform@ transform an XYZ integer to be computed against+-- the xyzToRGB matrix.+transform :: Double -> Integer+transform v | v > 0.0031308 = min (truncate ((1.055 * (v ** (1 / 2.4)) - 0.055) * 255)) 255+ | otherwise = min (truncate ((12.92 * v) * 255)) 255++-- | @toRGB@ convert a CIE color to an SRGB color.+-- +-- 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 -> SRGB+--toRGB (LAB _ _ _) = Nothing+toRGB (XYZ x y z) =+ let t = ZipList ((/100) <$> [x,y,z])+ [r,g,b] = (transform) <$> ((zipTransform t) <$> matrix)+ in SRGB r g b
+ src/Data/Prizm/Color/SRGB.hs view
@@ -0,0 +1,30 @@+module Data.Prizm.Color.SRGB+(+ toXYZ+) where++import Data.Prizm.Types+import Data.Prizm.Color.Transform++import Control.Applicative++matrix :: [[Double]]+matrix = [+ [0.4124, 0.3576, 0.1805],+ [0.2126, 0.7152, 0.0722],+ [0.0193, 0.1192, 0.9505]]++-- | @rgbTransform@ transform an RGB integer to be computed against+-- the rgbToXYZ matrix.+transform :: Integer -> Double+transform v | dv > 0.04045 = (((dv + 0.055) / ap) ** 2.4) * 100+ | otherwise = (dv / 12.92) * 100+ where dv = fromIntegral v / 255+ ap = 1.0 + 0.055++-- | @toXYZ@ convert an sRGB value to a CIE XYZ value.+toXYZ :: SRGB -> CIE+toXYZ (SRGB r g b) =+ let t = ZipList (transform <$> [r,g,b])+ [x,y,z] = (zipTransform t) <$> matrix+ in XYZ x y z
+ src/Data/Prizm/Color/Transform.hs view
@@ -0,0 +1,8 @@+{-# LANGUAGE OverloadedStrings #-}++module Data.Prizm.Color.Transform where++import Control.Applicative++zipTransform :: ZipList Double -> [Double] -> Double+zipTransform tv m = sum $ getZipList $ (*) <$> ZipList m <*> tv
+ src/Data/Prizm/Types.hs view
@@ -0,0 +1,10 @@+module Data.Prizm.Types where++data SRGB+ = SRGB Integer Integer Integer+ deriving (Eq, Ord, Show)++data CIE+ = XYZ Double Double Double+-- | LAB Double Double Double+ deriving (Eq, Ord, Show)
− src/Prizm.hs
@@ -1,12 +0,0 @@-module Prizm-(- module Prizm.Types-, module Prizm.Color.Transform-, module Prizm.Color.SRGB-, module Prizm.Color.CIE-) where--import Prizm.Types-import Prizm.Color.Transform-import Prizm.Color.CIE-import Prizm.Color.SRGB
− src/Prizm/Color/CIE.hs
@@ -1,33 +0,0 @@-module Prizm.Color.CIE-(- toRGB-) where--import Prizm.Types-import Prizm.Color.Transform--import Control.Applicative--matrix :: [[Double]]-matrix = [- [3.2406, (-1.5372), (-0.4986)],- [(-0.9689), 1.8758, 0.0415],- [0.0557, (-0.2040), 1.0570]]---- | @transform@ transform an XYZ integer to be computed against--- the xyzToRGB matrix.-transform :: Double -> Integer-transform v | v > 0.0031308 = min (truncate ((1.055 * (v ** (1 / 2.4)) - 0.055) * 255)) 255- | otherwise = min (truncate ((12.92 * v) * 255)) 255---- | @toRGB@ convert a CIE color to an SRGB color.--- --- 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 -> SRGB---toRGB (LAB _ _ _) = Nothing-toRGB (XYZ x y z) =- let t = ZipList ((/100) <$> [x,y,z])- [r,g,b] = (transform) <$> ((zipTransform t) <$> matrix)- in SRGB r g b
− src/Prizm/Color/SRGB.hs
@@ -1,30 +0,0 @@-module Prizm.Color.SRGB-(- toXYZ-) where--import Prizm.Types-import Prizm.Color.Transform--import Control.Applicative--matrix :: [[Double]]-matrix = [- [0.4124, 0.3576, 0.1805],- [0.2126, 0.7152, 0.0722],- [0.0193, 0.1192, 0.9505]]---- | @rgbTransform@ transform an RGB integer to be computed against--- the rgbToXYZ matrix.-transform :: Integer -> Double-transform v | dv > 0.04045 = (((dv + 0.055) / ap) ** 2.4) * 100- | otherwise = (dv / 12.92) * 100- where dv = fromIntegral v / 255- ap = 1.0 + 0.055---- | @toXYZ@ convert an sRGB value to a CIE XYZ value.-toXYZ :: SRGB -> CIE-toXYZ (SRGB r g b) =- let t = ZipList (transform <$> [r,g,b])- [x,y,z] = (zipTransform t) <$> matrix- in XYZ x y z
− src/Prizm/Color/Transform.hs
@@ -1,8 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}--module Prizm.Color.Transform where--import Control.Applicative--zipTransform :: ZipList Double -> [Double] -> Double-zipTransform tv m = sum $ getZipList $ (*) <$> ZipList m <*> tv
− src/Prizm/Types.hs
@@ -1,10 +0,0 @@-module Prizm.Types where--data SRGB- = SRGB Integer Integer Integer- deriving (Eq, Ord, Show)--data CIE- = XYZ Double Double Double--- | LAB Double Double Double- deriving (Eq, Ord, Show)