packages feed

SDL-image (empty) → 0.4.0

raw patch · 5 files changed

+338/−0 lines, 5 filesdep +SDLdep +basebuild-type:Customsetup-changed

Dependencies added: SDL, base

Files

+ Graphics/UI/SDL/Image.hs view
@@ -0,0 +1,250 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Graphics.UI.SDL.Image+-- Copyright   :  (c) David Himmelstrup 2005+-- License     :  BSD-like+--+-- Maintainer  :  lemmih@gmail.com+-- Stability   :  provisional+-- Portability :  portable+--+-----------------------------------------------------------------------------+module Graphics.UI.SDL.Image+    ( load+    , loadRW+    , ImageType(..)+    , loadTypedRW+    , loadTyped+    , isTypedRW+    , isTyped+    , isBMPRW+    , isBMP+    , isPNMRW+    , isPNM+    , isXPMRW+    , isXPM+    , isXCFRW+    , isXCF+    , isPCXRW+    , isPCX+    , isGIFRW+    , isGIF+    , isJPGRW+    , isJPG+    , isTIFRW+    , isTIF+    , isPNGRW+    , isPNG+    , isLBMRW+    , isLBM+    , module Graphics.UI.SDL.Image.Version+    ) where++import Graphics.UI.SDL.Image.Version++import Foreign+import Foreign.C++import Graphics.UI.SDL.Video+import Graphics.UI.SDL.General+import Graphics.UI.SDL.Types+import Graphics.UI.SDL.RWOps as RW++finalizeWhenNotNull :: String -> Ptr SurfaceStruct -> IO Surface+finalizeWhenNotNull errMsg image+    = if image == nullPtr+         then failWithError errMsg+         else mkFinalizedSurface image++-- SDL_Surface *IMG_Load(const char *file)+foreign import ccall unsafe "IMG_Load" imgLoad :: CString -> IO (Ptr SurfaceStruct)+load :: FilePath -> IO Surface+load filepath+    = withCString filepath $ \cPath ->+      imgLoad cPath >>= finalizeWhenNotNull "IMG_Load"++-- SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc)+foreign import ccall "IMG_Load_RW" imgLoadRW :: Ptr RWopsStruct -> Int -> IO (Ptr SurfaceStruct)+loadRW :: RWops -> Bool -> IO Surface+loadRW rw freesrc+    = withForeignPtr rw $ \rwPtr ->+      imgLoadRW rwPtr (fromBool freesrc) >>= finalizeWhenNotNull "IMG_Load_RW"++++data ImageType+    = TGA+    | BMP+    | PNM+    | XPM+    | XCF+    | PCX+    | GIF+    | JPG+    | TIF+    | LBM+    | PNG+    | Other String++imageTypeToString :: ImageType -> String+imageTypeToString TGA = "TGA"+imageTypeToString BMP = "BMP"+imageTypeToString PNM = "PNM"+imageTypeToString XPM = "XPM"+imageTypeToString XCF = "XCF"+imageTypeToString PCX = "PCX"+imageTypeToString GIF = "GIF"+imageTypeToString JPG = "JPG"+imageTypeToString TIF = "TIF"+imageTypeToString LBM = "LBM"+imageTypeToString PNG = "PNG"+imageTypeToString (Other format) = format++-- SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)+foreign import ccall "IMG_LoadTyped_RW" imgLoadTypedRW :: Ptr RWopsStruct -> Int -> CString -> IO (Ptr SurfaceStruct)+loadTypedRW :: RWops -> Bool -> ImageType -> IO Surface+loadTypedRW rw freesrc imageType+    = withForeignPtr rw $ \rwPtr ->+      withCString (imageTypeToString imageType) $ \cType ->+      imgLoadTypedRW rwPtr (fromBool freesrc) cType >>= finalizeWhenNotNull "IMG_LoadTyped_RW"++loadTyped :: FilePath -> ImageType -> IO Surface+loadTyped filepath imageType+    = RW.with filepath "rb" $ \rw ->+      loadTypedRW rw False imageType++isTypedRW :: ImageType -> RWops -> IO Bool+isTypedRW BMP = isBMPRW+isTypedRW PNM = isPNMRW+isTypedRW XPM = isXPMRW+isTypedRW XCF = isXCFRW+isTypedRW PCX = isPCXRW+isTypedRW GIF = isGIFRW+isTypedRW JPG = isJPGRW+isTypedRW TIF = isTIFRW+isTypedRW PNG = isPNGRW+isTypedRW LBM = isLBMRW+isTypedRW _other = const (return False)++isTyped :: ImageType -> FilePath -> IO Bool+isTyped imageType path+    = isTypedRW imageType =<< RW.fromFile path "rb"+++-- int IMG_isBMP(SDL_RWops *src)+foreign import ccall unsafe "IMG_isBMP" imgIsBMP :: Ptr RWopsStruct -> IO Int+isBMPRW :: RWops -> IO Bool+isBMPRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsBMP rwPtr)++isBMP :: FilePath -> IO Bool+isBMP path = RW.with path "rb" $+             isBMPRW++-- int IMG_isPNM(SDL_RWops *src)+foreign import ccall unsafe "IMG_isPNM" imgIsPNM :: Ptr RWopsStruct -> IO Int+isPNMRW :: RWops -> IO Bool+isPNMRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsPNM rwPtr)++isPNM :: FilePath -> IO Bool+isPNM path = RW.with path "rb" $+             isPNMRW++-- int IMG_isXPM(SDL_RWops *src)+foreign import ccall unsafe "IMG_isXPM" imgIsXPM :: Ptr RWopsStruct -> IO Int+isXPMRW :: RWops -> IO Bool+isXPMRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsXPM rwPtr)++isXPM :: FilePath -> IO Bool+isXPM path = RW.with path "rb" $+             isXPMRW++-- int IMG_isXCF(SDL_RWops *src)+foreign import ccall unsafe "IMG_isXCF" imgIsXCF :: Ptr RWopsStruct -> IO Int+isXCFRW :: RWops -> IO Bool+isXCFRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsXCF rwPtr)++isXCF :: FilePath -> IO Bool+isXCF path = RW.with path "rb" $+             isXCFRW+++-- int IMG_isPCX(SDL_RWops *src)+foreign import ccall unsafe "IMG_isPCX" imgIsPCX :: Ptr RWopsStruct -> IO Int+isPCXRW :: RWops -> IO Bool+isPCXRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsPCX rwPtr)++isPCX :: FilePath -> IO Bool+isPCX path = RW.with path "rb" $+             isPCXRW+++-- int IMG_isGIF(SDL_RWops *src)+foreign import ccall unsafe "IMG_isGIF" imgIsGIF :: Ptr RWopsStruct -> IO Int+isGIFRW :: RWops -> IO Bool+isGIFRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsGIF rwPtr)++isGIF :: FilePath -> IO Bool+isGIF path = RW.with path "rb" $+             isGIFRW+++-- int IMG_isJPG(SDL_RWops *src)+foreign import ccall unsafe "IMG_isJPG" imgIsJPG :: Ptr RWopsStruct -> IO Int+isJPGRW :: RWops -> IO Bool+isJPGRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsJPG rwPtr)++isJPG :: FilePath -> IO Bool+isJPG path = RW.with path "rb" $+             isJPGRW+++-- int IMG_isTIF(SDL_RWops *src)+foreign import ccall unsafe "IMG_isTIF" imgIsTIF :: Ptr RWopsStruct -> IO Int+isTIFRW :: RWops -> IO Bool+isTIFRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsTIF rwPtr)++isTIF :: FilePath -> IO Bool+isTIF path = RW.with path "rb" $+             isTIFRW+++-- int IMG_isPNG(SDL_RWops *src)+foreign import ccall unsafe "IMG_isPNG" imgIsPNG :: Ptr RWopsStruct -> IO Int+isPNGRW :: RWops -> IO Bool+isPNGRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsPNG rwPtr)++isPNG :: FilePath -> IO Bool+isPNG path = RW.with path "rb" $+             isPNGRW+++-- int IMG_isLBM(SDL_RWops *src)+foreign import ccall unsafe "IMG_isLBM" imgIsLBM :: Ptr RWopsStruct -> IO Int+isLBMRW :: RWops -> IO Bool+isLBMRW rw+    = withForeignPtr rw $ \rwPtr ->+      fmap toBool (imgIsLBM rwPtr)++isLBM :: FilePath -> IO Bool+isLBM path = RW.with path "rb" $+             isLBMRW++
+ Graphics/UI/SDL/Image/Version.hsc view
@@ -0,0 +1,32 @@+#include "SDL_image.h"+module Graphics.UI.SDL.Image.Version+    ( compiledFor+    , linkedWith+    ) where++import Data.Version (Version(Version))++import Foreign (Word8, Ptr, Storable(sizeOf, alignment, peekByteOff, peek))++data SDLVersion+    = SDLVersion Word8 Word8 Word8++instance Storable SDLVersion where+    sizeOf _ = #{size SDL_version}+    alignment _ = 1+    peek ptr = do major <- #{peek SDL_version, major} ptr+                  minor <- #{peek SDL_version, minor} ptr+                  patch <- #{peek SDL_version, patch} ptr+                  return (SDLVersion major minor patch)++compiledFor :: Version+compiledFor = Version [ #{const SDL_IMAGE_MAJOR_VERSION}+                      , #{const SDL_IMAGE_MINOR_VERSION}+                      , #{const SDL_IMAGE_PATCHLEVEL}+                      ] []++foreign import ccall unsafe "IMG_Linked_Version" sdlLinkedVersion :: IO (Ptr SDLVersion)+linkedWith :: IO Version+linkedWith = do versionPtr <- sdlLinkedVersion+                SDLVersion major minor patch <- peek versionPtr+                return (Version (map fromIntegral [major,minor,patch]) [])
+ LICENSE view
@@ -0,0 +1,35 @@+Copyright (c) 2004-2006, David Himmelstrup+All rights reserved.++Redistribution and use in source and binary forms,+with or without modification, are permitted provided+that the following conditions are met:++    * Redistributions of source code must retain+      the above copyright notice, this list of+      conditions and the following disclaimer.+    * Redistributions in binary form must reproduce+      the above copyright notice, this list of+      conditions and the following disclaimer in the+      documentation and/or other materials provided+      with the distribution.+    * Neither the name of David Himmelstrup nor the+      names of other contributors may be used to+      endorse or promote products derived from this+      software without specific prior written permission.+++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY+OF SUCH DAMAGE.
+ SDL-image.cabal view
@@ -0,0 +1,16 @@+Name: SDL-image+Version: 0.4.0+Maintainer: Lemmih (lemmih@gmail.com)+Author: Lemmih (lemmih@gmail.com)+Copyright: 2004-2005, Lemmih+License-File: LICENSE+License: BSD3+Build-Depends: base, SDL+Category: Foreign binding+Synopsis: Binding to libSDL_image+Extensions: ForeignFunctionInterface+Exposed-Modules:+  Graphics.UI.SDL.Image,+  Graphics.UI.SDL.Image.Version+Includes: SDL.h SDL_image.h+GHC-Options: -O2 -fvia-c -Wall -Werror
+ Setup.lhs view
@@ -0,0 +1,5 @@+#!/usr/bin/env runhaskell+> module Main where+> import Distribution.Simple+> main :: IO ()+> main = defaultMainWithHooks defaultUserHooks