Twinside / Juicy.Pixels

Haskell library to load & save pictures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RGB to CMYK conversion is wrong

lehins opened this issue · comments

Conversion from RGB to CMYK colorspace is completely off.

Here is a quick helper function that converts a YCbCr8 image through RGB8 to CMYK8 and writes it as a tiff image:

import qualified Codec.Picture as JP
import qualified Codec.Picture.Types as JP

writeCMYK8 :: JP.ColorSpaceConvertible a JP.PixelRGB8 => FilePath -> JP.Image a -> IO ()
writeCMYK8 filename iYCbCr8 = JP.writeTiff filename iCMYK8
  where
    iCMYK8 = JP.convertImage iRGB8 :: JP.Image JP.PixelCMYK8
    iRGB8 = JP.convertImage iYCbCr8 :: JP.Image JP.PixelRGB8

Then if we try reading this image (or any image for that matter):
frog

and try to convert it to CMYK:

λ> Right (JP.ImageYCbCr8 iYCbCr8) <- JP.readJpeg "frog.jpg"
λ> writeCMYK8 "frogCMYK8.tiff" iYCbCr8

We get back a gray scale tiff image (tiffs aren't uploadable on github, so it is in zipped form):
frogCMYK8.zip