prizm 1.0.5 → 1.1.0
raw patch · 6 files changed
+39/−32 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Prizm.Color.CIE: instance Data.Convertible.Base.Convertible Data.Prizm.Types.Hex Data.Prizm.Types.CIELCH
+ Data.Prizm.Color.CIE: instance Data.Convertible.Base.Convertible Data.Prizm.Types.RGB Data.Prizm.Types.CIELCH
- Data.Prizm.Color.SRGB: clamp :: Word8 -> Word8
+ Data.Prizm.Color.SRGB: clamp :: Integral a => a -> a
Files
- prizm.cabal +2/−2
- src/Data/Prizm/Color/CIE.hs +19/−11
- src/Data/Prizm/Color/SRGB.hs +1/−2
- src/Data/Prizm/Types.hs +1/−1
- tests/QC.hs +0/−16
- tests/Test.hs +16/−0
prizm.cabal view
@@ -1,5 +1,5 @@ name: prizm-version: 1.0.5+version: 1.1.0 synopsis: Color transformations in different color spaces homepage: https://github.com/ixmatus/prizm license: BSD3@@ -98,7 +98,7 @@ test-suite tests type: exitcode-stdio-1.0 hs-source-dirs: tests- main-is: QC.hs+ main-is: Test.hs default-language: Haskell2010 other-modules: QC.SRGB
src/Data/Prizm/Color/CIE.hs view
@@ -40,17 +40,16 @@ black = CIELCH 100.0 0.0 360.0 instance BlendableColor CIELCH where- -- | Interpolate two colors in the @CIE L*Ch* color space with a+ -- | Interpolate two colors in the @CIE L*C*h@ color space with a -- weight. -- -- Weight is 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%. interpolate w ((CIELCH al ac ah), (CIELCH bl bc bh)) =- let w' = pct $ pctClamp w- (CIELCH l c h) = (CIELCH (al - bl) (ac - bc) (ah - bh))- (CIELCH nl nc nh) = omap (*w') (CIELCH l c (shortestPath h))- in CIELCH (nl + al) (nc + ac) (nh + ah)+ let w' = pct w+ (CIELCH nl nc nh) = omap (*w') (CIELCH (bl - al) (bc - ac) (shortestPath (bh - ah)))+ in CIELCH (al + nl) (ac + nc) (ah + nh) instance AdjustableColor CIELCH where -- | Adjust the lightness / darkness of a color.@@ -82,7 +81,6 @@ v2 :: Double v2 = 1/3 * ((29/6) ** 2) - -- | Reference white, 2deg observer, d65 illuminant. -- -- @[x,y,z]@@@ -120,8 +118,8 @@ -- | Transform an 'CIEXYZ' 'Double' to be computed against the -- xyzToRGB matrix. transformRGB :: Double -> Integer-transformRGB v | v > 0.0031308 = min (round ((1.055 * (v ** (1 / 2.4)) - 0.055) * 255)) 255- | otherwise = min (round ((12.92 * v) * 255)) 255+transformRGB v | v > 0.0031308 = min (round (255 * (1.055 * (v ** (1 / 2.4)) - 0.055))) 255+ | otherwise = min (round (255 * (12.92 * v))) 255 -- | Convert an XYZ color to an SRGB color. --@@ -130,7 +128,9 @@ toRGBMatrix :: XYZtoRGB -> CIEXYZ -> RGB toRGBMatrix (XYZtoRGB m) (CIEXYZ x y z) = let t = ZipList ((/100) <$> [x,y,z])- [r,g,b] = S.clamp <$> (fromIntegral . transformRGB) <$> ((zipTransform t) <$> m)+ -- NB: be sure to clamp before converting to a Word8,+ -- otherwise we can overflow!+ [r,g,b] = (fromIntegral . S.clamp . transformRGB) <$> ((zipTransform t) <$> m) in RGB r g b ------------------------------------------------------------------------------@@ -150,7 +150,7 @@ let y = (l + 16) / 116 x = a / 500 + y z = y - b / 200- [nx,ny,nz] = getZipList $ ((*) <$> ZipList ((transformXYZ) <$> [x,y,z])) <*> ZipList refWhite+ [nx,ny,nz] = getZipList $ ((*) <$> ZipList (transformXYZ <$> [x,y,z])) <*> ZipList refWhite in Right $ CIEXYZ nx ny nz instance Convertible CIELAB RGB where@@ -165,10 +165,18 @@ -- | Convert a S'RGB' to a 'CIELAB' safeConvert = convertVia (undefined :: CIEXYZ) +instance Convertible RGB CIELCH where+ -- | Convert a S'RGB' to a 'CIELCH'+ safeConvert = convertVia (undefined :: CIELAB)+ instance Convertible Hex CIELAB where -- | Convert an S'RGB' hexadecimal color to a 'CIELAB' safeConvert = convertVia (undefined :: RGB) +instance Convertible Hex CIELCH where+ -- | Convert an S'RGB' hexadecimal color to a 'CIELCH'+ safeConvert = convertVia (undefined :: RGB)+ instance Convertible CIELCH CIELAB where -- | Convert a 'CIELCH' to a 'CIELAB' safeConvert (CIELCH l c h) =@@ -177,7 +185,7 @@ instance Convertible CIELCH RGB where -- | Convert a 'CIELCH' to a S'RGB'- safeConvert = convertVia (undefined :: CIEXYZ)+ safeConvert = convertVia (undefined :: CIELAB) instance Convertible CIELCH CIEXYZ where safeConvert = convertVia (undefined :: CIELAB)
src/Data/Prizm/Color/SRGB.hs view
@@ -30,7 +30,6 @@ import Data.String import qualified Data.Text as T import Data.Text.Read as R-import Data.Word import Numeric (showHex) instance PresetColor RGB where@@ -49,7 +48,7 @@ -- | Clamp a 'Word8' with an upper-bound of 255 (the maximum RGB -- value).-clamp :: Word8 -> Word8+clamp :: Integral a => a -> a clamp i = max (min i 255) 0 -- All credit for the below three functions go to the HSColour module.
src/Data/Prizm/Types.hs view
@@ -119,7 +119,7 @@ pct :: Percent -> Double pct i = fromIntegral m / 100 where- m = max (-100) $ min 100 i+ m = pctClamp i -- | Clamp a @Percent@ value in the range -100 to 100. pctClamp :: Percent -> Percent
− tests/QC.hs
@@ -1,16 +0,0 @@-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--module Main (main) where--import qualified QC.CIE as CIE-import qualified QC.SRGB as SRGB-import Test.Framework (Test, defaultMain, testGroup)--main :: IO ()-main = defaultMain tests--tests :: [Test]-tests =- [ testGroup "SRGB" SRGB.tests- , testGroup "CIE" CIE.tests- ]
+ tests/Test.hs view
@@ -0,0 +1,16 @@+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}++module Main (main) where++import qualified QC.CIE as CIE+import qualified QC.SRGB as SRGB+import Test.Framework (Test, defaultMain, testGroup)++main :: IO ()+main = defaultMain tests++tests :: [Test]+tests =+ [ testGroup "SRGB" SRGB.tests+ , testGroup "CIE" CIE.tests+ ]