Skip to content

Commit 422e3bf

Browse files
authored
Merge pull request #12 from lehins/apply-luma
Apply luma
2 parents a91cb90 + 5681ca4 commit 422e3bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1003
-176
lines changed

.github/workflows/haskell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ jobs:
209209
if: steps.install-doctest.outcome == 'success'
210210
run: |
211211
set -ex
212-
cabal repl Color --build-depends=QuickCheck --build-depends=JuicyPixels --build-depends=QuickCheck --with-compiler=doctest --repl-options='-w -Wdefault'
212+
./scripts/doctest.sh
213213
214214
- name: Check Cabal Files
215215
run: |

Color/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog for Color
22

3+
## 0.4.0
4+
5+
* Addition of `DIN99` color space.
6+
* Scale `L*a*b*` color space to `[0, 1]` range from the more common `[0, 100]` for
7+
consistency.
8+
* Addition of: `toGrayscale`, `applyGrayscale` and `replaceGrayscale`.
9+
* Addition of: `ChannelCount`, `channelCount`, `channelNames` and `channelColors`
10+
* Remove `RealFloat` constraint from `ColorSpace` for `Y'`
11+
312
## 0.3.3
413

514
Addition of `SVG` colors

Color/Color.cabal

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: Color
2-
version: 0.3.3
2+
version: 0.4.0
33
synopsis: Color spaces and conversions between them
44
description: Please see the README on GitHub at <https://github.com/lehins/Color#readme>
55
homepage: https://github.com/lehins/Color
66
license: BSD3
77
license-file: LICENSE
88
author: Alexey Kuleshevich
99
maintainer: alexey@kuleshevi.ch
10-
copyright: 2019-2021 Alexey Kuleshevich
10+
copyright: 2019-2025 Alexey Kuleshevich
1111
category: Graphics
1212
extra-source-files: README.md
1313
, CHANGELOG.md
@@ -182,6 +182,19 @@ benchmark conversion
182182
, random
183183
default-language: Haskell2010
184184

185+
benchmark ycbcr
186+
type: exitcode-stdio-1.0
187+
hs-source-dirs: bench
188+
main-is: YCbCr.hs
189+
ghc-options: -Wall
190+
-threaded
191+
-O2
192+
build-depends: base
193+
, criterion
194+
, Color
195+
, deepseq
196+
default-language: Haskell2010
197+
185198
source-repository head
186199
type: git
187200
location: https://github.com/lehins/Color

Color/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright Alexey Kuleshevich (c) 2019-2020
1+
Copyright Alexey Kuleshevich (c) 2019-2025
22

33
All rights reserved.
44

Color/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Currently supported:
3838
* `Y'` - luma
3939
* `CIE XYZ`
4040
* `CIE L*a*b*`
41+
* `DIN99`
4142
* `RGB`:
4243

4344
* `sRGB` - both standardized and derived

