pods::SDL::Image(3pm)
This is the user-contributed Perl doc for pods::SDL::Image(3pm), bestie β buckle up, we're loading pixels π
π NAME π
SDL::Image β bindings for the SDL_Image library, periodt.
β¨ DESCRIPTION β¨
SDL::Image lets you load many different formats of images into memory as an SDL::Surface. That's the whole vibe: image in, surface out π¦
π·οΈ CATEGORY π·οΈ
Image β that's the category, no cap.
πΌοΈ SUPPORTED FORMATS πΌοΈ
The following types are supported:
- TGA β TrueVision Targa (MUST have
.tga) - BMP β Windows Bitmap (
.bmp) - PNM β Portable Anymap (
.pnm)..pbm= Portable BitMap (mono),.pgm= Portable GreyMap (256 greys),.ppm= Portable PixMap (full color) - XPM β X11 Pixmap (
.xpm), can be#includeddirectly in code. This is NOT the same as XBM(X11 Bitmap) format, which is for monocolor images. - XCF β GIMP native (
.xcf) (XCF = eXperimental Computing Facility?). This format is always changing, and since there's no library supplied by the GIMP project to load XCF, the loader may frequently fail to load much of any image from an XCF file. It's better to load this in GIMP and convert to a better supported image format. - PCX β ZSoft IBM PC Paintbrush (
.pcx) - GIF β CompuServe Graphics Interchange Format (
.gif) - JPG β Joint Photographic Experts Group JFIF format (
.jpgor.jpeg) - TIF β Tagged Image File Format (
.tifor.tiff) - LBM β Interleaved Bitmap (
.lbmor.iff) FORM : ILBM or PBM(packed bitmap), HAM6, HAM8, and 24bit types are not supported. - PNG β Portable Network Graphics (
.png) - XV
- ICO
- CUR
π₯ LOADING METHODS π₯
load π
my $surface = SDL::Image::load( $file );
$file β image file name to load a surface from.
Loads a file for use as an image in a new SDL::Surface. This actually calls SDL::Image::load_typed_rw, with the file extension used as the type string. It can load all supported image files, including TGA as long as the filename ends with .tga. Bestie, call this outside of event loops and keep the loaded images around until you're really done with them β disk speed and image conversion to a surface is not that speedy π
Note: if the image format loader requires initialization, it will attempt to do that the first time it is needed if you have not already called SDL::Image::init to load support for your image format.
Note: if the image format supports a transparent pixel,SDL::Imagewill set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:SDL::Video::set_color_key
my $image = SDL::Image::load( $some_png_file );
SDL::Video::set_color_key($image, SDL_RLEACCEL, $image->format->colorkey);
Return: an image as a SDL::Surface. NULL is returned on errors, such as no support built for the image, or a file reading error. Use SDL::get_error to get cause of error.
load_typed_rw π
SDL::Image::load_typed_rw($src, $freesrc, $type);
srcβ the sourceSDL::RWopsas a pointer. The image is loaded from this.freesrcβ a non-zero value means it will automatically close/free the$srcfor you. Since SDL Perl cannot handle the memory inside this function you would most likely want1here.typeβ a string that indicates which format type to interpret the image as.
Here is a list of the currently recognized strings (case is not important):
"BMP"
"CUR"
"GIF"
"ICO"
"JPG"
"LBM"
"PCX"
"PNG"
"PNM"
"TGA"
"TIF"
"XCF"
"XPM"
"XV"
Loads $src for use as a surface. This can load all supported image formats. This method does not guarantee that the format specified by type is the format of the loaded image, except in the case when TGA format is specified (or any other non-magicable format in the future). Using SDL_RWops is not covered here, but they enable you to load from almost any source π
Note: if the image format loader requires initialization, it will attempt to do that the first time it is needed if you have not already called SDL::Image::init to load support for your image format.
Note: if the image format supports a transparent pixel,SDL::Imagewill set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling:SDL::Video::set_color_key
Transparency:
use SDL;
use SDL::RWOps;
use SDL::Image;
my $file2 = SDL::RWOps->new_file("test/data/menu.png", "rb");
my $image = SDL::Image::load_typed_rw($file2, 1, "PNG");
SDL::Video::set_color_key($image, SDL_RLEACCEL, $image->format->colorkey);
Return: the image as a new SDL::Surface. NULL is returned on errors.
is_[TYPE] π
Test for valid, supported image files:
is_ICOis_CURis_PNGis_BMPis_GIFis_JPGis_LBMis_PCXis_PNMis_TIFis_XCFis_XPMis_XV
These functions take a SDL::RWOps as a parameter.
Return: 1 if the image is a valid [TYPE] and the [TYPE] format support is compiled into SDL_image. 0 is returned otherwise.
Example:
use SDL::RWOps;
use SDL::Image;
my $file = SDL::RWOps->new_file("file", "rb");
print "Image is BMP" if ( SDL::is_BMP );
load_[TYPE]_rw π§
Specific loader for known formats:
load_ICO_rwload_CUR_rwload_PNG_rwload_BMP_rwload_GIF_rwload_JPG_rwload_LBM_rwload_PCX_rwload_PNM_rwload_TIF_rwload_XCF_rwload_XPM_rwload_XV_rw
These functions take a SDL::RWop as a parameter.
Return: the image as a new SDL::Surface. NULL is returned on errors, like if the [TYPE] is not supported, or a read error.
Example:
use SDL;
use SDL::RWOps;
use SDL::Image;
my $file = SDL::RWOps->new_file("file.png", "rb");
my $image = SDL::Image::load_PNG_rw($file);
die SDL::get_error if (!$image);
read_XPM_from_array π
my $picture = SDL::Image::read_XPM_from_array(\@XPM, $width);
This functions takes the reference of an array in the valid @XPM format. Also the $width of the XPM image.
Return: the image as a new SDL::Surface. NULL is returned on errors, like if XPM is not supported, or a read error.
Example:
my @XPM= (
'30 30 9 1',
' c #FFFFFF',
'. c #EFEFEF',
'+ c #CFCFCF',
'@ c #9F9F9F',
'# c #808080',
'$ c #505050',
'% c #202020',
'& c #000000',
'* c #303030',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' .+@##@+. ',
' .@$%&&%$@. ',
' .@*&&&&&&*@. ',
' +$&&&&&&&&$+ ',
' @%&&&&&&&&%@ ',
' #&&&&&&&&&&# ',
' #&&&&&&&&&&# ',
' @%&&&&&&&&%@ ',
' +$&&&&&&&&$+ ',
' .@*&&&&&&*@. ',
' .@$%&&%$@. ',
' .+@##@+. ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',);
my $picture = SDL::Image::read_XPM_from_array(\@XPM, 30);
π οΈ MISC METHODS π οΈ
linked_version π
Provides the version of linked sdl_image library.
Return: returns a SDL::Version object.
Example:
my $version = SDL::Image::linked_version();
print $version->major.' '.$version->minor.' '.$version->patch;
init β
For version SDL_image 1.2.10 and up.
Flags: bitwise OR'd set of image formats to support by loading a library now. The values you may OR together to pass in are:
IMG_INIT_JPGIMG_INIT_PNGIMG_INIT_TIF
Initialize by loading support as indicated by the flags, or at least return success if support is already loaded. You may call this multiple times, which will actually require you to call IMG_Quit just once to clean up. You may call this function with a 0 to retrieve whether support was built-in or not loaded yet.
Note: to load JPG, PNG, and/or TIF images you can callIMG_Initwith the rightIMG_INIT_*flags OR'd together before your program gets busy, to prevent a later hiccup while it loads the library, and to check that you do have the support that you need before you try and use it.
Note: no initialization is needed nor performed when using theSDL::Image::is_JPG,SDL::Image::is_PNG, andSDL::Image::is_TIFfunctions.
Note: this function does not always set the error string, so do not depend on SDL::Image::get_error being meaningful all the time.
Return: a bitmask of all the currently inited image loaders.
Example:
use SDL::Image;
my $flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_JPG;
my $inited = SDL::Image::init($flags);
quit π¦
For version SDL_image 1.2.10 and up.
This function cleans up all dynamically loaded library handles, freeing memory. If support is required again it will be initialized again, either by SDL::Image::init or loading an image with dynamic support required. You may call this function when SDL::Image::load functions are no longer needed for the JPG, PNG, and TIF image formats. You only need to call this function once, no matter how many times SDL::Image::init was called.
Example:
use SDL::Image;
SDL::Image::init(IMG_INIT_JPG); #loads JPG support
SDL::Image::load("file.png"); #loads PNG support
SDL::Image::quit(); #unloads everything
set_error π
Same as SDL::set_error.
get_error π
Same as SDL::get_error.
π SEE ALSO π
SDLSDL::SurfaceSDL::VideoSDL::RWOps
π AUTHORS π
See "AUTHORS" in SDL.
And that's the whole manual, bestie: source/version is perl v5.42.0, dated 2024-05-01, and this iconic little page is pods::SDL::Image(3pm) π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms