1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Services of the SDL_image 2.0 library
19 # Offers `SDLSurface::load` which supports more image formats than `sdl2::sdl2`
20 # alone: JPG, PNG, TIF, GIT, ICO and much more.
23 ldflags
"-lSDL2_image"
29 #include <SDL2/SDL_image.h>
33 # Access to the global methods of `sdl2::image`
34 var img
= new IMG is lazy
37 # Holds the global methods of `sdl2::image`
39 # Get the `IMG` singleton
40 new do return once
new IMG.internal
42 # TODO make this private and only called through `sys.sdl.img`
45 # Initialize the image library
46 fun initialize
(flags
: SDLImgInitFlags): SDLImgInitFlags `{
47 return IMG_Init(flags);
50 # Finalize and clean up the image library
51 fun quit
`{ IMG_Quit(); `}
53 # Get the latest image library error
54 fun error: NativeString `{ return (char*)IMG_GetError(); `}
57 redef extern class SDLSurface
58 # Load the image at `path` inferring its type from the file extension
59 new load
(path
: NativeString) `{ return IMG_Load(path); `}
62 # Flags from `sys
.sdl
.img
.initialize
`
63 extern class SDLImgInitFlags `{ int `}
64 # Get the default empty flag set
67 # Add the JPG support to this flag set
68 fun jpg: SDLImgInitFlags `{ return recv | IMG_INIT_JPG; `}
70 # Add the PNG support to this flag set
71 fun png
: SDLImgInitFlags `{ return recv | IMG_INIT_PNG; `}
73 # Add the TIF support to this flag set
74 fun tif: SDLImgInitFlags `{ return recv | IMG_INIT_TIF; `}
76 # Add the WEBP support to this flag set
77 fun webp
: SDLImgInitFlags `{ return recv | IMG_INIT_WEBP; `}