{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}
-- | Helper functions to save dynamic images to other file format

-- with automatic color space/sample format conversion done automatically.

module Codec.Picture.Saving( imageToJpg
                           , imageToPng
                           , imageToGif
                           , imageToBitmap
                           , imageToTiff
                           , imageToRadiance
                           , imageToTga
                           ) where

#if !MIN_VERSION_base(4,8,0)
import Data.Monoid( mempty )
#endif

import Data.Bits( unsafeShiftR )
import Data.Word( Word8, Word16, Word32 )
import qualified Data.ByteString.Lazy as L
import Codec.Picture.Bitmap
import Codec.Picture.Jpg
import Codec.Picture.Png
import Codec.Picture.Gif
import Codec.Picture.ColorQuant
import Codec.Picture.HDR
import Codec.Picture.Types
import Codec.Picture.Tiff
import Codec.Picture.Tga

import qualified Data.Vector.Storable as V

componentToLDR :: Float -> Word8
componentToLDR :: PixelF -> Pixel8
componentToLDR = PixelF -> Pixel8
forall b. Integral b => PixelF -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate (PixelF -> Pixel8) -> (PixelF -> PixelF) -> PixelF -> Pixel8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PixelF
255 PixelF -> PixelF -> PixelF
forall a. Num a => a -> a -> a
*) (PixelF -> PixelF) -> (PixelF -> PixelF) -> PixelF -> PixelF
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PixelF -> PixelF -> PixelF
forall a. Ord a => a -> a -> a
min PixelF
1.0 (PixelF -> PixelF) -> (PixelF -> PixelF) -> PixelF -> PixelF
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PixelF -> PixelF -> PixelF
forall a. Ord a => a -> a -> a
max PixelF
0.0

toStandardDef :: Image PixelRGBF -> Image PixelRGB8
toStandardDef :: Image PixelRGBF -> Image PixelRGB8
toStandardDef = (PixelRGBF -> PixelRGB8) -> Image PixelRGBF -> Image PixelRGB8
forall a b. (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
pixelMap PixelRGBF -> PixelRGB8
pixelConverter
  where pixelConverter :: PixelRGBF -> PixelRGB8
pixelConverter (PixelRGBF PixelF
rf PixelF
gf PixelF
bf) = Pixel8 -> Pixel8 -> Pixel8 -> PixelRGB8
PixelRGB8 Pixel8
r Pixel8
g Pixel8
b
          where r :: Pixel8
r = PixelF -> Pixel8
componentToLDR PixelF
rf
                g :: Pixel8
g = PixelF -> Pixel8
componentToLDR PixelF
gf
                b :: Pixel8
b = PixelF -> Pixel8
componentToLDR PixelF
bf

greyScaleToStandardDef :: Image PixelF -> Image Pixel8
greyScaleToStandardDef :: Image PixelF -> Image Pixel8
greyScaleToStandardDef = (PixelF -> Pixel8) -> Image PixelF -> Image Pixel8
forall a b. (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
pixelMap PixelF -> Pixel8
componentToLDR

from16to8 :: ( PixelBaseComponent source ~ Word16
             , PixelBaseComponent dest ~ Word8 )
          => Image source -> Image dest
from16to8 :: forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image { imageWidth :: forall a. Image a -> Int
imageWidth = Int
w, imageHeight :: forall a. Image a -> Int
imageHeight = Int
h
                , imageData :: forall a. Image a -> Vector (PixelBaseComponent a)
imageData = Vector (PixelBaseComponent source)
arr } = Int -> Int -> Vector (PixelBaseComponent dest) -> Image dest
forall a. Int -> Int -> Vector (PixelBaseComponent a) -> Image a
Image Int
w Int
h Vector Pixel8
Vector (PixelBaseComponent dest)
transformed
   where transformed :: Vector Pixel8
transformed = (Pixel16 -> Pixel8) -> Vector Pixel16 -> Vector Pixel8
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
V.map Pixel16 -> Pixel8
forall {a} {b}. (Integral a, Bits a, Num b) => a -> b
toWord8 Vector Pixel16
Vector (PixelBaseComponent source)
arr
         toWord8 :: a -> b
toWord8 a
v = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a
v a -> Int -> a
forall a. Bits a => a -> Int -> a
`unsafeShiftR` Int
8)

from32to8 :: ( PixelBaseComponent source ~ Word32
             , PixelBaseComponent dest ~ Word8 )
          => Image source -> Image dest
from32to8 :: forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from32to8 Image { imageWidth :: forall a. Image a -> Int
imageWidth = Int
w, imageHeight :: forall a. Image a -> Int
imageHeight = Int
h
                , imageData :: forall a. Image a -> Vector (PixelBaseComponent a)
imageData = Vector (PixelBaseComponent source)
arr } = Int -> Int -> Vector (PixelBaseComponent dest) -> Image dest
forall a. Int -> Int -> Vector (PixelBaseComponent a) -> Image a
Image Int
w Int
h Vector Pixel8
Vector (PixelBaseComponent dest)
transformed
   where transformed :: Vector Pixel8
transformed = (Pixel32 -> Pixel8) -> Vector Pixel32 -> Vector Pixel8
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
V.map Pixel32 -> Pixel8
forall {a} {b}. (Integral a, Bits a, Num b) => a -> b
toWord8 Vector Pixel32
Vector (PixelBaseComponent source)
arr
         toWord8 :: a -> b
toWord8 a
v = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a
v a -> Int -> a
forall a. Bits a => a -> Int -> a
`unsafeShiftR` Int
24)

