Offers SDLSurface::load
which supports more image formats than sdl2
alone: JPG, PNG, TIF, GIT, ICO and much more.
core :: union_find
union–find algorithm using an efficient disjoint-set data structureegl
, sdl
and x11
gamnit :: camera_control_linux
Mouse wheel and middle mouse button to control camera
# Services of the SDL_image 2.0 library
#
# Offers `SDLSurface::load` which supports more image formats than `sdl2::sdl2`
# alone: JPG, PNG, TIF, GIT, ICO and much more.
module image is
pkgconfig "sdl2"
ldflags "-lSDL2_image"
end
import sdl2
in "C" `{
#include <SDL2/SDL_image.h>
`}
redef class SDL
# Access to the global methods of `sdl2::image`
var img = new IMG is lazy
end
# Holds the global methods of `sdl2::image`
class IMG
# Get the `IMG` singleton
new do return once new IMG.internal
# TODO make this private and only called through `sys.sdl.img`
init internal do end
# Initialize the image library
fun initialize(flags: SDLImgInitFlags): SDLImgInitFlags `{
return IMG_Init(flags);
`}
# Finalize and clean up the image library
fun quit `{ IMG_Quit(); `}
# Get the latest image library error
fun error: CString `{ return (char*)IMG_GetError(); `}
end
redef extern class SDLSurface
# Load the image at `path` inferring its type from the file extension
new load(path: CString) `{ return IMG_Load(path); `}
end
# Flags from `sys.sdl.img.initialize`
extern class SDLImgInitFlags `{ IMG_InitFlags `}
# Get the default empty flag set
new `{ return 0; `}
# Add the JPG support to this flag set
fun jpg: SDLImgInitFlags `{ return self | IMG_INIT_JPG; `}
# Add the PNG support to this flag set
fun png: SDLImgInitFlags `{ return self | IMG_INIT_PNG; `}
# Add the TIF support to this flag set
fun tif: SDLImgInitFlags `{ return self | IMG_INIT_TIF; `}
# Add the WEBP support to this flag set
fun webp: SDLImgInitFlags `{ return self | IMG_INIT_WEBP; `}
end
lib/sdl2/image.nit:17,1--78,3