module OpenCV.Internal.ImgCodecs
( ImreadMode(..)
, marshalImreadMode
, JpegParams(..)
, defaultJpegParams
, marshalJpegParams
, PngStrategy(..)
, marshalPngStrategy
, PngParams(..)
, defaultPngParams
, marshalPngParams
, OutputFormat(..)
, marshalOutputFormat
) where
import "base" Data.Int
import "base" Data.Word
import "base" Foreign.C.Types
import "base" Foreign.Marshal.Utils ( fromBool )
import qualified "vector" Data.Vector.Storable as VS
data ImreadMode
= ImreadUnchanged
| ImreadGrayscale
| ImreadColor
| ImreadAnyDepth
| ImreadAnyColor
| ImreadLoadGdal
deriving (Show)
c'IMREAD_UNCHANGED = 1
c'IMREAD_UNCHANGED :: (Num a) => a
c'IMREAD_GRAYSCALE = 0
c'IMREAD_GRAYSCALE :: (Num a) => a
c'IMREAD_COLOR = 1
c'IMREAD_COLOR :: (Num a) => a
c'IMREAD_ANYDEPTH = 2
c'IMREAD_ANYDEPTH :: (Num a) => a
c'IMREAD_ANYCOLOR = 4
c'IMREAD_ANYCOLOR :: (Num a) => a
c'IMREAD_LOAD_GDAL = 8
c'IMREAD_LOAD_GDAL :: (Num a) => a
marshalImreadMode :: ImreadMode -> Int32
marshalImreadMode = \case
ImreadUnchanged -> c'IMREAD_UNCHANGED
ImreadGrayscale -> c'IMREAD_GRAYSCALE
ImreadColor -> c'IMREAD_COLOR
ImreadAnyDepth -> c'IMREAD_ANYDEPTH
ImreadAnyColor -> c'IMREAD_ANYCOLOR
ImreadLoadGdal -> c'IMREAD_LOAD_GDAL
data JpegParams =
JpegParams
{ jpegParamQuality :: Int
, jpegParamProgressive :: Bool
, jpegParamOptimize :: Bool
, jpegParamRestartInterval :: Word16
, jpegParamLumaQuality :: Int
, jpegParamChromaQuality :: Int
} deriving Show
defaultJpegParams :: JpegParams
defaultJpegParams =
JpegParams
{ jpegParamQuality = 95
, jpegParamProgressive = False
, jpegParamOptimize = False
, jpegParamRestartInterval = 0
, jpegParamLumaQuality = 1
, jpegParamChromaQuality = 1
}
c'IMWRITE_JPEG_QUALITY = 1
c'IMWRITE_JPEG_QUALITY :: (Num a) => a
c'IMWRITE_JPEG_PROGRESSIVE = 2
c'IMWRITE_JPEG_PROGRESSIVE :: (Num a) => a
c'IMWRITE_JPEG_OPTIMIZE = 3
c'IMWRITE_JPEG_OPTIMIZE :: (Num a) => a
c'IMWRITE_JPEG_RST_INTERVAL = 4
c'IMWRITE_JPEG_RST_INTERVAL :: (Num a) => a
c'IMWRITE_JPEG_LUMA_QUALITY = 5
c'IMWRITE_JPEG_LUMA_QUALITY :: (Num a) => a
c'IMWRITE_JPEG_CHROMA_QUALITY = 6
c'IMWRITE_JPEG_CHROMA_QUALITY :: (Num a) => a
marshalJpegParams :: JpegParams -> VS.Vector CInt
marshalJpegParams params =
[ c'IMWRITE_JPEG_QUALITY , fromIntegral $ jpegParamQuality params
, c'IMWRITE_JPEG_PROGRESSIVE , fromBool $ jpegParamProgressive params
, c'IMWRITE_JPEG_OPTIMIZE , fromBool $ jpegParamOptimize params
, c'IMWRITE_JPEG_RST_INTERVAL , fromIntegral $ jpegParamRestartInterval params
, c'IMWRITE_JPEG_LUMA_QUALITY , fromIntegral $ jpegParamLumaQuality params
, c'IMWRITE_JPEG_CHROMA_QUALITY, fromIntegral $ jpegParamChromaQuality params
]
data PngStrategy
= PngStrategyDefault
| PngStrategyFiltered
| PngStrategyHuffmanOnly
| PngStrategyRLE
| PngStrategyFixed
deriving Show
c'IMWRITE_PNG_STRATEGY_DEFAULT = 0
c'IMWRITE_PNG_STRATEGY_DEFAULT :: (Num a) => a
c'IMWRITE_PNG_STRATEGY_FILTERED = 1
c'IMWRITE_PNG_STRATEGY_FILTERED :: (Num a) => a
c'IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2
c'IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY :: (Num a) => a
c'IMWRITE_PNG_STRATEGY_RLE = 3
c'IMWRITE_PNG_STRATEGY_RLE :: (Num a) => a
c'IMWRITE_PNG_STRATEGY_FIXED = 4
c'IMWRITE_PNG_STRATEGY_FIXED :: (Num a) => a
marshalPngStrategy :: PngStrategy -> CInt
marshalPngStrategy = \case
PngStrategyDefault -> c'IMWRITE_PNG_STRATEGY_DEFAULT
PngStrategyFiltered -> c'IMWRITE_PNG_STRATEGY_FILTERED
PngStrategyHuffmanOnly -> c'IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY
PngStrategyRLE -> c'IMWRITE_PNG_STRATEGY_RLE
PngStrategyFixed -> c'IMWRITE_PNG_STRATEGY_FIXED
data PngParams =
PngParams
{ pngParamCompression :: Int
, pngParamStrategy :: PngStrategy
, pngParamBinaryLevel :: Bool
} deriving Show
defaultPngParams :: PngParams
defaultPngParams =
PngParams
{ pngParamCompression = 3
, pngParamStrategy = PngStrategyDefault
, pngParamBinaryLevel = False
}
c'IMWRITE_PNG_COMPRESSION = 16
c'IMWRITE_PNG_COMPRESSION :: (Num a) => a
c'IMWRITE_PNG_STRATEGY = 17
c'IMWRITE_PNG_STRATEGY :: (Num a) => a
c'IMWRITE_PNG_BILEVEL = 18
c'IMWRITE_PNG_BILEVEL :: (Num a) => a
marshalPngParams :: PngParams -> VS.Vector CInt
marshalPngParams params =
[ c'IMWRITE_PNG_COMPRESSION, fromIntegral $ pngParamCompression params
, c'IMWRITE_PNG_STRATEGY , marshalPngStrategy $ pngParamStrategy params
, c'IMWRITE_PNG_BILEVEL , fromBool $ pngParamBinaryLevel params
]
data OutputFormat
= OutputBmp
| OutputExr
| OutputHdr Bool
| OutputJpeg JpegParams
| OutputJpeg2000
| OutputPng PngParams
| OutputPxm Bool
| OutputSunras
| OutputTiff
| OutputWebP Int
deriving Show
c'IMWRITE_PXM_BINARY = 32
c'IMWRITE_PXM_BINARY :: (Num a) => a
c'IMWRITE_WEBP_QUALITY = 64
c'IMWRITE_WEBP_QUALITY :: (Num a) => a
marshalOutputFormat :: OutputFormat -> (String, VS.Vector CInt)
marshalOutputFormat = \case
OutputBmp -> (".bmp" , [])
OutputExr -> (".exr" , [])
OutputHdr comp -> (".hdr" , [fromBool comp])
OutputJpeg params -> (".jpeg", marshalJpegParams params)
OutputJpeg2000 -> (".jp2" , [])
OutputPng params -> (".png" , marshalPngParams params)
OutputPxm binary -> (".pxm" , [c'IMWRITE_PXM_BINARY, fromBool binary])
OutputSunras -> (".sr" , [])
OutputTiff -> (".tiff", [])
OutputWebP quality -> (".webp", [c'IMWRITE_WEBP_QUALITY, fromIntegral quality])