![]() version :: ( Integral a, MonadIO m ) => m ( a, a, a ) version = liftIO $ do SDL. isWEBP - | Gets the major, minor, patch versions of the linked library. formatPredicate :: MonadIO m => Format -> Ptr RWops -> m CInt formatPredicate = \ case CUR -> SDL. data Format = CUR | ICO | BMP | PNM | XPM | XCF | PCX | GIF | LBM | XV | JPG | PNG | TIF | WEBP deriving ( Eq, Enum, Ord, Bounded, Generic, Read, Show ) - Given an image format, return its raw predicate function. format :: ByteString -> Maybe Format format bytes = fst find snd attempts where attempts = map ( \ f -> ( f, formattedAs f bytes ) ) - | Each of the supported image formats. If you're trying to test for a specific format, use a specific 'formattedAs' - directly instead. unsafeUseAsCStringLen bytes $ \ ( cstr, len ) -> do rw >= \ case 1 -> return True 0 -> return False e -> do let err = "Expected 1 or 0, got " ` mappend ` pack ( show e ) ` mappend ` "." let fun = "IMG_is" ` mappend ` pack ( show f ) throwIO $ SDLCallFailed "" fun err - | Tries to detect the image format by attempting 'formattedAs' with each - possible 'Format'. formattedAs :: Format -> ByteString -> Bool formattedAs f bytes = unsafePerformIO. createTextureFromSurface r - | Tests whether a 'ByteString' contains an image of a given format. unsafeUseAsCStringLen bytes $ \ ( cstr, len ) -> do rw Renderer -> ByteString -> m Texture decodeTextureTGA r bytes = liftIO. decodeTGA :: MonadIO m => ByteString -> m Surface decodeTGA bytes = liftIO. createTextureFromSurface r - | Reads a image from a 'ByteString'. liftIO $ do rw Renderer -> FilePath -> m Texture loadTextureTGA r path = liftIO. loadTGA :: MonadIO m => FilePath -> m Surface loadTGA path = fmap unmanaged. createTextureFromSurface r - | If your files aren't in a filename ending with you can - load them using this function. unsafeUseAsCStringLen bytes $ \ ( cstr, len ) -> do rw Renderer -> ByteString -> m Texture decodeTexture r bytes = liftIO. decode :: MonadIO m => ByteString -> m Surface decode bytes = liftIO. If you need to - decode a 'ByteString', use 'decodeTGA' instead. This will work for all supported image types, _except TGA_. createTextureFromSurface r - | Reads an image from a 'ByteString'. loadTexture :: MonadIO m => Renderer -> FilePath -> m Texture loadTexture r path = liftIO. For files not ending in ".tga", use 'loadTextureTGA' instead. load - | Same as 'load', but returning a 'Texture' instead. load :: MonadIO m => FilePath -> m Surface load path = fmap unmanaged. Surface -> Surface unmanaged p = Surface p Nothing - | Loads any given file of a supported image type as a 'Surface', including - if the filename ends with - If you have files that don't have names ending with use - 'loadTGA' instead. IMG_INIT_WEBP - | A helper for unmanaged 'Surface's, since it is not exposed by SDL itself. deriving ( Eq, Enum, Ord, Bounded, Generic, Read, Show ) flagToCInt :: InitFlag -> CInt flagToCInt = \ case InitJPG -> SDL. data InitFlag = InitJPG - ^ Load support for reading files. Each designates early loading of support for a particular image format. init cint ) - | Flags intended to be fed to 'initialize'. flagToCInt b ) 0 flags throwIf_ ( \ result -> cint /= 0 & cint /= result ) "" "IMG_Init" ( SDL. initialize :: ( Foldable f, MonadIO m ) => f InitFlag -> m ( ) initialize flags = do let cint = foldl ( \ a b -> a. You may call this function multiple times. Otherwise, image support will be - loaded dynamically when you attempt to load a or - file. You should call this function if you prefer to load image support yourself, - at a time when your process isn't as busy. Image - | Initializes by loading support for the chosen image formats. ![]() Unsafe ( unsafePerformIO ) import qualified SDL import qualified SDL. Filesystem ( rwFromFile, rwFromConstMem ) import SDL. ExceptionHelper ( throwIfNull, throwIf_ ) import SDL. Generics ( Generic ) import SDL ( Renderer, Texture, Surface (. Unsafe ( unsafeUseAsCStringLen ) import Data. Exception ( bracket, throwIO ) import Control. ), version, quit ) where import Control. , loadTGA, decodeTGA, loadTextureTGA, decodeTextureTGA - * Format detection, formattedAs, format, Format (. Only use these functions if you're certain the inputs are - otherwise they'll throw an exception. load, decode, loadTexture, decodeTexture - * Loading TGA images - | #tga# Since images don't contain a specific unique signature, the - following functions might succeed even when given files not formatted as - images. If you have data, you might wish to use the functions from - the instead. Image ( - * Loading images - | Use the following functions to read any - and formatted - data. Throwing an 'SDLException' in case it encounters an error. You can safely assume that any monadic function listed here is capable of Types of images as 'Surface's, as well as detect image formats.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |