prizm (empty) → 0.1.0.0
raw patch · 9 files changed
+197/−0 lines, 9 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +28/−0
- README.md +30/−0
- Setup.hs +2/−0
- prizm.cabal +44/−0
- src/Prizm.hs +12/−0
- src/Prizm/Color/CIE.hs +33/−0
- src/Prizm/Color/SRGB.hs +30/−0
- src/Prizm/Color/Transform.hs +8/−0
- src/Prizm/Types.hs +10/−0
+ LICENSE view
@@ -0,0 +1,28 @@+Copyright (c) 2013, Parnell Springmeyer+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++ - Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+ - Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in+ the documentation and/or other materials provided with the+ distribution.+ - Neither the name of the Parnell Springmeyer nor the names of its+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,30 @@+Welcome!+=====++Prizm is a haskell library for dealing with colors. Please contribute!++My inspiration for writing this was Sass and Bourbon, both implement interesting color handling functions for+use in stylesheets and I wanted the same thing for use in [Clay](http://fvisser.nl/clay/) (also for+[Bentonite](https://github.com/ixmatus/bentonite)).++## Supported Algorithms++- sRGB -> CIE XYZ+- CIE XYZ -> sRGB++## Roadmap++### 1.0.0+Implementation of conversions for all the CIE color representations and a converter for HEX to SRGB (trivial).++### 1.1.0+Implementations for++- color mixing+- tint / shade+- darken / lighten+- hue+- saturation+- inversion++[Conversion Algorithm Sources](http://www.easyrgb.com/index.php?X=MATH&H=01)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ prizm.cabal view
@@ -0,0 +1,44 @@+Name: prizm+Version: 0.1.0.0+Synopsis: A haskell library for computing with colors++Description: Prizm can convert between many different color+ representations; notably the sRGB and CIE+ representations. Future versions will+ implementations for mutating colors as well.++Homepage: https://github.com/ixmatus/prizm+License: BSD3+License-file: LICENSE+Author: Parnell Springmeyer+Maintainer: ixmatus@gmail.com+Copyright: (c) 2013 Parnell Springmeyer+Category: Graphics+Build-type: Simple+Stability: alpha+Bug-reports: https://github.com/ixmatus/prizm/issues+Package-url: http://hackage.haskell.org/package/prizm+Tested-with: GHC == 7.4.2+Cabal-version: >=1.14.0++extra-source-files:+ LICENSE+ README.md++source-repository head+ type: git+ location: https://github.com/ixmatus/prizm++library+ hs-source-dirs: src+ default-language: Haskell2010+ exposed-modules:+ Prizm+ Prizm.Types+ Prizm.Color.Transform+ Prizm.Color.SRGB+ Prizm.Color.CIE+ + ghc-options: -Wall+ + build-depends: base ==4.5.*
+ src/Prizm.hs view
@@ -0,0 +1,12 @@+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 view
@@ -0,0 +1,33 @@+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 view
@@ -0,0 +1,30 @@+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 view
@@ -0,0 +1,8 @@+{-# 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 view
@@ -0,0 +1,10 @@+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)