Services of the SDL_image 2.0 library

Offers SDLSurface::load which supports more image formats than sdl2 alone: JPG, PNG, TIF, GIT, ICO and much more.

Introduced classes

class IMG

sdl2 :: IMG

Holds the global methods of sdl2::image
extern class SDLImgInitFlags

sdl2 :: SDLImgInitFlags

Flags from sys.sdl.img.initialize

Redefined classes

redef class SDL

sdl2 :: image $ SDL

Holds the global methods of sdl2
redef extern class SDLSurface

sdl2 :: image $ SDLSurface

A bitmap surface

All class definitions

class IMG

sdl2 $ IMG

Holds the global methods of sdl2::image
redef class SDL

sdl2 :: image $ SDL

Holds the global methods of sdl2
extern class SDLImgInitFlags

sdl2 $ SDLImgInitFlags

Flags from sys.sdl.img.initialize
redef extern class SDLSurface

sdl2 :: image $ SDLSurface

A bitmap surface
package_diagram sdl2::image image sdl2 sdl2 sdl2::image->sdl2 core core sdl2->core ...core ... ...core->core gamnit::display_linux display_linux gamnit::display_linux->sdl2::image sdl2::all all sdl2::all->sdl2::image gamnit::gamnit_linux gamnit_linux gamnit::gamnit_linux->gamnit::display_linux gamnit::gamnit_linux... ... gamnit::gamnit_linux...->gamnit::gamnit_linux sdl2::minimal minimal sdl2::minimal->sdl2::all sdl2::minimal... ... sdl2::minimal...->sdl2::minimal

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module events

sdl2 :: events

SDL 2 events and related services
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sdl2_base

sdl2 :: sdl2_base

Basic SDL 2 features
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module syswm

sdl2 :: syswm

Window manager related SDL 2 services
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module sdl2

sdl2 :: sdl2

Simple DirectMedia Layer (SDL) 2.0 services for easy window creation and 2D drawing

Children

module all

sdl2 :: all

Unites the main sdl2 module and its sister library sdl2::image
module display_linux

gamnit :: display_linux

Gamnit display implementation for GNU/Linux using egl, sdl and x11

Descendants

module a_star-m

a_star-m

module camera_control_linux

gamnit :: camera_control_linux

Mouse wheel and middle mouse button to control camera
module gamnit_linux

gamnit :: gamnit_linux

Support services for Gamnit on GNU/Linux
module minimal

sdl2 :: minimal

An example to test and demonstrate the sdl2 lib with image and events
# 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