-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
module Graphics.Color.Model.YCbCrSpec (spec) where | ||
|
||
import Graphics.Color.Model | ||
import Graphics.Color.Model.Common | ||
import Graphics.Color.Model.RGBSpec () | ||
import qualified Codec.Picture.Types as JuicyPixels | ||
|
||
instance (Elevator e, Random e) => Arbitrary (Color YCbCr e) where | ||
arbitrary = | ||
ColorYCbCr <$> arbitraryElevator <*> arbitraryElevator <*> arbitraryElevator | ||
|
||
spec :: Spec | ||
spec = | ||
describe "YCbCr" $ do | ||
colorModelSpec @YCbCr @Word "YCbCr" | ||
-- prop "rgb2ycbcr . ycbcr2rgb" $ \(rgb :: Color RGB Double) -> | ||
-- rgb `epsilonEqColor` ycbcr2rgb (rgb2ycbcr rgb) | ||
-- describe "Match JuicyPixels" $ do | ||
-- prop "rgb2ycbcr" $ \(rgb@(ColorRGB r g b) :: Color RGB Word8) -> | ||
-- case JuicyPixels.convertPixel (JuicyPixels.PixelRGB8 r g b) of | ||
-- JuicyPixels.PixelYCbCr8 y cb cr -> | ||
-- toWord8 <$> rgb2ycbcr (toFloat <$> rgb) `approxIntegralColorExpect1` ColorYCbCr y cb cr | ||
-- prop "ycbcr2rgb" $ \(ycbcr@(ColorYCbCr y cb cr) :: Color YCbCr Word8) -> | ||
-- case JuicyPixels.convertPixel (JuicyPixels.PixelYCbCr8 y cb cr) of | ||
-- JuicyPixels.PixelRGB8 r g b -> | ||
-- toWord8 <$> ycbcr2rgb (toFloat <$> ycbcr) `approxIntegralColorExpect1` ColorRGB r g b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Color/tests/Graphics/Color/Space/RGB/Alternative/YCbCrSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
module Graphics.Color.Space.RGB.Alternative.YCbCrSpec (spec) where | ||
|
||
import qualified Codec.Picture.Types as JuicyPixels | ||
import Graphics.Color.Space.Common | ||
import Graphics.Color.Space.RGB.SRGB | ||
import qualified Graphics.Color.Space.RGB.Derived.SRGB as Derived | ||
import Graphics.Color.Space.RGB.Alternative.YCbCr | ||
|
||
instance (Elevator e, Random e) => Arbitrary (Color SRGB e) where | ||
arbitrary = | ||
ColorRGB <$> arbitraryElevator <*> arbitraryElevator <*> arbitraryElevator | ||
|
||
instance (Illuminant i, Elevator e, Random e) => Arbitrary (Color (Derived.SRGB i) e) where | ||
arbitrary = | ||
ColorRGB <$> arbitraryElevator <*> arbitraryElevator <*> arbitraryElevator | ||
|
||
|
||
instance (Elevator e, Random e) => Arbitrary (Color (YCbCr cs) e) where | ||
arbitrary = | ||
ColorYCbCr <$> arbitraryElevator <*> arbitraryElevator <*> arbitraryElevator | ||
|
||
spec :: Spec | ||
spec = | ||
describe "YCbCr" $ do | ||
describe "sRGB" $ do | ||
colorModelSpec @(YCbCr SRGB) @Word "YCbCr" | ||
colorSpaceCommonSpec @(YCbCr SRGB) @_ @Double $ pure () | ||
describe "Derived-sRGB" $ do | ||
colorModelSpec @(YCbCr (Derived.SRGB D65)) @Word "YCbCr" | ||
colorSpaceCommonSpec @(YCbCr (Derived.SRGB D65)) @_ @Double $ pure () | ||
prop "toColorYCbCr . toColorYCbCr" $ \(rgb :: Color (Derived.SRGB D65) Double) -> | ||
rgb `epsilonEqColor` | ||
fromColorYCbCr (toColorYCbCr rgb :: Color (YCbCr (Derived.SRGB D65)) Double) | ||
prop "toColorYCbCr == srgb2ycbcr" $ \(rgb :: Color SRGB Double) -> | ||
srgb2ycbcr rgb `epsilonEqColor` | ||
(toColorYCbCr rgb :: Color (YCbCr SRGB) Double) | ||
prop "fromColorYCbCr == ycbcr2srgb" $ \(ycbcr :: Color (YCbCr SRGB) Double) -> | ||
ycbcr2srgb ycbcr `epsilonEqColor` (fromColorYCbCr ycbcr :: Color SRGB Double) | ||
describe "Match JuicyPixels" $ do | ||
prop "rgb2ycbcr" $ \(rgb@(ColorRGB r g b) :: Color SRGB Word8) -> | ||
case JuicyPixels.convertPixel (JuicyPixels.PixelRGB8 r g b) of | ||
JuicyPixels.PixelYCbCr8 y cb cr -> | ||
(fromBaseSpace rgb :: Color (YCbCr SRGB) Word8) | ||
`approxIntegralColorExpect1` ColorYCbCr y cb cr | ||
prop "ycbcr2rgb" $ \(ycbcr@(ColorYCbCr y cb cr) :: Color (YCbCr SRGB) Word8) -> | ||
case JuicyPixels.convertPixel (JuicyPixels.PixelYCbCr8 y cb cr) of | ||
JuicyPixels.PixelRGB8 r g b -> | ||
(toBaseSpace ycbcr) `approxIntegralColorExpect1` ColorRGB r g b |