from32to16 :: ( PixelBaseComponent source ~ Word32
             , PixelBaseComponent dest ~ Word16 )
          => Image source -> Image dest
from32to16 :: forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel16) =>
Image source -> Image dest
from32to16 Image { imageWidth :: forall a. Image a -> Int
imageWidth = Int
w, imageHeight :: forall a. Image a -> Int
imageHeight = Int
h
                , imageData :: forall a. Image a -> Vector (PixelBaseComponent a)
imageData = Vector (PixelBaseComponent source)
arr } = Int -> Int -> Vector (PixelBaseComponent dest) -> Image dest
forall a. Int -> Int -> Vector (PixelBaseComponent a) -> Image a
Image Int
w Int
h Vector Pixel16
Vector (PixelBaseComponent dest)
transformed
   where transformed :: Vector Pixel16
transformed = (Pixel32 -> Pixel16) -> Vector Pixel32 -> Vector Pixel16
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
V.map Pixel32 -> Pixel16
forall {a} {b}. (Integral a, Bits a, Num b) => a -> b
toWord16 Vector Pixel32
Vector (PixelBaseComponent source)
arr
         toWord16 :: a -> b
toWord16 a
v = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a
v a -> Int -> a
forall a. Bits a => a -> Int -> a
`unsafeShiftR` Int
16)

from16toFloat :: ( PixelBaseComponent source ~ Word16
                 , PixelBaseComponent dest ~ Float )
          => Image source -> Image dest
from16toFloat :: forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ PixelF) =>
Image source -> Image dest
from16toFloat Image { imageWidth :: forall a. Image a -> Int
imageWidth = Int
w, imageHeight :: forall a. Image a -> Int
imageHeight = Int
h
                    , imageData :: forall a. Image a -> Vector (PixelBaseComponent a)
imageData = Vector (PixelBaseComponent source)
arr } = Int -> Int -> Vector (PixelBaseComponent dest) -> Image dest
forall a. Int -> Int -> Vector (PixelBaseComponent a) -> Image a
Image Int
w Int
h Vector PixelF
Vector (PixelBaseComponent dest)
transformed
   where transformed :: Vector PixelF
transformed = (Pixel16 -> PixelF) -> Vector Pixel16 -> Vector PixelF
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
V.map Pixel16 -> PixelF
forall {a} {a}. (Fractional a, Integral a) => a -> a
toWord8 Vector Pixel16
Vector (PixelBaseComponent source)
arr
         toWord8 :: a -> a
toWord8 a
v = a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
v a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
65536.0

-- | This function will try to do anything to encode an image

-- as RADIANCE, make all color conversion and such. Equivalent

-- of 'decodeImage' for radiance encoding

imageToRadiance :: DynamicImage -> L.ByteString
imageToRadiance :: DynamicImage -> ByteString
imageToRadiance (ImageCMYK8 Image PixelCMYK8
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK8
img
imageToRadiance (ImageCMYK16 Image PixelCMYK16
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGB16 -> DynamicImage)
-> Image PixelRGB16
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB16 -> DynamicImage
ImageRGB16 (Image PixelRGB16 -> ByteString) -> Image PixelRGB16 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK16 -> Image PixelRGB16
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK16
img
imageToRadiance (ImageYCbCr8 Image PixelYCbCr8
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYCbCr8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelYCbCr8
img
imageToRadiance (ImageRGB8   Image PixelRGB8
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGB8 -> Image PixelRGBF
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage Image PixelRGB8
img
imageToRadiance (ImageRGBF   Image PixelRGBF
img) = Image PixelRGBF -> ByteString
encodeHDR Image PixelRGBF
img
imageToRadiance (ImageRGBA8  Image PixelRGBA8
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> DynamicImage)
-> (Image PixelRGB8 -> Image PixelRGBF)
-> Image PixelRGB8
-> DynamicImage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> Image PixelRGBF
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBA8 -> Image PixelRGB8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelRGBA8
img
imageToRadiance (ImageY8     Image Pixel8
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel8 -> Image PixelRGB8
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage Image Pixel8
img
imageToRadiance (ImageYF     Image PixelF
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image PixelRGBF
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage Image PixelF
img
imageToRadiance (ImageYA8    Image PixelYA8
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image Pixel8 -> DynamicImage) -> Image Pixel8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> DynamicImage)
-> (Image Pixel8 -> Image PixelRGB8)
-> Image Pixel8
-> DynamicImage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> Image PixelRGB8
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA8 -> Image Pixel8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelYA8
img
imageToRadiance (ImageY16    Image Pixel16
img) =
  DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ (Pixel16 -> PixelRGBF) -> Image Pixel16 -> Image PixelRGBF
forall a b. (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
pixelMap Pixel16 -> PixelRGBF
forall {a}. Integral a => a -> PixelRGBF
toRgbf Image Pixel16
img
    where toRgbf :: a -> PixelRGBF
toRgbf a
v = PixelF -> PixelF -> PixelF -> PixelRGBF
PixelRGBF PixelF
val PixelF
val PixelF
val
            where val :: PixelF
val = a -> PixelF
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
v PixelF -> PixelF -> PixelF
forall a. Fractional a => a -> a -> a
/ PixelF
65536.0
imageToRadiance (ImageY32    Image Pixel32
img) =
  DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ (Pixel32 -> PixelRGBF) -> Image Pixel32 -> Image PixelRGBF
forall a b. (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
pixelMap Pixel32 -> PixelRGBF
forall {a}. Integral a => a -> PixelRGBF
toRgbf Image Pixel32
img
    where toRgbf :: a -> PixelRGBF
toRgbf a
v = PixelF -> PixelF -> PixelF -> PixelRGBF
PixelRGBF PixelF
val PixelF
val PixelF
val
            where val :: PixelF
val = a -> PixelF
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
v PixelF -> PixelF -> PixelF
forall a. Fractional a => a -> a -> a
/ PixelF
4294967296.0
imageToRadiance (ImageYA16   Image PixelYA16
img) =
  DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ (PixelYA16 -> PixelRGBF) -> Image PixelYA16 -> Image PixelRGBF
forall a b. (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
pixelMap PixelYA16 -> PixelRGBF
toRgbf Image PixelYA16
img
    where toRgbf :: PixelYA16 -> PixelRGBF
toRgbf (PixelYA16 Pixel16
v Pixel16
_) = PixelF -> PixelF -> PixelF -> PixelRGBF
PixelRGBF PixelF
val PixelF
val PixelF
val
            where val :: PixelF
val = Pixel16 -> PixelF
forall a b. (Integral a, Num b) => a -> b
fromIntegral Pixel16
v PixelF -> PixelF -> PixelF
forall a. Fractional a => a -> a -> a
/ PixelF
65536.0
imageToRadiance (ImageRGB16  Image PixelRGB16
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGB16 -> Image PixelRGBF
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ PixelF) =>
Image source -> Image dest
from16toFloat Image PixelRGB16
img
imageToRadiance (ImageRGBA16 Image PixelRGBA16
img) =
    DynamicImage -> ByteString
imageToRadiance (DynamicImage -> ByteString)
-> (Image PixelRGBF -> DynamicImage)
-> Image PixelRGBF
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBF -> DynamicImage
ImageRGBF (Image PixelRGBF -> ByteString) -> Image PixelRGBF -> ByteString
forall a b. (a -> b) -> a -> b
$ (PixelRGBA16 -> PixelRGBF) -> Image PixelRGBA16 -> Image PixelRGBF
forall a b. (Pixel a, Pixel b) => (a -> b) -> Image a -> Image b
pixelMap PixelRGBA16 -> PixelRGBF
toRgbf Image PixelRGBA16
img
    where toRgbf :: PixelRGBA16 -> PixelRGBF
toRgbf (PixelRGBA16 Pixel16
r Pixel16
g Pixel16
b Pixel16
_) = PixelF -> PixelF -> PixelF -> PixelRGBF
PixelRGBF (Pixel16 -> PixelF
forall {a} {a}. (Fractional a, Integral a) => a -> a
f Pixel16
r) (Pixel16 -> PixelF
forall {a} {a}. (Fractional a, Integral a) => a -> a
f Pixel16
g) (Pixel16 -> PixelF
forall {a} {a}. (Fractional a, Integral a) => a -> a
f Pixel16
b)
            where f :: a -> a
f a
v = a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
v a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
65536.0

-- | This function will try to do anything to encode an image

-- as JPEG, make all color conversion and such. Equivalent

-- of 'decodeImage' for jpeg encoding

-- Save Y or YCbCr Jpeg only, all other colorspaces are converted.

-- To save a RGB or CMYK JPEG file, use the

-- 'Codec.Picture.Jpg.Internal.encodeDirectJpegAtQualityWithMetadata' function

imageToJpg :: Int -> DynamicImage -> L.ByteString
imageToJpg :: Int -> DynamicImage -> ByteString
imageToJpg Int
quality DynamicImage
dynImage =
    let encodeAtQuality :: Image PixelYCbCr8 -> ByteString
encodeAtQuality = Pixel8 -> Image PixelYCbCr8 -> ByteString
encodeJpegAtQuality (Int -> Pixel8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
quality)
        encodeWithMeta :: Image Pixel8 -> ByteString
encodeWithMeta = Pixel8 -> Metadatas -> Image Pixel8 -> ByteString
forall px.
JpgEncodable px =>
Pixel8 -> Metadatas -> Image px -> ByteString
encodeDirectJpegAtQualityWithMetadata (Int -> Pixel8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
quality) Metadatas
forall a. Monoid a => a
mempty
    in case DynamicImage
dynImage of
        ImageYCbCr8 Image PixelYCbCr8
img -> Image PixelYCbCr8 -> ByteString
encodeAtQuality Image PixelYCbCr8
img
        ImageCMYK8  Image PixelCMYK8
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK8
img
        ImageCMYK16 Image PixelCMYK16
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image PixelRGB16 -> DynamicImage)
-> Image PixelRGB16
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB16 -> DynamicImage
ImageRGB16 (Image PixelRGB16 -> ByteString) -> Image PixelRGB16 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK16 -> Image PixelRGB16
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK16
img
        ImageRGB8   Image PixelRGB8
img -> Image PixelYCbCr8 -> ByteString
encodeAtQuality (Image PixelRGB8 -> Image PixelYCbCr8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelRGB8
img)
        ImageRGBF   Image PixelRGBF
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBF -> Image PixelRGB8
toStandardDef Image PixelRGBF
img
        ImageRGBA8  Image PixelRGBA8
img -> Image PixelYCbCr8 -> ByteString
encodeAtQuality (Image PixelRGB8 -> Image PixelYCbCr8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage (Image PixelRGB8 -> Image PixelYCbCr8)
-> Image PixelRGB8 -> Image PixelYCbCr8
forall a b. (a -> b) -> a -> b
$ Image PixelRGBA8 -> Image PixelRGB8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelRGBA8
img)
        ImageYF     Image PixelF
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image Pixel8 -> DynamicImage) -> Image Pixel8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image Pixel8
greyScaleToStandardDef Image PixelF
img
        ImageY8     Image Pixel8
img -> Image Pixel8 -> ByteString
encodeWithMeta Image Pixel8
img
        ImageYA8    Image PixelYA8
img -> Image Pixel8 -> ByteString
encodeWithMeta (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA8 -> Image Pixel8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelYA8
img
        ImageY16    Image Pixel16
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image Pixel8 -> DynamicImage) -> Image Pixel8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel16 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image Pixel16
img
        ImageYA16   Image PixelYA16
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image PixelYA8 -> DynamicImage) -> Image PixelYA8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelYA8 -> DynamicImage
ImageYA8 (Image PixelYA8 -> ByteString) -> Image PixelYA8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA16 -> Image PixelYA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelYA16
img
        ImageY32    Image Pixel32
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image Pixel8 -> DynamicImage) -> Image Pixel8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel32 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from32to8 Image Pixel32
img
        ImageRGB16  Image PixelRGB16
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGB16 -> Image PixelRGB8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGB16
img
        ImageRGBA16 Image PixelRGBA16
img -> Int -> DynamicImage -> ByteString
imageToJpg Int
quality (DynamicImage -> ByteString)
-> (Image PixelRGBA8 -> DynamicImage)
-> Image PixelRGBA8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBA8 -> DynamicImage
ImageRGBA8 (Image PixelRGBA8 -> ByteString) -> Image PixelRGBA8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBA16 -> Image PixelRGBA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGBA16
img

-- | This function will try to do anything to encode an image

-- as PNG, make all color conversion and such. Equivalent

-- of 'decodeImage' for PNG encoding

imageToPng :: DynamicImage -> L.ByteString
imageToPng :: DynamicImage -> ByteString
imageToPng (ImageYCbCr8 Image PixelYCbCr8
img) = Image PixelRGB8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng (Image PixelYCbCr8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelYCbCr8
img :: Image PixelRGB8)
imageToPng (ImageCMYK8 Image PixelCMYK8
img)  = Image PixelRGB8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng (Image PixelCMYK8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK8
img :: Image PixelRGB8)
imageToPng (ImageCMYK16 Image PixelCMYK16
img) = Image PixelRGB16 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng (Image PixelCMYK16 -> Image PixelRGB16
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK16
img :: Image PixelRGB16)
imageToPng (ImageRGB8   Image PixelRGB8
img) = Image PixelRGB8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image PixelRGB8
img
imageToPng (ImageRGBF   Image PixelRGBF
img) = Image PixelRGB8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBF -> Image PixelRGB8
toStandardDef Image PixelRGBF
img
imageToPng (ImageRGBA8  Image PixelRGBA8
img) = Image PixelRGBA8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image PixelRGBA8
img
imageToPng (ImageY8     Image Pixel8
img) = Image Pixel8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image Pixel8
img
imageToPng (ImageYF     Image PixelF
img) = Image Pixel8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image Pixel8
greyScaleToStandardDef Image PixelF
img
imageToPng (ImageYA8    Image PixelYA8
img) = Image PixelYA8 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image PixelYA8
img
imageToPng (ImageY16    Image Pixel16
img) = Image Pixel16 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image Pixel16
img
imageToPng (ImageY32    Image Pixel32
img) = DynamicImage -> ByteString
imageToPng (DynamicImage -> ByteString)
-> (Image Pixel16 -> DynamicImage) -> Image Pixel16 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel16 -> DynamicImage
ImageY16 (Image Pixel16 -> ByteString) -> Image Pixel16 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel32 -> Image Pixel16
forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel16) =>
Image source -> Image dest
from32to16 Image Pixel32
img
imageToPng (ImageYA16   Image PixelYA16
img) = Image PixelYA16 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image PixelYA16
img
imageToPng (ImageRGB16  Image PixelRGB16
img) = Image PixelRGB16 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image PixelRGB16
img
imageToPng (ImageRGBA16 Image PixelRGBA16
img) = Image PixelRGBA16 -> ByteString
forall a. PngSavable a => Image a -> ByteString
encodePng Image PixelRGBA16
img

-- | This function will try to do anything to encode an image

-- as a Tiff, make all color conversion and such. Equivalent

-- of 'decodeImage' for Tiff encoding

imageToTiff :: DynamicImage -> L.ByteString
imageToTiff :: DynamicImage -> ByteString
imageToTiff (ImageYCbCr8 Image PixelYCbCr8
img) = Image PixelYCbCr8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelYCbCr8
img
imageToTiff (ImageCMYK8 Image PixelCMYK8
img)  = Image PixelCMYK8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelCMYK8
img
imageToTiff (ImageCMYK16 Image PixelCMYK16
img) = Image PixelCMYK16 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelCMYK16
img
imageToTiff (ImageRGB8   Image PixelRGB8
img) = Image PixelRGB8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelRGB8
img
imageToTiff (ImageRGBF   Image PixelRGBF
img) = Image PixelRGB8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBF -> Image PixelRGB8
toStandardDef Image PixelRGBF
img
imageToTiff (ImageRGBA8  Image PixelRGBA8
img) = Image PixelRGBA8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelRGBA8
img
imageToTiff (ImageY8     Image Pixel8
img) = Image Pixel8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image Pixel8
img
imageToTiff (ImageYF     Image PixelF
img) = Image Pixel8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image Pixel8
greyScaleToStandardDef Image PixelF
img
imageToTiff (ImageYA8    Image PixelYA8
img) = Image Pixel8 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA8 -> Image Pixel8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelYA8
img
imageToTiff (ImageY16    Image Pixel16
img) = Image Pixel16 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image Pixel16
img
imageToTiff (ImageY32    Image Pixel32
img) = Image Pixel32 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image Pixel32
img
imageToTiff (ImageYA16   Image PixelYA16
img) = Image Pixel16 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff (Image Pixel16 -> ByteString) -> Image Pixel16 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA16 -> Image Pixel16
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelYA16
img
imageToTiff (ImageRGB16  Image PixelRGB16
img) = Image PixelRGB16 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelRGB16
img
imageToTiff (ImageRGBA16 Image PixelRGBA16
img) = Image PixelRGBA16 -> ByteString
forall px. TiffSaveable px => Image px -> ByteString
encodeTiff Image PixelRGBA16
img

-- | This function will try to do anything to encode an image

-- as bitmap, make all color conversion and such. Equivalent

-- of 'decodeImage' for Bitmap encoding

imageToBitmap :: DynamicImage -> L.ByteString
imageToBitmap :: DynamicImage -> ByteString
imageToBitmap (ImageYCbCr8 Image PixelYCbCr8
img) = Image PixelRGB8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap (Image PixelYCbCr8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelYCbCr8
img :: Image PixelRGB8)
imageToBitmap (ImageCMYK8  Image PixelCMYK8
img) = Image PixelRGB8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap (Image PixelCMYK8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK8
img :: Image PixelRGB8)
imageToBitmap (ImageCMYK16 Image PixelCMYK16
img) = DynamicImage -> ByteString
imageToBitmap (DynamicImage -> ByteString)
-> (Image PixelRGB16 -> DynamicImage)
-> Image PixelRGB16
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB16 -> DynamicImage
ImageRGB16 (Image PixelRGB16 -> ByteString) -> Image PixelRGB16 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK16 -> Image PixelRGB16
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK16
img
imageToBitmap (ImageRGBF   Image PixelRGBF
img) = Image PixelRGB8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBF -> Image PixelRGB8
toStandardDef Image PixelRGBF
img
imageToBitmap (ImageRGB8   Image PixelRGB8
img) = Image PixelRGB8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap Image PixelRGB8
img
imageToBitmap (ImageRGBA8  Image PixelRGBA8
img) = Image PixelRGBA8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap Image PixelRGBA8
img
imageToBitmap (ImageY8     Image Pixel8
img) = Image Pixel8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap Image Pixel8
img
imageToBitmap (ImageYF     Image PixelF
img) = Image Pixel8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image Pixel8
greyScaleToStandardDef Image PixelF
img
imageToBitmap (ImageYA8    Image PixelYA8
img) = Image PixelRGBA8 -> ByteString
forall pixel. BmpEncodable pixel => Image pixel -> ByteString
encodeBitmap (Image PixelYA8 -> Image PixelRGBA8
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage Image PixelYA8
img :: Image PixelRGBA8)
imageToBitmap (ImageY16    Image Pixel16
img) = DynamicImage -> ByteString
imageToBitmap (DynamicImage -> ByteString)
-> (Image Pixel8 -> DynamicImage) -> Image Pixel8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel16 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image Pixel16
img
imageToBitmap (ImageY32    Image Pixel32
img) = DynamicImage -> ByteString
imageToBitmap (DynamicImage -> ByteString)
-> (Image Pixel8 -> DynamicImage) -> Image Pixel8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel32 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from32to8 Image Pixel32
img
imageToBitmap (ImageYA16   Image PixelYA16
img) = DynamicImage -> ByteString
imageToBitmap (DynamicImage -> ByteString)
-> (Image PixelYA8 -> DynamicImage) -> Image PixelYA8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelYA8 -> DynamicImage
ImageYA8 (Image PixelYA8 -> ByteString) -> Image PixelYA8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA16 -> Image PixelYA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelYA16
img
imageToBitmap (ImageRGB16  Image PixelRGB16
img) = DynamicImage -> ByteString
imageToBitmap (DynamicImage -> ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGB16 -> Image PixelRGB8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGB16
img
imageToBitmap (ImageRGBA16 Image PixelRGBA16
img) = DynamicImage -> ByteString
imageToBitmap (DynamicImage -> ByteString)
-> (Image PixelRGBA8 -> DynamicImage)
-> Image PixelRGBA8
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBA8 -> DynamicImage
ImageRGBA8 (Image PixelRGBA8 -> ByteString) -> Image PixelRGBA8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBA16 -> Image PixelRGBA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGBA16
img


-- | This function will try to do anything to encode an image

-- as a gif, make all color conversion and quantization. Equivalent

-- of 'decodeImage' for gif encoding

imageToGif :: DynamicImage -> Either String L.ByteString
imageToGif :: DynamicImage -> Either String ByteString
imageToGif (ImageYCbCr8 Image PixelYCbCr8
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> Either String ByteString)
-> Image PixelRGB8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYCbCr8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelYCbCr8
img
imageToGif (ImageCMYK8  Image PixelCMYK8
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> Either String ByteString)
-> Image PixelRGB8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK8
img
imageToGif (ImageCMYK16 Image PixelCMYK16
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGB16 -> DynamicImage)
-> Image PixelRGB16
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB16 -> DynamicImage
ImageRGB16 (Image PixelRGB16 -> Either String ByteString)
-> Image PixelRGB16 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelCMYK16 -> Image PixelRGB16
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK16
img
imageToGif (ImageRGBF   Image PixelRGBF
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> Either String ByteString)
-> Image PixelRGB8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBF -> Image PixelRGB8
toStandardDef Image PixelRGBF
img
imageToGif (ImageRGB8   Image PixelRGB8
img) = Image Pixel8 -> Image PixelRGB8 -> Either String ByteString
encodeGifImageWithPalette Image Pixel8
indexed Image PixelRGB8
pal
  where (Image Pixel8
indexed, Image PixelRGB8
pal) = PaletteOptions
-> Image PixelRGB8 -> (Image Pixel8, Image PixelRGB8)
palettize PaletteOptions
defaultPaletteOptions Image PixelRGB8
img
imageToGif (ImageRGBA8  Image PixelRGBA8
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> Either String ByteString)
-> Image PixelRGB8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBA8 -> Image PixelRGB8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelRGBA8
img
imageToGif (ImageY8     Image Pixel8
img) = ByteString -> Either String ByteString
forall a b. b -> Either a b
Right (ByteString -> Either String ByteString)
-> ByteString -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel8 -> ByteString
encodeGifImage Image Pixel8
img
imageToGif (ImageYF     Image PixelF
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image Pixel8 -> DynamicImage)
-> Image Pixel8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> Either String ByteString)
-> Image Pixel8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image Pixel8
greyScaleToStandardDef Image PixelF
img
imageToGif (ImageYA8    Image PixelYA8
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image Pixel8 -> DynamicImage)
-> Image Pixel8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> Either String ByteString)
-> Image Pixel8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA8 -> Image Pixel8
forall a b. TransparentPixel a b => Image a -> Image b
dropAlphaLayer Image PixelYA8
img
imageToGif (ImageY16    Image Pixel16
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image Pixel8 -> DynamicImage)
-> Image Pixel8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> Either String ByteString)
-> Image Pixel8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel16 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image Pixel16
img
imageToGif (ImageY32    Image Pixel32
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image Pixel8 -> DynamicImage)
-> Image Pixel8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image Pixel8 -> DynamicImage
ImageY8 (Image Pixel8 -> Either String ByteString)
-> Image Pixel8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image Pixel32 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from32to8 Image Pixel32
img
imageToGif (ImageYA16   Image PixelYA16
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelYA8 -> DynamicImage)
-> Image PixelYA8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelYA8 -> DynamicImage
ImageYA8 (Image PixelYA8 -> Either String ByteString)
-> Image PixelYA8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelYA16 -> Image PixelYA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelYA16
img
imageToGif (ImageRGB16  Image PixelRGB16
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGB8 -> DynamicImage)
-> Image PixelRGB8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGB8 -> DynamicImage
ImageRGB8 (Image PixelRGB8 -> Either String ByteString)
-> Image PixelRGB8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGB16 -> Image PixelRGB8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGB16
img
imageToGif (ImageRGBA16 Image PixelRGBA16
img) = DynamicImage -> Either String ByteString
imageToGif (DynamicImage -> Either String ByteString)
-> (Image PixelRGBA8 -> DynamicImage)
-> Image PixelRGBA8
-> Either String ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image PixelRGBA8 -> DynamicImage
ImageRGBA8 (Image PixelRGBA8 -> Either String ByteString)
-> Image PixelRGBA8 -> Either String ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBA16 -> Image PixelRGBA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGBA16
img

-- | This function will try to do anything to encode an image

-- as a tga, make all color conversion and quantization. Equivalent

-- of 'decodeImage' for tga encoding

imageToTga :: DynamicImage -> L.ByteString
imageToTga :: DynamicImage -> ByteString
imageToTga (ImageYCbCr8 Image PixelYCbCr8
img) = Image PixelRGB8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelYCbCr8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelYCbCr8
img :: Image PixelRGB8)
imageToTga (ImageCMYK8  Image PixelCMYK8
img) = Image PixelRGB8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelCMYK8 -> Image PixelRGB8
forall a b. ColorSpaceConvertible a b => Image a -> Image b
convertImage Image PixelCMYK8
img :: Image PixelRGB8)
imageToTga (ImageCMYK16 Image PixelCMYK16
img) = Image PixelRGB8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelCMYK16 -> Image PixelRGB8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelCMYK16
img :: Image PixelRGB8)
imageToTga (ImageRGBF   Image PixelRGBF
img) = Image PixelRGB8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelRGB8 -> ByteString) -> Image PixelRGB8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelRGBF -> Image PixelRGB8
toStandardDef Image PixelRGBF
img
imageToTga (ImageRGB8   Image PixelRGB8
img) = Image PixelRGB8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga Image PixelRGB8
img
imageToTga (ImageRGBA8  Image PixelRGBA8
img) = Image PixelRGBA8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga Image PixelRGBA8
img
imageToTga (ImageY8     Image Pixel8
img) = Image Pixel8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga Image Pixel8
img
imageToTga (ImageYF     Image PixelF
img) = Image Pixel8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image Pixel8 -> ByteString) -> Image Pixel8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Image PixelF -> Image Pixel8
greyScaleToStandardDef Image PixelF
img
imageToTga (ImageYA8    Image PixelYA8
img) = Image PixelRGBA8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelYA8 -> Image PixelRGBA8
forall a b. ColorConvertible a b => Image a -> Image b
promoteImage Image PixelYA8
img :: Image PixelRGBA8)
imageToTga (ImageY16    Image Pixel16
img) = Image Pixel8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image Pixel16 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image Pixel16
img :: Image Pixel8)
imageToTga (ImageY32    Image Pixel32
img) = Image Pixel8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image Pixel32 -> Image Pixel8
forall source dest.
(PixelBaseComponent source ~ Pixel32,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from32to8 Image Pixel32
img :: Image Pixel8)
imageToTga (ImageYA16   Image PixelYA16
img) = Image PixelRGBA8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelYA16 -> Image PixelRGBA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelYA16
img :: Image PixelRGBA8)
imageToTga (ImageRGB16  Image PixelRGB16
img) = Image PixelRGB8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelRGB16 -> Image PixelRGB8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGB16
img :: Image PixelRGB8)
imageToTga (ImageRGBA16 Image PixelRGBA16
img) = Image PixelRGBA8 -> ByteString
forall px. TgaSaveable px => Image px -> ByteString
encodeTga (Image PixelRGBA16 -> Image PixelRGBA8
forall source dest.
(PixelBaseComponent source ~ Pixel16,
 PixelBaseComponent dest ~ Pixel8) =>
Image source -> Image dest
from16to8 Image PixelRGBA16
img :: Image PixelRGBA8)