Color/bench/YCbCr.hs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE PolyKinds #-}
3+
{-# LANGUAGE FlexibleContexts #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
5+
module Main where
6+
7+
import Criterion.Main
8+
import Control.DeepSeq
9+
import qualified Graphics.Color.Model as CM
10+
import Graphics.Color.Space
11+
import Graphics.Color.Space.RGB.ITU.Rec601
12+
import Graphics.Color.Space.RGB.ITU.Rec709
13+
import Data.Coerce
14+
15+
main :: IO ()
16+
main = do
17+
defaultMain
18+
[ bgroup
19+
"toYCbCr"
20+
[ toYCbCrBench (CM.ColorRGB 0.1 0.2 0.3 :: Color CM.RGB Float) "Float"
21+
, toYCbCrBench (CM.ColorRGB 0.1 0.2 0.3 :: Color CM.RGB Double) "Double"
22+
]
23+
, bgroup
24+
"fromYCbCr"
25+
[ fromYCbCrBench (CM.ColorYCbCr 0.1 0.2 0.3 :: Color CM.YCbCr Float) "Float"
26+
, fromYCbCrBench (CM.ColorYCbCr 0.1 0.2 0.3 :: Color CM.YCbCr Double) "Double"
27+
]
28+
]
29+
30+
31+
toYCbCrBench ::
32+
forall e. (Elevator e, NFData e)
33+
=> Color CM.RGB e
34+
-> String
35+
-> Benchmark
36+
toYCbCrBench rgb tyName =
37+
bgroup
38+
tyName
39+
[ bgroup
40+
"Standard"
41+
[ bench "SRGB" $
42+
nf (fromBaseSpace :: Color (SRGB 'NonLinear) e -> Color (Y'CbCr SRGB) e) (mkColorRGB rgb)
43+
, bench "Rec601" $
44+
nf
45+
(fromBaseSpace :: Color (BT601_625 'NonLinear) e -> Color (Y'CbCr BT601_625) e)
46+
(mkColorRGB rgb)
47+
, bench "Rec709" $
48+
nf (fromBaseSpace :: Color (BT709 'NonLinear) e -> Color (Y'CbCr BT709) e) (mkColorRGB rgb)
49+
]
50+
]
51+
52+
fromYCbCrBench ::
53+
forall e. (Elevator e, NFData e)
54+
=> Color CM.YCbCr e
55+
-> String
56+
-> Benchmark
57+
fromYCbCrBench ycbcr tyName =
58+
bgroup
59+
tyName
60+
[ bgroup
61+
"Standard"
62+
[ bench "SRGB" $
63+
nf (toBaseSpace :: Color (Y'CbCr SRGB) e -> Color (SRGB 'NonLinear) e) (coerce ycbcr)
64+
, bench "Rec601" $
65+
nf
66+
(toBaseSpace :: Color (Y'CbCr BT601_625) e -> Color (BT601_625 'NonLinear) e)
67+
(coerce ycbcr)
68+
, bench "Rec709" $
69+
nf (toBaseSpace :: Color (Y'CbCr BT709) e -> Color (BT709 'NonLinear) e) (coerce ycbcr)
70+
]
71+
]

Color/src/Graphics/Color/Adaptation.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- |
22
-- Module : Graphics.Color.Adaptation
3-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
3+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
44
-- License : BSD3
55
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
66
-- Stability : experimental

Color/src/Graphics/Color/Adaptation/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{-# LANGUAGE TypeOperators #-}
88
-- |
99
-- Module : Graphics.Color.Adaptation.Internal
10-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
10+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
1111
-- License : BSD3
1212
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1313
-- Stability : experimental

Color/src/Graphics/Color/Adaptation/VonKries.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#endif
1515
-- |
1616
-- Module : Graphics.Color.Adaptation.VonKries
17-
-- Copyright : (c) Alexey Kuleshevich 2018-2020
17+
-- Copyright : (c) Alexey Kuleshevich 2018-2025
1818
-- License : BSD3
1919
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
2020
-- Stability : experimental

Color/src/Graphics/Color/Algebra.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
-- |
66
-- Module : Graphics.Color.Algebra
7-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
7+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
88
-- License : BSD3
99
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1010
-- Stability : experimental

Color/src/Graphics/Color/Algebra/Binary.hs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{-# LANGUAGE TypeFamilies #-}
99
-- |
1010
-- Module : Graphics.Color.Algebra.Binary
11-
-- Copyright : (c) Alexey Kuleshevich 2018-2020
11+
-- Copyright : (c) Alexey Kuleshevich 2018-2025
1212
-- License : BSD3
1313
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1414
-- Stability : experimental
@@ -31,7 +31,7 @@ import qualified Data.Vector.Unboxed as U
3131
import Foreign.Storable
3232
import Graphics.Color.Algebra.Elevator
3333
import Prelude hiding (map)
34-
34+
import Data.Coerce
3535

3636
-- | Under the hood, binary pixels are backed by `Word8`, but can only take
3737
-- values of @0@ or @1@. Use `zero`\/`one` to construct a bit and `on`\/`off` to
@@ -43,35 +43,32 @@ instance Show Bit where
4343
show (Bit 0) = "0"
4444
show _ = "1"
4545

46+
cf :: (Word8 -> Word8) -> Bit -> Bit
47+
cf = coerce
48+
49+
cf2 :: (Word8 -> Word8 -> Word8) -> Bit -> Bit -> Bit
50+
cf2 = coerce
4651

4752
instance Bits Bit where
48-
(Bit 0) .&. _ = Bit 0
49-
(Bit 1) .&. (Bit 1) = Bit 1
50-
_ .&. (Bit 0) = Bit 0
51-
_ .&. _ = Bit 1
53+
(.&.) = cf2 (.&.)
5254
{-# INLINE (.&.) #-}
53-
(Bit 1) .|. _ = Bit 1
54-
(Bit 0) .|. (Bit 0) = Bit 0
55-
_ .|. _ = Bit 1
55+
(.|.) = cf2 (.|.)
5656
{-# INLINE (.|.) #-}
57-
(Bit 0) `xor` (Bit 0) = Bit 0
58-
(Bit 1) `xor` (Bit 1) = Bit 0
59-
_ `xor` _ = Bit 1
57+
xor = cf2 xor
6058
{-# INLINE xor #-}
61-
complement (Bit 0) = Bit 1
62-
complement _ = Bit 0
59+
complement = cf complement
6360
{-# INLINE complement #-}
6461
shift !b 0 = b
6562
shift _ _ = Bit 0
6663
{-# INLINE shift #-}
6764
rotate !b _ = b
6865
{-# INLINE rotate #-}
69-
zeroBits = Bit 0
66+
zeroBits = zero
7067
{-# INLINE zeroBits #-}
71-
bit 0 = Bit 1
72-
bit _ = Bit 0
68+
bit 0 = one
69+
bit _ = zero
7370
{-# INLINE bit #-}
74-
testBit (Bit 1) 0 = True
71+
testBit (Bit b) 0 = b /= 0
7572
testBit _ _ = False
7673
{-# INLINE testBit #-}
7774
bitSizeMaybe _ = Just 1
@@ -119,24 +116,23 @@ fromNum _ = one
119116

120117

121118
zero :: Bit
122-
zero = Bit 0
119+
zero = coerce (0x00 :: Word8)
123120
{-# INLINE zero #-}
124121

125122
one :: Bit
126-
one = Bit 1
123+
one = coerce (0xff :: Word8)
127124
{-# INLINE one #-}
128125

129126

130127
-- | Values: @0@ and @1@
131128
instance Elevator Bit where
132-
minValue = Bit 0
129+
minValue = Bit 0x00
133130
{-# INLINE minValue #-}
134-
maxValue = Bit 1
131+
maxValue = Bit 0xff
135132
{-# INLINE maxValue #-}
136133
toShowS (Bit 0) = ('0':)
137134
toShowS _ = ('1':)
138-
toWord8 (Bit 0) = 0
139-
toWord8 _ = maxBound
135+
toWord8 = coerce
140136
{-# INLINE toWord8 #-}
141137
toWord16 (Bit 0) = 0
142138
toWord16 _ = maxBound
@@ -153,10 +149,10 @@ instance Elevator Bit where
153149
toRealFloat (Bit 0) = 0
154150
toRealFloat _ = 1
155151
{-# INLINE toRealFloat #-}
156-
fromRealFloat 0 = Bit 0
157-
fromRealFloat _ = Bit 1
152+
fromRealFloat 0 = zero
153+
fromRealFloat _ = one
158154
{-# INLINE fromRealFloat #-}
159-
(//) (Bit x) (Bit y) = Bit (x `div` y)
155+
(//) = cf2 div
160156
{-# INLINE (//) #-}
161157

162158

@@ -167,18 +163,18 @@ instance Num Bit where
167163
-- 0 - 1 = 0
168164
-- 1 - 0 = 1
169165
-- 1 - 1 = 0
170-
(Bit 0) - (Bit 0) = Bit 0
171-
_ - (Bit 0) = Bit 1
172-
_ - _ = Bit 0
166+
(Bit 0) - (Bit 0) = zero
167+
_ - (Bit 0) = one
168+
_ - _ = zero
173169
{-# INLINE (-) #-}
174170
(*) = (.&.)
175171
{-# INLINE (*) #-}
176172
abs = id
177173
{-# INLINE abs #-}
178174
signum = id
179175
{-# INLINE signum #-}
180-
fromInteger 0 = Bit 0
181-
fromInteger _ = Bit 1
176+
fromInteger 0 = zero
177+
fromInteger _ = one
182178
{-# INLINE fromInteger #-}
183179

184180
-- | Unboxing of a `Bit`.

Color/src/Graphics/Color/Algebra/Elevator.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{-# LANGUAGE ScopedTypeVariables #-}
66
-- |
77
-- Module : Graphics.Color.Algebra.Elevator
8-
-- Copyright : (c) Alexey Kuleshevich 2018-2020
8+
-- Copyright : (c) Alexey Kuleshevich 2018-2025
99
-- License : BSD3
1010
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1111
-- Stability : experimental

Color/src/Graphics/Color/Illuminant/CIE1931.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{-# LANGUAGE DataKinds #-}
55
-- |
66
-- Module : Graphics.Color.Illuminant.CIE1931
7-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
7+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
88
-- License : BSD3
99
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1010
-- Stability : experimental

Color/src/Graphics/Color/Illuminant/CIE1964.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{-# LANGUAGE TypeFamilies #-}
44
-- |
55
-- Module : Graphics.Color.Illuminant.CIE1964
6-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
6+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
77
-- License : BSD3
88
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
99
-- Stability : experimental

Color/src/Graphics/Color/Illuminant/ICC/PCS.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{-# LANGUAGE DataKinds #-}
55
-- |
66
-- Module : Graphics.Color.Illuminant.ICC.PCS
7-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
7+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
88
-- License : BSD3
99
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1010
-- Stability : experimental

Color/src/Graphics/Color/Illuminant/ITU/Rec470.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{-# LANGUAGE DataKinds #-}
55
-- |
66
-- Module : Graphics.Color.Illuminant.ITU.Rec470
7-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
7+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
88
-- License : BSD3
99
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1010
-- Stability : experimental

Color/src/Graphics/Color/Illuminant/ITU/Rec601.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{-# LANGUAGE DataKinds #-}
55
-- |
66
-- Module : Graphics.Color.Illuminant.ITU.Rec601
7-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
7+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
88
-- License : BSD3
99
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1010
-- Stability : experimental

Color/src/Graphics/Color/Illuminant/Wikipedia.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{-# LANGUAGE DataKinds #-}
55
-- |
66
-- Module : Graphics.Color.Illuminant.Wikipedia
7-
-- Copyright : (c) Alexey Kuleshevich 2019-2020
7+
-- Copyright : (c) Alexey Kuleshevich 2019-2025
88
-- License : BSD3
99
-- Maintainer : Alexey Kuleshevich <lehins@yandex.ru>
1010
-- Stability : experimental

0 commit comments

Comments
 (0)