module Graphics.Imlib (
ImlibProgressFunction, ImlibDataDestructorFunction,
ImlibTTFEncoding (..), ImlibLoadError (..), ImlibTextDirection (..),
ImlibOperation (..), ImlibColor (..), ImlibBorder (..), ImlibPolygon,
ImlibFilter, ImlibColorRange, ImlibFont, ImlibUpdates,
ImlibColorModifier, ImlibImage, ImlibContext,
contextSetDitherMask, contextSetAntiAlias, contextSetDither,
contextSetBlend, contextSetColorModifier, contextSetOperation,
contextSetFont, contextSetDirection, contextSetAngle, contextSetColor,
contextSetColorCmya, contextSetColorHsva, contextSetColorHlsa,
contextSetColorRange, contextSetProgressFunction,
contextSetProgressGranularity, contextSetFilter, contextSetImage,
contextGetDitherMask, contextGetAntiAlias, contextGetDither,
contextGetBlend, contextGetColorModifier, contextGetOperation,
contextGetFont, contextGetAngle, contextGetDirection, contextGetColor,
contextGetColorCmya, contextGetColorHsva, contextGetColorHlsa,
contextGetImlibColor, contextGetColorRange, contextGetProgressFunction,
contextGetProgressGranularity, contextGetImage, contextGetFilter,
getCacheSize, setCacheSize, getColorUsage, setColorUsage,
flushLoaders, loadImage, loadImageImmediately, loadImageWithoutCache,
loadImageImmediatelyWithoutCache, loadImageWithErrorReturn, freeImage,
freeImageAndDecache, imageGetWidth, imageGetHeight, imageGetFilename,
imageGetData, imageGetDataForReadingOnly, imagePutBackData,
imageWithData, imageHasAlpha, imageSetChangesOnDisk, imageGetBorder,
imageSetBorder, imageSetFormat, imageSetIrrelevantFormat,
imageSetIrrelevantBorder, imageSetIrrelevantAlpha, imageFormat,
imageSetHasAlpha, blendImageOntoImage, createImage,
createImageUsingData, createImageUsingCopiedData, cloneImage,
createCroppedImage, createCroppedScaledImage, updatesClone,
updateAppendRect, updatesMerge, updatesMergeForRendering,
updatesFree, updatesGetNext, updatesGetCoordinates,
updatesSetCoordinates, updatesInit, updatesAppendUpdates,
imageFlipHorizontal, imageFlipVertical, imageFlipDiagonal,
imageOrientate, imageBlur, imageSharpen, imageTileHorizontal,
imageTileVertical, imageTile, loadFont, freeFont, textDraw,
textDrawWithReturnMetrics, getTextSize, getTextAdvance, getTextInset,
addPathToFontPath, removePathFromFontPath, listFontPath,
textGetIndexAndLocation, textGetLocationAtIndex, listFonts,
getFontCacheSize, setFontCacheSize, flushFontCache, getFontAscent,
getFontDescent, getMaximumFontAscent, getMaximumFontDescent,
createColorModifier, freeColorModifier, modifyColorModifierGamma,
modifyColorModifierBrightness, modifyColorModifierContrast,
setColorModifierTables, getColorModifierTables, resetColorModifier,
applyColorModifier, applyColorModifierToRectangle, imageDrawLine,
imageDrawRectangle, imageFillRectangle, imageCopyAlphaToImage,
imageCopyAlphaRectangleToImage, imageScrollRect, imageCopyRect,
createColorRange, freeColorRange, addColorToColorRange,
imageFillColorRangeRectangle, imageFillHsvaColorRangeRectangle,
imageQueryPixel, imageQueryPixelCmya, imageQueryPixelHsva,
imageQueryPixelHlsa, imageAttachDataValue, imageGetAttachedData,
imageGetAttachedValue, imageRemoveAttachedDataValue,
imageRemoveAndFreeAttachedDataValue, saveImage,
saveImageWithErrorReturn, createRotatedImage,
blendImageOntoImageAtAngle, blendImageOntoImageSkewed,
contextSetCliprect, polygonNew, polygonFree,
polygonAddPoint, imageDrawPolygon, imageFillPolygon, polygonGetBounds,
polygonContainsPoint, imageDrawEllipse, imageFillEllipse, imageFilter,
createFilter, freeFilter, filterSet, filterSetAlpha, filterSetRed,
filterSetGreen, filterSetBlue, filterConstants, filterDivisors,
createImageUsingArray, withImageBits, withImage, colorFromBits, colorToBits
)
where
import Foreign
import Foreign.C
import Data.Bits
import Data.Array
import Control.Monad
import Graphics.X11.Types
nmalloc :: Storable a => Int -> IO [Ptr a]
nmalloc n = replicateM n malloc
nmallocArray :: Storable a => Int -> Int -> IO [Ptr a]
nmallocArray n m = replicateM n (mallocArray m)
newtype ImlibContext = ImlibContext (Ptr ImlibContext)
newtype ImlibImage = ImlibImage (Ptr ImlibImage)
newtype ImlibColorModifier = ImlibColorModifier (Ptr ImlibColorModifier)
newtype ImlibUpdates = ImlibUpdates (Ptr ImlibUpdates)
newtype ImlibFont = ImlibFont (Ptr ImlibFont)
newtype ImlibColorRange = ImlibColorRange (Ptr ImlibColorRange)
newtype ImlibFilter = ImlibFilter (Ptr ImlibFilter)
newtype ImlibPolygon = ImlibPolygon (Ptr ImlibPolygon)
data ImlibBorder = ImlibBorder CInt CInt CInt CInt deriving (Show, Eq)
instance Storable ImlibBorder where
sizeOf _ = 16
alignment _ = 4
peek p = do
[a,b,c,d] <- peekArray 4 (castPtr p)
return (ImlibBorder a b c d)
poke p (ImlibBorder a b c d) =
pokeArray (castPtr p) [a,b,c,d]
data ImlibColor = ImlibColor Word32 Word32 Word32 Word32 deriving (Show, Eq)
instance Storable ImlibColor where
sizeOf _ = 16
alignment _ = 4
peek p = do
[a,b,c,d] <- peekArray 4 (castPtr p)
return (ImlibColor a b c d)
where
poke p (ImlibColor a b c d) = do
pokeArray (castPtr p) [a,b,c,d]
data ImlibOperation = ImlibOpCopy
| ImlibOpAdd
| ImlibOpSubtract
| ImlibOpReshade
deriving (Enum, Show, Eq)
data ImlibTextDirection = ImlibTextToRight
| ImlibTextToLeft
| ImlibTextToDown
| ImlibTextToUp
| ImlibTextToAngle
deriving (Enum, Show, Eq)
data ImlibLoadError = ImlibLoadErrorNone
| ImlibLoadErrorFileDoesNotExist
| ImlibLoadErrorFileIsDirectory
| ImlibLoadErrorPermissionDeniedToRead
| ImlibLoadErrorNoLoaderForFileFormat
| ImlibLoadErrorPathTooLong
| ImlibLoadErrorPathComponentNonExistant
| ImlibLoadErrorPathComponentNotDirectory
| ImlibLoadErrorPathPointsOutsideAddressSpace
| ImlibLoadErrorTooManySymbolicLinks
| ImlibLoadErrorOutOfMemory
| ImlibLoadErrorOutOfFileDescriptors
| ImlibLoadErrorPermissionDeniedToWrite
| ImlibLoadErrorOutOfDiskSpace
| ImlibLoadErrorUnknown
deriving (Show, Enum, Eq)
data ImlibTTFEncoding = ImlibTTFEncodingISO88591
| ImlibTTFEncodingISO88592
| ImlibTTFEncodingISO88593
| ImlibTTFEncodingISO88594
| ImlibTTFEncodingISO88595
deriving (Enum, Show, Eq)
type ImlibProgressFunction = ImlibImage
-> Word8
-> CInt
-> CInt
-> CInt
-> CInt
-> IO CInt
foreign import ccall "wrapper" mkProgressFunction :: ImlibProgressFunction -> IO (FunPtr ImlibProgressFunction)
colorToBits :: ImlibColor -> Word32
colorToBits (ImlibColor a r g b) = fromIntegral (b + (g `shift` 8) + (r `shift` 16) + (a `shift` 24))
colorFromBits :: Word32 -> ImlibColor
colorFromBits n = ImlibColor a r g b
where
b = fromIntegral $ n `mod` 256
g = fromIntegral $ (n `shift` (8)) `mod` 256
r = fromIntegral $ (n `shift` (16)) `mod` 256
a = fromIntegral $ (n `shift` (24)) `mod` 256
type ImlibDataDestructorFunction = ImlibImage -> Ptr () -> IO ()
foreign import ccall "wrapper" mkDestructorFunction :: ImlibDataDestructorFunction -> IO (FunPtr ImlibDataDestructorFunction)
foreign import ccall "static Imlib2.h imlib_context_set_dither_mask" imlibContextSetDitherMask :: Bool -> IO ()
contextSetDitherMask :: Bool -> IO ()
contextSetDitherMask = imlibContextSetDitherMask
foreign import ccall "static Imlib2.h imlib_context_set_anti_alias" imlibContextSetAntiAlias :: Bool -> IO ()
contextSetAntiAlias :: Bool -> IO ()
contextSetAntiAlias = imlibContextSetAntiAlias
foreign import ccall "static Imlib2.h imlib_context_set_dither" imlibContextSetDither :: Bool -> IO ()
contextSetDither :: Bool -> IO ()
contextSetDither = imlibContextSetDither
foreign import ccall "static Imlib2.h imlib_context_set_blend" imlibContextSetBlend :: Bool -> IO ()
contextSetBlend :: Bool -> IO ()
contextSetBlend = imlibContextSetBlend
foreign import ccall "static Imlib2.h imlib_context_set_color_modifier" imlibContextSetColorModifier :: ImlibColorModifier -> IO ()
contextSetColorModifier :: ImlibColorModifier -> IO ()
contextSetColorModifier = imlibContextSetColorModifier
foreign import ccall "static Imlib2.h imlib_context_set_operation" imlibContextSetOperation :: CInt -> IO ()
contextSetOperation :: ImlibOperation -> IO ()
contextSetOperation op = imlibContextSetOperation (fromIntegral $ fromEnum op)
foreign import ccall "static Imlib2.h imlib_context_set_font" imlibContextSetFont :: ImlibFont -> IO ()
contextSetFont :: ImlibFont -> IO ()
contextSetFont = imlibContextSetFont
foreign import ccall "static Imlib2.h imlib_context_set_direction" imlibContextSetDirection :: CInt -> IO ()
contextSetDirection :: ImlibTextDirection -> IO ()
contextSetDirection dir = imlibContextSetDirection (fromIntegral $ fromEnum dir)
foreign import ccall "static Imlib2.h imlib_context_set_angle" imlibContextSetAngle :: CDouble -> IO ()
contextSetAngle :: Double -> IO ()
contextSetAngle = imlibContextSetAngle . realToFrac
foreign import ccall "static Imlib2.h imlib_context_set_color" imlibContextSetColor :: CInt -> CInt -> CInt -> CInt -> IO ()
contextSetColor :: Int -> Int -> Int -> Int -> IO ()
contextSetColor r g b a = imlibContextSetColor (fromIntegral r) (fromIntegral g) (fromIntegral b) (fromIntegral a)
foreign import ccall "static Imlib2.h imlib_context_set_color_cmya" imlibContextSetColorCmya :: CInt -> CInt -> CInt -> CInt -> IO ()
contextSetColorCmya :: Int -> Int -> Int -> Int -> IO ()
contextSetColorCmya c m y a = imlibContextSetColorCmya (fromIntegral c) (fromIntegral m) (fromIntegral y) (fromIntegral a)
foreign import ccall "static Imlib2.h imlib_context_set_color_hsva" imlibContextSetColorHsva :: CInt -> CInt -> CInt -> CInt -> IO ()
contextSetColorHsva h s v a = imlibContextSetColorHsva (fromIntegral h) (fromIntegral s) (fromIntegral v) (fromIntegral a)
foreign import ccall "static Imlib2.h imlib_context_set_color_hlsa" imlibContextSetColorHlsa :: CInt -> CInt -> CInt -> CInt -> IO ()
contextSetColorHlsa h l s a = imlibContextSetColorHlsa (fromIntegral h) (fromIntegral l) (fromIntegral s) (fromIntegral a)
foreign import ccall "static Imlib2.h imlib_context_set_color_range" imlibContextSetColorRange :: ImlibColorRange -> IO ()
contextSetColorRange :: ImlibColorRange -> IO ()
contextSetColorRange = imlibContextSetColorRange
foreign import ccall "static Imlib2.h imlib_context_set_progress_function" imlibContextSetProgressFunction :: FunPtr(ImlibProgressFunction) -> IO ()
contextSetProgressFunction f = do
fn <- mkProgressFunction f
imlibContextSetProgressFunction fn
foreign import ccall "static Imlib2.h imlib_context_set_progress_granularity" imlibContextSetProgressGranularity :: Word8 -> IO ()
contextSetProgressGranularity :: Word8 -> IO ()
contextSetProgressGranularity = imlibContextSetProgressGranularity
foreign import ccall "static Imlib2.h imlib_context_set_filter" imlibContextSetFilter :: ImlibFilter -> IO ()
contextSetFilter :: ImlibFilter -> IO ()
contextSetFilter = imlibContextSetFilter
foreign import ccall "static Imlib2.h imlib_context_set_image" imlibContextSetImage :: ImlibImage -> IO ()
contextSetImage :: ImlibImage -> IO ()
contextSetImage = imlibContextSetImage
foreign import ccall "static Imlib2.h imlib_context_get_dither_mask" imlibContextGetDitherMask :: IO Bool
contextGetDitherMask :: IO Bool
contextGetDitherMask = imlibContextGetDitherMask
foreign import ccall "static Imlib2.h imlib_context_get_anti_alias" imlibContextGetAntiAlias :: IO Bool
contextGetAntiAlias :: IO Bool
contextGetAntiAlias = imlibContextGetAntiAlias
foreign import ccall "static Imlib2.h imlib_context_get_dither" imlibContextGetDither :: IO Bool
contextGetDither :: IO Bool
contextGetDither = imlibContextGetDither
foreign import ccall "static Imlib2.h imlib_context_get_blend" imlibContextGetBlend :: IO Bool
contextGetBlend :: IO Bool
contextGetBlend = imlibContextGetBlend
foreign import ccall "static Imlib2.h imlib_context_get_color_modifier" imlibContextGetColorModifier :: IO ImlibColorModifier
contextGetColorModifier :: IO ImlibColorModifier
contextGetColorModifier = imlibContextGetColorModifier
foreign import ccall "static Imlib2.h imlib_context_get_operation" imlibContextGetOperation :: IO CInt
contextGetOperation :: IO ImlibOperation
contextGetOperation = do
i <- imlibContextGetOperation
return (toEnum $ fromIntegral i)
foreign import ccall "static Imlib2.h imlib_context_get_font" imlibContextGetFont :: IO ImlibFont
contextGetFont :: IO ImlibFont
contextGetFont = imlibContextGetFont
foreign import ccall "static Imlib2.h imlib_context_get_angle" imlibContextGetAngle :: IO CDouble
contextGetAngle :: IO Double
contextGetAngle = imlibContextGetAngle >>= return . realToFrac
foreign import ccall "static Imlib2.h imlib_context_get_direction" imlibContextGetDirection :: IO CInt
contextGetDirection :: IO ImlibTextDirection
contextGetDirection = do
d <- imlibContextGetDirection
return (toEnum $ fromIntegral d)
foreign import ccall "static Imlib2.h imlib_context_get_color" imlibContextGetColor :: Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
contextGetColor :: IO (Int, Int, Int, Int)
contextGetColor = do
[r,g,b,a] <- nmalloc 4
imlibContextGetColor r g b a
[rr,gg,bb,aa] <- liftM (map fromIntegral) $ mapM peek [r,g,b,a]
mapM free [r,g,b,a]
return (rr,gg,bb,aa)
foreign import ccall "static Imlib2.h imlib_context_get_color_cmya" imlibContextGetColorCmya :: Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
contextGetColorCmya :: IO (Int, Int, Int, Int)
contextGetColorCmya = do
[c,m,y,a] <- nmalloc 4
imlibContextGetColorCmya c m y a
[cc,mm,yy,aa] <- liftM (map fromIntegral) $ mapM peek [c,m,y,a]
mapM free [c,m,y,a]
return (cc,mm,yy,aa)
foreign import ccall "static Imlib2.h imlib_context_get_color_hsva" imlibContextGetColorHsva :: Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
contextGetColorHsva :: IO (Int, Int, Int, Int)
contextGetColorHsva = do
[h,s,v,a] <- nmalloc 4
imlibContextGetColorHsva h s v a
[hh,ss,vv,aa] <- liftM (map fromIntegral) $ mapM peek [h,s,v,a]
mapM free [h,s,v,a]
return (hh,ss,vv,aa)
foreign import ccall "static Imlib2.h imlib_context_get_color_hlsa" imlibContextGetColorHlsa :: Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
contextGetColorHlsa :: IO (Int, Int, Int, Int)
contextGetColorHlsa = do
[h,l,s,a] <- nmalloc 4
imlibContextGetColorHlsa h l s a
[hh,ll,ss,aa] <- liftM (map fromIntegral) $ mapM peek [h,l,s,a]
mapM free [h,l,s,a]
return (hh,ll,ss,aa)
foreign import ccall "static Imlib2.h imlib_context_get_imlib_color" imlibContextGetImlibColor :: IO (Ptr ImlibColor)
contextGetImlibColor :: IO ImlibColor
contextGetImlibColor = do
c <- imlibContextGetImlibColor
cc <- peek c
free c
return cc
foreign import ccall "static Imlib2.h imlib_context_get_color_range" imlibContextGetColorRange :: IO ImlibColorRange
contextGetColorRange :: IO ImlibColorRange
contextGetColorRange = imlibContextGetColorRange
foreign import ccall "static Imlib2.h imlib_context_get_progress_function" imlibContextGetProgressFunction :: IO (FunPtr ImlibProgressFunction)
contextGetProgressFunction = imlibContextGetProgressFunction
foreign import ccall "static Imlib2.h imlib_context_get_progress_granularity" imlibContextGetProgressGranularity :: IO Word8
contextGetProgressGranularity :: IO Word8
contextGetProgressGranularity = imlibContextGetProgressGranularity
foreign import ccall "static Imlib2.h imlib_context_get_image" imlibContextGetImage :: IO ImlibImage
contextGetImage :: IO ImlibImage
contextGetImage = imlibContextGetImage
foreign import ccall "static Imlib2.h imlib_context_get_filter" imlibContextGetFilter :: IO ImlibFilter
contextGetFilter :: IO ImlibFilter
contextGetFilter = imlibContextGetFilter
foreign import ccall "static Imlib2.h imlib_get_cache_size" imlibGetCacheSize :: IO CInt
getCacheSize :: IO Int
getCacheSize = imlibGetCacheSize >>= return . fromIntegral
foreign import ccall "static Imlib2.h imlib_set_cache_size" imlibSetCacheSize :: Int -> IO ()
setCacheSize :: Int -> IO ()
setCacheSize = imlibSetCacheSize
foreign import ccall "static Imlib2.h imlib_get_color_usage" imlibGetColorUsage :: IO CInt
getColorUsage :: IO Int
getColorUsage = imlibGetColorUsage >>= return . fromIntegral
foreign import ccall "static Imlib2.h imlib_set_color_usage" imlibSetColorUsage :: CInt -> IO ()
setColorUsage :: Int -> IO ()
setColorUsage = imlibSetColorUsage . fromIntegral
foreign import ccall "static Imlib2.h imlib_flush_loaders" imlibFlushLoaders :: IO ()
flushLoaders :: IO ()
flushLoaders = imlibFlushLoaders
foreign import ccall "static Imlib2.h imlib_load_image" imlibLoadImage :: CString -> IO ImlibImage
loadImage :: String -> IO ImlibImage
loadImage str = withCString str imlibLoadImage
foreign import ccall "static Imlib2.h imlib_load_image_immediately" imlibLoadImageImmediately :: CString -> IO ImlibImage
loadImageImmediately :: String -> IO ImlibImage
loadImageImmediately str = withCString str imlibLoadImageImmediately
foreign import ccall "static Imlib2.h imlib_load_image_without_cache" imlibLoadImageWithoutCache :: CString -> IO ImlibImage
loadImageWithoutCache :: String -> IO ImlibImage
loadImageWithoutCache str = withCString str imlibLoadImageWithoutCache
foreign import ccall "static Imlib2.h imlib_load_image_immediately_without_cache" imlibLoadImageImmediatelyWithoutCache :: CString -> IO ImlibImage
loadImageImmediatelyWithoutCache str = withCString str imlibLoadImageImmediatelyWithoutCache
foreign import ccall "static Imlib2.h imlib_load_image_with_error_return" imlibLoadImageWithErrorReturn :: CString -> Ptr CInt -> IO ImlibImage
loadImageWithErrorReturn :: String -> IO (ImlibImage, ImlibLoadError)
loadImageWithErrorReturn str = do
pe <- malloc
im <- withCString str (\s -> imlibLoadImageWithErrorReturn s pe)
e <- peek pe
free pe
return (im, toEnum $ fromIntegral e)
foreign import ccall "static Imlib2.h imlib_free_image" imlibFreeImage :: IO ()
freeImage :: IO ()
freeImage = imlibFreeImage
foreign import ccall "static Imlib2.h imlib_free_image_and_decache" imlibFreeImageAndDecache :: IO ()
freeImageAndDecache :: IO ()
freeImageAndDecache = imlibFreeImageAndDecache
foreign import ccall "static Imlib2.h imlib_image_get_width" imlibImageGetWidth :: IO CInt
imageGetWidth :: IO Int
imageGetWidth = imlibImageGetWidth >>= return . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_get_height" imlibImageGetHeight :: IO CInt
imageGetHeight :: IO Int
imageGetHeight = imlibImageGetHeight >>= return . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_get_filename" imlibImageGetFilename :: IO CString
imageGetFilename :: IO String
imageGetFilename = do
b <- imlibImageGetFilename
peekCString b
foreign import ccall "static Imlib2.h imlib_image_get_data" imlibImageGetData :: IO (Ptr Word32)
imageGetData :: IO (Ptr Word32)
imageGetData = imlibImageGetData
foreign import ccall "static Imlib2.h imlib_image_get_data_for_reading_only" imlibImageGetDataForReadingOnly :: IO (Ptr Word32)
imageGetDataForReadingOnly :: IO (Ptr Word32)
imageGetDataForReadingOnly = imlibImageGetDataForReadingOnly
foreign import ccall "static Imlib2.h imlib_image_put_back_data" imlibImagePutBackData :: Ptr Word32 -> IO ()
imagePutBackData :: Ptr Word32 -> IO ()
imagePutBackData = imlibImagePutBackData
imageWithData :: (Ptr Word32 -> IO a) -> IO a
imageWithData f = do
p <- imageGetData
r <- f p
imagePutBackData p
return r
withImageBits :: (Int -> Int -> [Word32] -> [Word32]) -> IO ()
withImageBits f = do
w <- imageGetWidth
h <- imageGetHeight
p <- imageGetData
arr <- peekArray (w*h) p
pokeArray p $ f w h arr
imagePutBackData p
withImage :: (Int -> Int -> [ImlibColor] -> [ImlibColor]) -> IO ()
withImage f = do
w <- imageGetWidth
h <- imageGetHeight
p <- imageGetData
arr <- peekArray (w*h) p
pokeArray p . map colorToBits . f w h . map colorFromBits $ arr
imagePutBackData p
foreign import ccall "static Imlib2.h imlib_image_has_alpha" imlibImageHasAlpha :: IO Bool
imageHasAlpha :: IO Bool
imageHasAlpha = imlibImageHasAlpha
foreign import ccall "static Imlib2.h imlib_image_set_changes_on_disk" imlibImageSetChangesOnDisk :: IO ()
imageSetChangesOnDisk :: IO ()
imageSetChangesOnDisk = imlibImageSetChangesOnDisk
foreign import ccall "static Imlib2.h imlib_image_get_border" imlibImageGetBorder :: Ptr ImlibBorder -> IO ()
imageGetBorder :: IO ImlibBorder
imageGetBorder = do
b <- malloc
imlibImageGetBorder b
bb <- peek b
free b
return bb
foreign import ccall "static Imlib2.h imlib_image_set_border" imlibImageSetBorder :: Ptr ImlibBorder -> IO ()
imageSetBorder :: ImlibBorder -> IO ()
imageSetBorder b = do
p <- malloc
poke p b
imlibImageSetBorder p
free p
foreign import ccall "static Imlib2.h imlib_image_set_format" imlibImageSetFormat :: CString -> IO ()
imageSetFormat :: String -> IO ()
imageSetFormat str = withCString str imlibImageSetFormat
foreign import ccall "static Imlib2.h imlib_image_set_irrelevant_format" imlibImageSetIrrelevantFormat :: Bool -> IO ()
imageSetIrrelevantFormat :: Bool -> IO ()
imageSetIrrelevantFormat = imlibImageSetIrrelevantFormat
foreign import ccall "static Imlib2.h imlib_image_set_irrelevant_border" imlibImageSetIrrelevantBorder :: Bool -> IO ()
imageSetIrrelevantBorder :: Bool -> IO ()
imageSetIrrelevantBorder = imlibImageSetIrrelevantBorder
foreign import ccall "static Imlib2.h imlib_image_set_irrelevant_alpha" imlibImageSetIrrelevantAlpha :: Bool -> IO ()
imageSetIrrelevantAlpha :: Bool -> IO ()
imageSetIrrelevantAlpha = imlibImageSetIrrelevantAlpha
foreign import ccall "static Imlib2.h imlib_image_format" imlibImageFormat :: IO CString
imageFormat :: IO String
imageFormat = imlibImageFormat >>= peekCString
foreign import ccall "static Imlib2.h imlib_image_set_has_alpha" imlibImageSetHasAlpha :: Bool -> IO ()
imageSetHasAlpha :: Bool -> IO ()
imageSetHasAlpha = imlibImageSetHasAlpha
foreign import ccall "static Imlib2.h imlib_blend_image_onto_image" imlibBlendImageOntoImage
:: ImlibImage
-> Bool
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> IO ()
blendImageOntoImage img mergeAlpha (sx, sy, sw, sh) (dx, dy, dw, dh) = imlibBlendImageOntoImage img mergeAlpha (fromIntegral sx) (fromIntegral sy) (fromIntegral sw) (fromIntegral sh) (fromIntegral dx) (fromIntegral dy) (fromIntegral dw) (fromIntegral dh)
foreign import ccall "static Imlib2.h imlib_create_image" imlibCreateImage :: CInt -> CInt -> IO ImlibImage
createImage :: Int -> Int -> IO ImlibImage
createImage w h = imlibCreateImage (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_create_image_using_data" imlibCreateImageUsingData :: CInt -> CInt -> Ptr Word32 -> IO ImlibImage
createImageUsingData :: Int -> Int -> Ptr Word32 -> IO ImlibImage
createImageUsingData w h ptr = imlibCreateImageUsingData (fromIntegral w) (fromIntegral h) ptr
foreign import ccall "static Imlib2.h imlib_create_image_using_copied_data" imlibCreateImageUsingCopiedData :: CInt -> CInt -> Ptr(Word32) -> IO ImlibImage
createImageUsingCopiedData w h ptr = imlibCreateImageUsingCopiedData (fromIntegral w) (fromIntegral h) ptr
createImageUsingList :: Int -> Int -> [ImlibColor] -> IO ImlibImage
createImageUsingList w h xs = withArray (map colorToBits xs) (createImageUsingCopiedData w h)
createImageUsingArray :: Array (Int, Int) ImlibColor -> IO ImlibImage
createImageUsingArray a = createImageUsingList (bt+1) (rl+1) (elems a)
where ((t,l),(b,r)) = bounds a
foreign import ccall "static Imlib2.h imlib_clone_image" imlibCloneImage :: IO ImlibImage
cloneImage :: IO ImlibImage
cloneImage = imlibCloneImage
foreign import ccall "static Imlib2.h imlib_create_cropped_image" imlibCreateCroppedImage :: CInt -> CInt -> CInt -> CInt -> IO ImlibImage
createCroppedImage x y w h = imlibCreateCroppedImage (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_create_cropped_scaled_image" imlibCreateCroppedScaledImage :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ImlibImage
createCroppedScaledImage sx sy sw sh dw dh = imlibCreateCroppedScaledImage (fromIntegral sx) (fromIntegral sy) (fromIntegral sw) (fromIntegral sh) (fromIntegral dw) (fromIntegral dh)
foreign import ccall "static Imlib2.h imlib_updates_clone" imlibUpdatesClone :: ImlibUpdates -> IO ImlibUpdates
updatesClone :: ImlibUpdates -> IO ImlibUpdates
updatesClone = imlibUpdatesClone
foreign import ccall "static Imlib2.h imlib_update_append_rect" imlibUpdateAppendRect :: ImlibUpdates -> CInt -> CInt -> CInt -> CInt -> IO ImlibUpdates
updateAppendRect u x y w h = imlibUpdateAppendRect u (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_updates_merge" imlibUpdatesMerge :: ImlibUpdates -> CInt -> CInt -> IO ImlibUpdates
updatesMerge u w h = imlibUpdatesMerge u (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_updates_merge_for_rendering" imlibUpdatesMergeForRendering :: ImlibUpdates -> CInt -> CInt -> IO ImlibUpdates
updatesMergeForRendering u w h = imlibUpdatesMergeForRendering u (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_updates_free" imlibUpdatesFree :: ImlibUpdates -> IO ()
updatesFree :: ImlibUpdates -> IO ()
updatesFree = imlibUpdatesFree
foreign import ccall "static Imlib2.h imlib_updates_get_next" imlibUpdatesGetNext :: ImlibUpdates -> IO ImlibUpdates
updatesGetNext :: ImlibUpdates -> IO ImlibUpdates
updatesGetNext = imlibUpdatesGetNext
foreign import ccall "static Imlib2.h imlib_updates_get_coordinates" imlibUpdatesGetCoordinates :: ImlibUpdates -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
updatesGetCoordinates :: ImlibUpdates -> IO (Int, Int, Int, Int)
updatesGetCoordinates u = do
[x,y,w,h] <- nmalloc 4
imlibUpdatesGetCoordinates u x y w h
[xx,yy,ww,hh] <- liftM (map fromIntegral) $ mapM peek [x,y,w,h]
mapM free [x,y,w,h]
return (xx,yy,ww,hh)
foreign import ccall "static Imlib2.h imlib_updates_set_coordinates" imlibUpdatesSetCoordinates :: ImlibUpdates -> CInt -> CInt -> CInt -> CInt -> IO ()
updatesSetCoordinates u x y w h = imlibUpdatesSetCoordinates u (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_updates_init" imlibUpdatesInit :: IO ImlibUpdates
updatesInit :: IO ImlibUpdates
updatesInit = imlibUpdatesInit
foreign import ccall "static Imlib2.h imlib_updates_append_updates" imlibUpdatesAppendUpdates :: ImlibUpdates -> ImlibUpdates -> IO ImlibUpdates
updatesAppendUpdates = imlibUpdatesAppendUpdates
foreign import ccall "static Imlib2.h imlib_image_flip_horizontal" imlibImageFlipHorizontal :: IO ()
imageFlipHorizontal :: IO ()
imageFlipHorizontal = imlibImageFlipHorizontal
foreign import ccall "static Imlib2.h imlib_image_flip_vertical" imlibImageFlipVertical :: IO ()
imageFlipVertical :: IO ()
imageFlipVertical = imlibImageFlipVertical
foreign import ccall "static Imlib2.h imlib_image_flip_diagonal" imlibImageFlipDiagonal :: IO ()
imageFlipDiagonal :: IO ()
imageFlipDiagonal = imlibImageFlipDiagonal
foreign import ccall "static Imlib2.h imlib_image_orientate" imlibImageOrientate :: CInt -> IO ()
imageOrientate :: Int -> IO ()
imageOrientate = imlibImageOrientate . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_blur" imlibImageBlur :: CInt -> IO ()
imageBlur :: Int -> IO ()
imageBlur = imlibImageBlur . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_sharpen" imlibImageSharpen :: CInt -> IO ()
imageSharpen :: Int -> IO ()
imageSharpen = imlibImageSharpen . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_tile_horizontal" imlibImageTileHorizontal :: IO ()
imageTileHorizontal :: IO ()
imageTileHorizontal = imlibImageTileHorizontal
foreign import ccall "static Imlib2.h imlib_image_tile_vertical" imlibImageTileVertical :: IO ()
imageTileVertical :: IO ()
imageTileVertical = imlibImageTileVertical
foreign import ccall "static Imlib2.h imlib_image_tile" imlibImageTile :: IO ()
imageTile :: IO ()
imageTile = imlibImageTile
foreign import ccall "static Imlib2.h imlib_load_font" imlibLoadFont :: CString -> IO ImlibFont
loadFont :: String -> IO ImlibFont
loadFont str = withCString str imlibLoadFont
foreign import ccall "static Imlib2.h imlib_free_font" imlibFreeFont :: IO ()
freeFont :: forall t. t -> IO ()
freeFont _ = imlibFreeFont
foreign import ccall "static Imlib2.h imlib_text_draw" imlibTextDraw :: CInt -> CInt -> CString -> IO ()
textDraw :: Int -> Int -> String -> IO ()
textDraw x y str = withCString str (imlibTextDraw (fromIntegral x) (fromIntegral y))
foreign import ccall "static Imlib2.h imlib_text_draw_with_return_metrics" imlibTextDrawWithReturnMetrics :: CInt -> CInt -> CString -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
textDrawWithReturnMetrics x y str = do
[w,h,ah,av] <- nmalloc 4
withCString str (\s -> imlibTextDrawWithReturnMetrics (fromIntegral x) (fromIntegral y) s w h ah av)
[rw,rh,rah,rav] <- liftM (map fromIntegral) $ mapM peek [w,h,ah,av]
mapM free [w,h,ah,av]
return (rw,rh,rah,rav)
foreign import ccall "static Imlib2.h imlib_get_text_size" imlibGetTextSize :: CString -> Ptr CInt -> Ptr CInt -> IO ()
getTextSize :: String -> IO (Int, Int)
getTextSize str = do
[w,h] <- nmalloc 2
withCString str (\s -> imlibGetTextSize s w h)
[rw,rh] <- mapM peek [w,h]
mapM free [w,h]
return (fromIntegral rw,fromIntegral rh)
foreign import ccall "static Imlib2.h imlib_get_text_advance" imlibGetTextAdvance :: CString -> Ptr CInt -> Ptr CInt -> IO ()
getTextAdvance :: String -> IO (Int, Int)
getTextAdvance str = do
[h,v] <- nmalloc 2
withCString str (\s -> imlibGetTextAdvance s h v)
[rh,rv] <- mapM peek [h,v]
mapM free [h,v]
return (fromIntegral rh,fromIntegral rv)
foreign import ccall "static Imlib2.h imlib_get_text_inset" imlibGetTextInset :: CString -> IO CInt
getTextInset :: String -> IO Int
getTextInset str = withCString str $ liftM fromIntegral . imlibGetTextInset
foreign import ccall "static Imlib2.h imlib_add_path_to_font_path" imlibAddPathToFontPath :: CString -> IO ()
addPathToFontPath :: String -> IO ()
addPathToFontPath str = withCString str imlibAddPathToFontPath
foreign import ccall "static Imlib2.h imlib_remove_path_from_font_path" imlibRemovePathFromFontPath :: CString -> IO ()
removePathFromFontPath :: String -> IO ()
removePathFromFontPath str = withCString str imlibRemovePathFromFontPath
foreign import ccall "static Imlib2.h imlib_list_font_path" imlibListFontPath :: Ptr CInt -> IO (Ptr CString)
listFontPath :: IO [String]
listFontPath = do
pn <- malloc
pxs <- imlibListFontPath pn
n <- peek pn
free pn
xs <- peekArray (fromIntegral n) pxs
ys <- mapM peekCString xs
return ys
foreign import ccall "static Imlib2.h imlib_text_get_index_and_location" imlibTextGetIndexAndLocation :: CString -> CInt -> CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
textGetIndexAndLocation str x y = do
[xp,yp,wp,hp] <- nmalloc 4
n <- withCString str (\s -> imlibTextGetIndexAndLocation s x y xp yp wp hp)
[xr,yr,wr,hr] <- mapM peek [xp,yp,wp,hp]
mapM free [xp,yp,wp,hp]
return (fromIntegral n, fromIntegral xr, fromIntegral yr, fromIntegral wr, fromIntegral hr)
foreign import ccall "static Imlib2.h imlib_text_get_location_at_index" imlibTextGetLocationAtIndex :: CString -> CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
textGetLocationAtIndex str k = do
[xp,yp,wp,hp] <- nmalloc 4
withCString str (\s -> imlibTextGetLocationAtIndex s k xp yp wp hp)
[xr,yr,wr,hr] <- mapM peek [xp,yp,wp,hp]
mapM free [xp,yp,wp,hp]
return (fromIntegral xr, fromIntegral yr, fromIntegral wr, fromIntegral hr)
foreign import ccall "static Imlib2.h imlib_list_fonts" imlibListFonts :: Ptr CInt -> IO (Ptr CString)
foreign import ccall "static Imlib2.h imlib_free_font_list" imlibFreeFontList :: Ptr (CString) -> CInt -> IO ()
listFonts :: IO [String]
listFonts = do
pn <- malloc
pxs <- imlibListFonts pn
n <- peek pn
free pn
xs <- peekArray (fromIntegral n) pxs
ys <- mapM peekCString xs
imlibFreeFontList pxs n
return ys
foreign import ccall "static Imlib2.h imlib_get_font_cache_size" imlibGetFontCacheSize :: IO CInt
getFontCacheSize :: IO Int
getFontCacheSize = liftM fromIntegral imlibGetFontCacheSize
foreign import ccall "static Imlib2.h imlib_set_font_cache_size" imlibSetFontCacheSize :: CInt -> IO ()
setFontCacheSize :: Int -> IO ()
setFontCacheSize = imlibSetFontCacheSize . fromIntegral
foreign import ccall "static Imlib2.h imlib_flush_font_cache" imlibFlushFontCache :: IO ()
flushFontCache :: IO ()
flushFontCache = imlibFlushFontCache
foreign import ccall "static Imlib2.h imlib_get_font_ascent" imlibGetFontAscent :: IO CInt
getFontAscent :: IO Int
getFontAscent = liftM fromIntegral imlibGetFontAscent
foreign import ccall "static Imlib2.h imlib_get_font_descent" imlibGetFontDescent :: IO CInt
getFontDescent :: IO Int
getFontDescent = liftM fromIntegral imlibGetFontDescent
foreign import ccall "static Imlib2.h imlib_get_maximum_font_ascent" imlibGetMaximumFontAscent :: IO CInt
getMaximumFontAscent :: IO Int
getMaximumFontAscent = liftM fromIntegral imlibGetMaximumFontAscent
foreign import ccall "static Imlib2.h imlib_get_maximum_font_descent" imlibGetMaximumFontDescent :: IO CInt
getMaximumFontDescent :: IO Int
getMaximumFontDescent = liftM fromIntegral imlibGetMaximumFontDescent
foreign import ccall "static Imlib2.h imlib_create_color_modifier" imlibCreateColorModifier :: IO ImlibColorModifier
createColorModifier :: IO ImlibColorModifier
createColorModifier = imlibCreateColorModifier
foreign import ccall "static Imlib2.h imlib_free_color_modifier" imlibFreeColorModifier :: IO ()
freeColorModifier :: IO ()
freeColorModifier = imlibFreeColorModifier
foreign import ccall "static Imlib2.h imlib_modify_color_modifier_gamma" imlibModifyColorModifierGamma :: CDouble -> IO ()
modifyColorModifierGamma :: Double -> IO ()
modifyColorModifierGamma = imlibModifyColorModifierGamma . fromRational . toRational
foreign import ccall "static Imlib2.h imlib_modify_color_modifier_brightness" imlibModifyColorModifierBrightness :: CDouble -> IO ()
modifyColorModifierBrightness :: Double -> IO ()
modifyColorModifierBrightness = imlibModifyColorModifierBrightness . fromRational . toRational
foreign import ccall "static Imlib2.h imlib_modify_color_modifier_contrast" imlibModifyColorModifierContrast :: CDouble -> IO ()
modifyColorModifierContrast :: Double -> IO ()
modifyColorModifierContrast = imlibModifyColorModifierContrast . fromRational . toRational
foreign import ccall "static Imlib2.h imlib_set_color_modifier_tables" imlibSetColorModifierTables :: (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> IO ()
setColorModifierTables r g b a = do
withArray rs (\ra ->
withArray gs (\ga ->
withArray bs (\ba ->
withArray as (\aa -> imlibSetColorModifierTables ra ga ba aa))))
where
padLeft n b xs | l > n = take n xs
| l < n = (replicate (nl) b) ++ xs
| otherwise = xs
where l = length xs
rs = padLeft 256 0 r
gs = padLeft 256 0 g
bs = padLeft 256 0 b
as = padLeft 256 0 a
foreign import ccall "static Imlib2.h imlib_get_color_modifier_tables" imlibGetColorModifierTables :: (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> IO ()
getColorModifierTables = do
[ra,ga,ba,aa] <- nmallocArray 4 256
imlibGetColorModifierTables ra ga ba aa
[rs,gs,bs,as] <- mapM (peekArray 256) [ra,ga,ba,aa]
mapM free [ra,ga,ba,aa]
return (rs,gs,bs,as)
foreign import ccall "static Imlib2.h imlib_reset_color_modifier" imlibResetColorModifier :: IO ()
resetColorModifier :: IO ()
resetColorModifier = imlibResetColorModifier
foreign import ccall "static Imlib2.h imlib_apply_color_modifier" imlibApplyColorModifier :: IO ()
applyColorModifier :: IO ()
applyColorModifier = imlibApplyColorModifier
foreign import ccall "static Imlib2.h imlib_apply_color_modifier_to_rectangle" imlibApplyColorModifierToRectangle :: CInt -> CInt -> CInt -> CInt -> IO ()
applyColorModifierToRectangle :: Int -> Int -> Int -> Int -> IO ()
applyColorModifierToRectangle x y w h = do
imlibApplyColorModifierToRectangle (fromIntegral x) (fromIntegral x) (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_image_draw_line" imlibImageDrawLine :: CInt -> CInt -> CInt -> CInt -> Bool -> IO ImlibUpdates
imageDrawLine :: Int -> Int -> Int -> Int -> Bool -> IO ImlibUpdates
imageDrawLine x1 y1 x2 y2 mu = do
imlibImageDrawLine (fromIntegral x1) (fromIntegral y1) (fromIntegral x2) (fromIntegral y2) mu
foreign import ccall "static Imlib2.h imlib_image_draw_rectangle" imlibImageDrawRectangle :: CInt -> CInt -> CInt -> CInt -> IO ()
imageDrawRectangle :: Int -> Int -> Int -> Int -> IO ()
imageDrawRectangle x y w h = do
imlibImageDrawRectangle (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_image_fill_rectangle" imlibImageFillRectangle :: CInt -> CInt -> CInt -> CInt -> IO ()
imageFillRectangle :: Int -> Int -> Int -> Int -> IO ()
imageFillRectangle x y w h = do
imlibImageFillRectangle (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h)
foreign import ccall "static Imlib2.h imlib_image_copy_alpha_to_image" imlibImageCopyAlphaToImage :: ImlibImage -> CInt -> CInt -> IO ()
imageCopyAlphaToImage :: ImlibImage -> Int -> Int -> IO ()
imageCopyAlphaToImage im x y = do
imlibImageCopyAlphaToImage im (fromIntegral x) (fromIntegral y)
foreign import ccall "static Imlib2.h imlib_image_copy_alpha_rectangle_to_image" imlibImageCopyAlphaRectangleToImage :: ImlibImage -> CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
imageCopyAlphaRectangleToImage img x y w h dx dy = imlibImageCopyAlphaRectangleToImage img (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) (fromIntegral dx) (fromIntegral dy)
foreign import ccall "static Imlib2.h imlib_image_scroll_rect" imlibImageScrollRect :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
imageScrollRect x y w h dx dy = imlibImageScrollRect (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) (fromIntegral dx) (fromIntegral dy)
foreign import ccall "static Imlib2.h imlib_image_copy_rect" imlibImageCopyRect :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
imageCopyRect x y w h dx dy = imlibImageCopyRect (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) (fromIntegral dx) (fromIntegral dy)
foreign import ccall "static Imlib2.h imlib_create_color_range" imlibCreateColorRange :: IO ImlibColorRange
createColorRange :: IO ImlibColorRange
createColorRange = imlibCreateColorRange
foreign import ccall "static Imlib2.h imlib_free_color_range" imlibFreeColorRange :: IO ()
freeColorRange :: IO ()
freeColorRange = imlibFreeColorRange
foreign import ccall "static Imlib2.h imlib_add_color_to_color_range" imlibAddColorToColorRange :: CInt -> IO ()
addColorToColorRange :: Int -> IO ()
addColorToColorRange = imlibAddColorToColorRange . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_fill_color_range_rectangle" imlibImageFillColorRangeRectangle :: CInt -> CInt -> CInt -> CInt -> CDouble -> IO ()
imageFillColorRangeRectangle x y w h a = imlibImageFillColorRangeRectangle (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) (realToFrac a)
foreign import ccall "static Imlib2.h imlib_image_fill_hsva_color_range_rectangle" imlibImageFillHsvaColorRangeRectangle :: CInt -> CInt -> CInt -> CInt -> CDouble -> IO ()
imageFillHsvaColorRangeRectangle x y w h a = imlibImageFillHsvaColorRangeRectangle (fromIntegral x) (fromIntegral y) (fromIntegral w) (fromIntegral h) (realToFrac a)
foreign import ccall "static Imlib2.h imlib_image_query_pixel" imlibImageQueryPixel :: CInt -> CInt -> Ptr ImlibColor -> IO ()
imageQueryPixel :: Int -> Int -> IO ImlibColor
imageQueryPixel x y = do
c <- malloc
imlibImageQueryPixel (fromIntegral x) (fromIntegral y) c
r <- peek c
free c
return r
foreign import ccall "static Imlib2.h imlib_image_query_pixel_cmya" imlibImageQueryPixelCmya :: CInt -> CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
imageQueryPixelCmya :: Int -> Int -> IO (Int, Int, Int, Int)
imageQueryPixelCmya cx cy = do
[c,m,y,a] <- nmalloc 4
imlibImageQueryPixelCmya (fromIntegral cx) (fromIntegral cy) c m y a
[cc,mm,yy,aa] <- liftM (map fromIntegral) $ mapM peek [c,m,y,a]
mapM free [c,m,y,a]
return (cc,mm,yy,aa)
foreign import ccall "static Imlib2.h imlib_image_query_pixel_hsva" imlibImageQueryPixelHsva :: CInt -> CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
imageQueryPixelHsva :: Int -> Int -> IO (Int, Int, Int, Int)
imageQueryPixelHsva cx cy = do
[h,s,v,a] <- nmalloc 4
imlibImageQueryPixelHsva (fromIntegral cx) (fromIntegral cy) h s v a
[hh,ss,vv,aa] <- liftM (map fromIntegral) $ mapM peek [h,s,v,a]
mapM free [h,s,v,a]
return (hh,ss,vv,aa)
foreign import ccall "static Imlib2.h imlib_image_query_pixel_hlsa" imlibImageQueryPixelHlsa :: CInt -> CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
imageQueryPixelHlsa :: Int -> Int -> IO (Int, Int, Int, Int)
imageQueryPixelHlsa cx cy = do
[h,l,s,a] <- nmalloc 4
imlibImageQueryPixelHlsa (fromIntegral cx) (fromIntegral cy) h l s a
[hh,ll,ss,aa] <- liftM (map fromIntegral) $ mapM peek [h,l,s,a]
mapM free [h,l,s,a]
return (hh,ll,ss,aa)
foreign import ccall "static Imlib2.h imlib_image_attach_data_value" imlibImageAttachDataValue :: CString -> Ptr () -> Int -> FunPtr ImlibDataDestructorFunction -> IO ()
imageAttachDataValue key d v dest = do
df <- mkDestructorFunction dest
withCString key (\k -> imlibImageAttachDataValue k d v df)
foreign import ccall "static Imlib2.h imlib_image_get_attached_data" imlibImageGetAttachedData :: CString -> IO (Ptr ())
imageGetAttachedData :: String -> IO (Ptr ())
imageGetAttachedData key = withCString key imlibImageGetAttachedData
foreign import ccall "static Imlib2.h imlib_image_get_attached_value" imlibImageGetAttachedValue :: CString -> IO CInt
imageGetAttachedValue :: String -> IO Int
imageGetAttachedValue key = withCString key imlibImageGetAttachedValue >>= return . fromIntegral
foreign import ccall "static Imlib2.h imlib_image_remove_attached_data_value" imlibImageRemoveAttachedDataValue :: CString -> IO ()
imageRemoveAttachedDataValue :: String -> IO ()
imageRemoveAttachedDataValue key = withCString key imlibImageRemoveAttachedDataValue
foreign import ccall "static Imlib2.h imlib_image_remove_and_free_attached_data_value" imlibImageRemoveAndFreeAttachedDataValue :: CString -> IO ()
imageRemoveAndFreeAttachedDataValue key = withCString key imlibImageRemoveAndFreeAttachedDataValue
foreign import ccall "static Imlib2.h imlib_save_image" imlibSaveImage :: CString -> IO ()
saveImage :: String -> IO ()
saveImage str = withCString str imlibSaveImage
foreign import ccall "static Imlib2.h imlib_save_image_with_error_return" imlibSaveImageWithErrorReturn :: CString -> Ptr CInt -> IO ()
saveImageWithErrorReturn :: String -> IO ImlibLoadError
saveImageWithErrorReturn str = do
pe <- malloc
im <- withCString str (\s -> imlibSaveImageWithErrorReturn s pe)
e <- peek pe
free pe
return (toEnum $ fromIntegral e)
foreign import ccall "static Imlib2.h imlib_create_rotated_image" imlibCreateRotatedImage :: CDouble -> IO ImlibImage
createRotatedImage :: Double -> IO ImlibImage
createRotatedImage = imlibCreateRotatedImage . realToFrac
foreign import ccall "static Imlib2.h imlib_blend_image_onto_image_at_angle" imlibBlendImageOntoImageAtAngle :: Ptr(ImlibImage)
-> Bool
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> IO ()
blendImageOntoImageAtAngle ptr mergeAlpha sx sy sw sh dx dy ax ay = imlibBlendImageOntoImageAtAngle ptr mergeAlpha (fromIntegral sx) (fromIntegral sy) (fromIntegral sw) (fromIntegral sh) (fromIntegral dx) (fromIntegral dy) (fromIntegral ax) (fromIntegral ay)
foreign import ccall "static Imlib2.h imlib_blend_image_onto_image_skewed" imlibBlendImageOntoImageSkewed :: Ptr(ImlibImage)
-> Bool
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> IO ()
blendImageOntoImageSkewed ptr mergeAlpha sx sy sw sh dx dy hx hy vx vy = imlibBlendImageOntoImageSkewed ptr mergeAlpha (fromIntegral sx) (fromIntegral sy) (fromIntegral sw) (fromIntegral sh) (fromIntegral dx) (fromIntegral dy) (fromIntegral hx) (fromIntegral hy) (fromIntegral vx) (fromIntegral vy)
foreign import ccall "static Imlib2.h imlib_context_set_cliprect" imlibContextSetCliprect :: Int -> Int -> Int -> Int -> IO ()
contextSetCliprect = imlibContextSetCliprect
foreign import ccall "static Imlib2.h imlib_polygon_new" imlibPolygonNew :: IO ()
polygonNew :: IO ()
polygonNew = imlibPolygonNew
foreign import ccall "static Imlib2.h imlib_polygon_free" imlibPolygonFree :: ImlibPolygon -> IO ()
polygonFree :: ImlibPolygon -> IO ()
polygonFree = imlibPolygonFree
foreign import ccall "static Imlib2.h imlib_polygon_add_point" imlibPolygonAddPoint :: ImlibPolygon -> CInt -> CInt -> IO ()
polygonAddPoint poly x y = imlibPolygonAddPoint poly (fromIntegral x) (fromIntegral y)
foreign import ccall "static Imlib2.h imlib_image_draw_polygon" imlibImageDrawPolygon :: ImlibPolygon -> Bool -> IO ()
imageDrawPolygon :: ImlibPolygon -> Bool -> IO ()
imageDrawPolygon = imlibImageDrawPolygon
foreign import ccall "static Imlib2.h imlib_image_fill_polygon" imlibImageFillPolygon :: ImlibPolygon -> IO ()
imageFillPolygon :: ImlibPolygon -> IO ()
imageFillPolygon = imlibImageFillPolygon
foreign import ccall "static Imlib2.h imlib_polygon_get_bounds" imlibPolygonGetBounds :: ImlibPolygon -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO ()
polygonGetBounds poly = do
[x1,y1,x2,y2] <- nmalloc 4
imlibPolygonGetBounds poly x1 y1 x2 y2
[rx1,ry1,rx2,ry2] <- liftM (map fromIntegral) $ mapM peek [x1,y1,x2,y2]
mapM free [x1,y1,x2,y2]
return (rx1,ry1,rx2,ry2)
foreign import ccall "static Imlib2.h imlib_polygon_contains_point" imlibPolygonContainsPoint :: ImlibPolygon -> CInt -> CInt -> IO Bool
polygonContainsPoint poly x y = imlibPolygonContainsPoint poly (fromIntegral x) (fromIntegral y)
foreign import ccall "static Imlib2.h imlib_image_draw_ellipse" imlibImageDrawEllipse :: CInt -> CInt -> CInt -> CInt -> IO ()
imageDrawEllipse xc yc a b = imlibImageDrawEllipse (fromIntegral xc) (fromIntegral yc) (fromIntegral a) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_image_fill_ellipse" imlibImageFillEllipse :: CInt -> CInt -> CInt -> CInt -> IO ()
imageFillEllipse xc yc a b = imlibImageFillEllipse (fromIntegral xc) (fromIntegral yc) (fromIntegral a) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_image_filter" imlibImageFilter :: IO ()
imageFilter :: IO ()
imageFilter = imlibImageFilter
foreign import ccall "static Imlib2.h imlib_create_filter" imlibCreateFilter :: CInt -> IO ImlibFilter
createFilter :: Int -> IO ImlibFilter
createFilter = imlibCreateFilter . fromIntegral
foreign import ccall "static Imlib2.h imlib_free_filter" imlibFreeFilter :: IO ()
freeFilter :: IO ()
freeFilter = imlibFreeFilter
foreign import ccall "static Imlib2.h imlib_filter_set" imlibFilterSet :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
filterSet xoff yoff a r g b = imlibFilterSet (fromIntegral xoff) (fromIntegral yoff) (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_filter_set_alpha" imlibFilterSetAlpha :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
filterSetAlpha xoff yoff a r g b = imlibFilterSetAlpha (fromIntegral xoff) (fromIntegral yoff) (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_filter_set_red" imlibFilterSetRed :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
filterSetRed xoff yoff a r g b = imlibFilterSetRed (fromIntegral xoff) (fromIntegral yoff) (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_filter_set_green" imlibFilterSetGreen :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
filterSetGreen xoff yoff a r g b = imlibFilterSetGreen (fromIntegral xoff) (fromIntegral yoff) (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_filter_set_blue" imlibFilterSetBlue :: CInt -> CInt -> CInt -> CInt -> CInt -> CInt -> IO ()
filterSetBlue xoff yoff a r g b = imlibFilterSetBlue (fromIntegral xoff) (fromIntegral yoff) (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_filter_constants" imlibFilterConstants :: CInt -> CInt -> CInt -> CInt -> IO ()
filterConstants :: Int -> Int -> Int -> Int -> IO ()
filterConstants a r g b = imlibFilterConstants (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)
foreign import ccall "static Imlib2.h imlib_filter_divisors" imlibFilterDivisors :: CInt -> CInt -> CInt -> CInt -> IO ()
filterDivisors :: Int -> Int -> Int -> Int -> IO ()
filterDivisors a r g b = imlibFilterDivisors (fromIntegral a) (fromIntegral r) (fromIntegral g) (fromIntegral b)