![]() |
CRM64Pro GDK v0.13.0
A free cross-platform game development kit built on top of SDL 3.0
|
Image Manager and Image objects for handling surfaces and textures [v25.12.0].
The Image module provides unified management for images and textures used by all graphic modules in the GDK. It supports BMP and PNG external files as well as SDL_Surface sources. Images can be saved to and loaded from CDC archives (using CDC v1.x specification).
| Source surface | Standard SDL_Surface where the imported BMP, PNG or SDL_Surface is stored |
|---|---|
| Textures | One texture per screen. Created "offline" via optimize() or "online" automatically on first render. Always created with SDL_TEXTUREACCESS_TARGET flag |
| Attributes | Color key (transparency), alpha value (surface transparency), color modulation and blending mode (SDL_BlendMode) |
The following filters can be applied to images (affects source surface and all textures):
| Noise | Adds random noise effect |
|---|---|
| Blur | Applies blur/smoothing effect |
| Negative | Inverts color values |
| Grey | Converts to greyscale |
| Black/White | Converts to two-tone black and white |
| Wiggle | Applies wave distortion effect |
| Pixelate | Reduces resolution for pixelated effect |
| Uninitialized | Created with ImageMgr::create() but lacks source surface (set via Image::assignSurface()). Not usable |
|---|---|
| Stand-alone | Fully usable image with no children. No restrictions |
| Parent | Stand-alone image with one or more children. Restrictions: ColorKey cannot be modified, cannot be closed while children are live, name cannot be changed |
| Child | Uses parent's source surface, textures and name. Restrictions: ColorKey cannot be modified, save() calls parent's method, name cannot be changed |
Images can be rendered to any valid screen or another image:
| Image::render() | Plain rendering with optional stretch or shrink |
|---|---|
| Image::renderEx() | Extended rendering with rotation around a given point and vertical/horizontal flip effects |
This is an advanced "cloning" manager: when loading an image from a CDC file that is already loaded or created (using the name as the key), it will create a new "clone" (child) for the image. Child images share the source surface and textures with their parent for memory efficiency.
Classes | |
| class | CRM64Pro::Image |
| Image Object class. More... | |
| class | CRM64Pro::ImageMgr |
| Image Manager class. More... | |
Enumerations | |
| enum | CRM64Pro::eImageFilter { CRM64Pro::IF_NOISE = 1 , CRM64Pro::IF_BLUR = 2 , CRM64Pro::IF_NEGATIVE = 3 , CRM64Pro::IF_GREY = 4 , CRM64Pro::IF_BW = 5 , CRM64Pro::IF_WIGGLE = 6 , CRM64Pro::IF_PIXELATE = 7 } |
| Image filters. More... | |
Functions | |
| Sint32 | CRM64Pro::Image::info (Sint32 iMode=0) |
| Request Image object information. | |
| Sint32 | CRM64Pro::Image::getName (string &sName) |
| Get the name. | |
| Uint32 | CRM64Pro::Image::getID () |
| Get the ID. | |
| Sint32 | CRM64Pro::Image::assignSurface (SDL_Surface *pSurf, Sint32 iOwnership=0) |
| Assign a SDL_Surface to this image. | |
| Sint32 | CRM64Pro::Image::setOwner (Sint32 iOwner) |
| Set the owner of this image. | |
| Sint32 | CRM64Pro::Image::getOwner () |
| Get the owner of this image. | |
| Sint32 | CRM64Pro::Image::optimize (Sint32 idScreen=0) |
| Optimize the image for rendering on screens in the most efficient way. | |
| Sint32 | CRM64Pro::Image::rebuild () |
| Rebuild the current textures. | |
| Sint32 | CRM64Pro::Image::render (Sint32 idRes=0, SDL_FRect *rSrc=nullptr, SDL_FRect *rDst=nullptr) |
| Render the image. | |
| Sint32 | CRM64Pro::Image::renderEx (const double dAngle, const SDL_FPoint *poCenter=nullptr, const SDL_FlipMode rf=SDL_FLIP_NONE, Sint32 idRes=0, SDL_FRect *rSrc=nullptr, SDL_FRect *rDst=nullptr) |
| Render the image with extended attributes: can rotate and flip the image. | |
| Sint32 | CRM64Pro::Image::applyFilter (eImageFilter eFilter, Sint32 iValue=0) |
| Apply a filter to this image. | |
| Sint32 | CRM64Pro::Image::setBlendMode (SDL_BlendMode bmValue) |
| Set blend mode used for rendering this image. | |
| SDL_BlendMode | CRM64Pro::Image::getBlendMode () |
| Get blend mode used for rendering this image. | |
| Sint32 | CRM64Pro::Image::setAlphaMod (Sint32 iAlpha) |
| Set alpha modulation used for rendering this image. | |
| Sint32 | CRM64Pro::Image::getAlphaMod () |
| Get alpha modulation used for rendering this image. | |
| Sint32 | CRM64Pro::Image::setColorMod (Uint8 iR, Uint8 iG, Uint8 iB) |
| Set color modulation used for rendering this image. | |
| Sint32 | CRM64Pro::Image::getColorMod (Uint8 &iR, Uint8 &iG, Uint8 &iB) |
| Get color modulation used for rendering this image. | |
| Sint32 | CRM64Pro::Image::setColorKey (Sint16 iR=-1, Sint16 iG=-1, Sint16 iB=-1) |
| Set colorkey used for rendering this image. | |
| Sint32 | CRM64Pro::Image::getColorKey (Sint16 &iR, Sint16 &iG, Sint16 &iB) |
| Get colorkey used for rendering this image. | |
| SDL_Surface * | CRM64Pro::Image::getSurface () |
| Get the source surface of this image. | |
| Sint32 | CRM64Pro::Image::findTex (Sint32 &iIndex, SDL_Texture *&pTex, Sint32 &idScreen) |
| Get the texture for each screen of this image. | |
| Sint32 | CRM64Pro::Image::saveToBMP (const string &sFile="") |
| Export the image to a BMP file. | |
| Sint32 | CRM64Pro::Image::saveToPNG (const string &sFile="") |
| Save the image to an external PNG file. | |
| Sint32 | CRM64Pro::Image::save (const string &sFileCDC) |
| Save the image to a CDC file. | |
| Sint32 | CRM64Pro::Image::save (Sint32 idCDC) |
| Save the image to a CDC file. | |
| Sint32 | CRM64Pro::ImageMgr::info (Sint32 iMode=0) |
| Request Image Manager information. | |
| Sint32 | CRM64Pro::ImageMgr::create (const string &sName, Uint32 iVersion=10) |
| Creates a new image. | |
| Sint32 | CRM64Pro::ImageMgr::close (Sint32 idImg) |
| Close and destroy an image. | |
| Sint32 | CRM64Pro::ImageMgr::getNum () const |
| Get number of loaded objects. | |
| Sint32 | CRM64Pro::ImageMgr::setName (Sint32 idImg, const string &sName) |
| Change the object name. | |
| Sint32 | CRM64Pro::ImageMgr::closeEx (Sint32 idImg, Uint32 iOwner) |
| Close and destroy an image. | |
| Image * | CRM64Pro::ImageMgr::get (Sint32 idImg) |
| Get a pointer to the image using its handler. | |
| Sint32 | CRM64Pro::ImageMgr::duplicate (Sint32 idImg, const string &sName) |
| Duplicate an image creating a new, identical and independent one. | |
| Sint32 | CRM64Pro::ImageMgr::child (Sint32 idImg) |
| Create a child image dependent on the provided one (the parent). | |
| Sint32 | CRM64Pro::ImageMgr::isBMP (const string &sFile) |
| Check if the file is a BMP. | |
| Sint32 | CRM64Pro::ImageMgr::isPNG (const string &sFile) |
| Check if the file is a PNG. | |
| Sint32 | CRM64Pro::ImageMgr::loadFromFile (const string &sFile, const string &sName="") |
| Load an image (BMP or PNG formats). | |
| Sint32 | CRM64Pro::ImageMgr::load (const string &sFileCDC, const string &sName) |
| Load an image stored in a CDC file. | |
| Sint32 | CRM64Pro::ImageMgr::load (const Sint32 idCDC, const string &sName) |
| Load an image stored in a CDC file. | |
| Sint32 | CRM64Pro::ImageMgr::load (void *pBuffer, Sint32 iSize, const string &sName) |
| Load an image (BMP or PNG formats) stored on a memory buffer. | |
| Sint32 | CRM64Pro::ImageMgr::remove (Sint32 idCDC, const string &sName) |
| Remove an image stored in a CDC file. | |
| Sint32 | CRM64Pro::ImageMgr::exist (Sint32 idCDC, const string &sName) |
| Check if an image is stored in a CDC file. | |
Image filters.
| Enumerator | |
|---|---|
| IF_NOISE | 'eFilter' parameter in Image::applyFilter. Apply a noise effect with a specific iValue (from 0 to 100). |
| IF_BLUR | 'eFilter' parameter in Image::applyFilter. Apply a blur effect with a specific iValue (from 0 to 100). |
| IF_NEGATIVE | 'eFilter' parameter in Image::applyFilter. Apply a negative effect. |
| IF_GREY | 'eFilter' parameter in Image::applyFilter. Apply a grey effect. |
| IF_BW | 'eFilter' parameter in Image::applyFilter. Apply a black/white effect. |
| IF_WIGGLE | 'eFilter' parameter in Image::applyFilter. Apply a wiggle effect that can be animated using variable iValue. |
| IF_PIXELATE | 'eFilter' parameter in Image::applyFilter. Apply a pixelate effect that can be animated using variable iValue. |
| Sint32 CRM64Pro::Image::info | ( | Sint32 | iMode = 0 | ) |
Request Image object information.
Writes information to the default log.
| iMode | unused for the time being. |
| Sint32 CRM64Pro::Image::getName | ( | string & | sName | ) |
Get the name.
| sName | a string pointer to be filled in with the image name. |
| Uint32 CRM64Pro::Image::getID | ( | ) |
Get the ID.
| Sint32 CRM64Pro::Image::assignSurface | ( | SDL_Surface * | pSurf, |
| Sint32 | iOwnership = 0 ) |
Assign a SDL_Surface to this image.
Used for loading the source surface to images created with ImageMgr::create().
| pSurf | SDL_Surface pointer. |
| iOwnership | 0 (default) creates an internal copy (original can be freed), any other value takes ownership (do not free if call succeeds). |
| Sint32 CRM64Pro::Image::setOwner | ( | Sint32 | iOwner | ) |
Set the owner of this image.
| iOwner | Owner of the image. |
| Sint32 CRM64Pro::Image::getOwner | ( | ) |
Get the owner of this image.
| Sint32 CRM64Pro::Image::optimize | ( | Sint32 | idScreen = 0 | ) |
Optimize the image for rendering on screens in the most efficient way.
| idScreen | a valid screen handle used to convert the image to the same format as the screen. The screen must be initialized. |
| Sint32 CRM64Pro::Image::rebuild | ( | ) |
Rebuild the current textures.
This method will rebuild any existing texture and it is used when the source surface is modified and the textures have to be "in-sync".
| Sint32 CRM64Pro::Image::render | ( | Sint32 | idRes = 0, |
| SDL_FRect * | rSrc = nullptr, | ||
| SDL_FRect * | rDst = nullptr ) |
Render the image.
| idRes | a valid screen or image handle. Default uses the default screen. |
| rSrc | the source SDL_FRect structure or nullptr for the entire image. Default nullptr. |
| rDst | the destination SDL_FRect structure or nullptr to match rSrc. Can stretch or shrink the image. Default nullptr. |
| Sint32 CRM64Pro::Image::renderEx | ( | const double | dAngle, |
| const SDL_FPoint * | poCenter = nullptr, | ||
| const SDL_FlipMode | rf = SDL_FLIP_NONE, | ||
| Sint32 | idRes = 0, | ||
| SDL_FRect * | rSrc = nullptr, | ||
| SDL_FRect * | rDst = nullptr ) |
Render the image with extended attributes: can rotate and flip the image.
| dAngle | angle in degrees for the rotation. |
| poCenter | SDL_FPoint pointer indicating the rotation center. Default nullptr rotates around rDst.w/2 and rDst.h/2. |
| rf | "SDL_FlipMode" value for flipping actions. |
| idRes | a valid screen or image handle. Default uses the default screen. |
| rSrc | the source SDL_FRect structure or nullptr for the entire image. Default nullptr. |
| rDst | the destination SDL_FRect structure or nullptr to match rSrc. Can stretch or shrink. Default nullptr. |
| Sint32 CRM64Pro::Image::applyFilter | ( | eImageFilter | eFilter, |
| Sint32 | iValue = 0 ) |
Apply a filter to this image.
Works on stand-alone and parent images; children cannot apply a filter. As the image is shared between parent and children, applying a filter to a parent affects all children.
| eFilter | Check ::eImageFilter enum for details. |
| iValue | adjustable value for some filters. |
| Sint32 CRM64Pro::Image::setBlendMode | ( | SDL_BlendMode | bmValue | ) |
Set blend mode used for rendering this image.
| bmValue | SDL_BlendMode. |
| SDL_BlendMode CRM64Pro::Image::getBlendMode | ( | ) |
Get blend mode used for rendering this image.
| Sint32 CRM64Pro::Image::setAlphaMod | ( | Sint32 | iAlpha | ) |
Set alpha modulation used for rendering this image.
| iAlpha | It ranges from 255 (opaque) to 0 (fully transparent). |
| Sint32 CRM64Pro::Image::getAlphaMod | ( | ) |
Get alpha modulation used for rendering this image.
| Sint32 CRM64Pro::Image::setColorMod | ( | Uint8 | iR, |
| Uint8 | iG, | ||
| Uint8 | iB ) |
Set color modulation used for rendering this image.
By default, all components are set to 255.
| iR | red color component value from 0 to 255. |
| iG | green color component value from 0 to 255. |
| iB | blue color component value from 0 to 255. |
| Sint32 CRM64Pro::Image::getColorMod | ( | Uint8 & | iR, |
| Uint8 & | iG, | ||
| Uint8 & | iB ) |
Get color modulation used for rendering this image.
| iR | red color component value from 0 to 255. |
| iG | green color component value from 0 to 255. |
| iB | blue color component value from 0 to 255. |
| Sint32 CRM64Pro::Image::setColorKey | ( | Sint16 | iR = -1, |
| Sint16 | iG = -1, | ||
| Sint16 | iB = -1 ) |
Set colorkey used for rendering this image.
Colorkey can only be modified on stand-alone images. Internally emulated using blending modes; if already set, it is not modified, otherwise SDL_BLENDMODE_BLEND is set.
| iR | red color component (0-255). Negative value disables colorkey. |
| iG | green color component (0-255). Negative value disables colorkey. |
| iB | blue color component (0-255). Negative value disables colorkey. |
| Sint32 CRM64Pro::Image::getColorKey | ( | Sint16 & | iR, |
| Sint16 & | iG, | ||
| Sint16 & | iB ) |
Get colorkey used for rendering this image.
| iR | red color component (0-255). Negative means colorkey is disabled. |
| iG | green color component (0-255). Negative means colorkey is disabled. |
| iB | blue color component (0-255). Negative means colorkey is disabled. |
| SDL_Surface * CRM64Pro::Image::getSurface | ( | ) |
Get the source surface of this image.
| Sint32 CRM64Pro::Image::findTex | ( | Sint32 & | iIndex, |
| SDL_Texture *& | pTex, | ||
| Sint32 & | idScreen ) |
Get the texture for each screen of this image.
| iIndex | pointer to an integer containing 0 for find the first texture or the iIndex value of previous calls to this method. |
| pTex | pointer to a SDL_Texture, nullptr when no texture is present. |
| idScreen | pointer to the screen handle for which the texture is, when no texture is present it is set to -1. |
| Sint32 CRM64Pro::Image::saveToBMP | ( | const string & | sFile = "" | ) |
Export the image to a BMP file.
If the BMP file already exists, it will be overwritten.
| sFile | string containing [directory]+filename+[extension]. Ideally should have .bmp extension. Directory separators '\' and '/' are supported. |
| Sint32 CRM64Pro::Image::saveToPNG | ( | const string & | sFile = "" | ) |
Save the image to an external PNG file.
If the PNG file already exists, it will be overwritten.
| sFile | string containing [directory]+filename+[extension]. Ideally should have .png extension. Directory separators '\' and '/' are supported. |
| Sint32 CRM64Pro::Image::save | ( | const string & | sFileCDC | ) |
Save the image to a CDC file.
| sFileCDC | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| Sint32 CRM64Pro::Image::save | ( | Sint32 | idCDC | ) |
Save the image to a CDC file.
| idCDC | CDC id. |
| Sint32 CRM64Pro::ImageMgr::info | ( | Sint32 | iMode = 0 | ) |
| Sint32 CRM64Pro::ImageMgr::create | ( | const string & | sName, |
| Uint32 | iVersion = 10 ) |
Creates a new image.
Creates an empty image (no source surface). Use Image::assignSurface() to assign the source surface.
| sName | The image name (e.g. 'myImage'). Must be unique, max 64 characters (truncated if longer). Cannot start with '#'. |
| iVersion | Image version. 10 means v1.0 (only version supported). Default v1.0. |
| Sint32 CRM64Pro::ImageMgr::close | ( | Sint32 | idImg | ) |
Close and destroy an image.
This method can only close images belonging to the default owner (ImageMgr).
| idImg | 0 for closing all images, or specific Image id. Stand-alone and child images can be closed; parent images cannot while they have children. |
| Sint32 CRM64Pro::ImageMgr::getNum | ( | ) | const |
Get number of loaded objects.
| Sint32 CRM64Pro::ImageMgr::setName | ( | Sint32 | idImg, |
| const string & | sName ) |
Change the object name.
| idImg | Image id. |
| sName | The image name (e.g. 'myImage'). Must be unique, max 64 characters (truncated if longer). Cannot start with '#'. |
| Sint32 CRM64Pro::ImageMgr::closeEx | ( | Sint32 | idImg, |
| Uint32 | iOwner ) |
Close and destroy an image.
Can close images belonging to any owner, but owner must be provided as a security check.
| idImg | 0 for closing all images, or specific Image id. Stand-alone and child images can be closed; parent images cannot while they have children. |
| iOwner | Owner of the image. |
| Image * CRM64Pro::ImageMgr::get | ( | Sint32 | idImg | ) |
Get a pointer to the image using its handler.
| idImg | Image id. |
| Sint32 CRM64Pro::ImageMgr::duplicate | ( | Sint32 | idImg, |
| const string & | sName ) |
Duplicate an image creating a new, identical and independent one.
| idImg | Image id to be duplicated. |
| sName | The image name (e.g. 'myImage'). Must be unique, max 64 characters (truncated if longer). Cannot start with '#'. |
| Sint32 CRM64Pro::ImageMgr::child | ( | Sint32 | idImg | ) |
Create a child image dependent on the provided one (the parent).
A child image uses the parent's source surface and textures but can have different attributes. Useful for saving memory.
| idImg | parent Image id. If the provided image is a child, the request is redirected to its parent. |
| Sint32 CRM64Pro::ImageMgr::isBMP | ( | const string & | sFile | ) |
Check if the file is a BMP.
| sFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| Sint32 CRM64Pro::ImageMgr::isPNG | ( | const string & | sFile | ) |
Check if the file is a PNG.
| sFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| Sint32 CRM64Pro::ImageMgr::loadFromFile | ( | const string & | sFile, |
| const string & | sName = "" ) |
Load an image (BMP or PNG formats).
| sFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| sName | the image object name. If empty (default), uses filename without extension. Must be unique, max 64 characters. |
| Sint32 CRM64Pro::ImageMgr::load | ( | const string & | sFileCDC, |
| const string & | sName ) |
Load an image stored in a CDC file.
| sFileCDC | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
| sName | string with the image name (max 64 characters). If already exists, creates a child instead. |
| Sint32 CRM64Pro::ImageMgr::load | ( | const Sint32 | idCDC, |
| const string & | sName ) |
Load an image stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the image name (max 64 characters). If already exists, creates a child instead. |
| Sint32 CRM64Pro::ImageMgr::load | ( | void * | pBuffer, |
| Sint32 | iSize, | ||
| const string & | sName ) |
Load an image (BMP or PNG formats) stored on a memory buffer.
| pBuffer | buffer pointer containing the BMP or PNG raw data. |
| iSize | size in bytes of the buffer. |
| sName | the image object name. Must be unique, max 64 characters. |
| Sint32 CRM64Pro::ImageMgr::remove | ( | Sint32 | idCDC, |
| const string & | sName ) |
Remove an image stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the image name (maximum size of 64 characters). |
| Sint32 CRM64Pro::ImageMgr::exist | ( | Sint32 | idCDC, |
| const string & | sName ) |
Check if an image is stored in a CDC file.
| idCDC | CDC id. |
| sName | string with the image name (maximum size of 64 characters). |