CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
|
v2.10 (7 Jul 2023)
The Image module includes the Image Manager and Image for handling all the operations with surfaces and textures.
The Image Manager is used by all the graphic modules so, it unified images and textures handling..
It supports BMP and PNG external files although can also use a SDL_Surface.
Once the image is created, it can be saved to a CDC file (as of now, we are using CDC v1.x specification) which can be also loaded.
The image has the following elements:
Source surface: | Standard SDL_Surface where the imported BMP,PNG or SDL_Surface is stored. |
Textures: | One texture for each screen. The textures can be created "offline" using optimize() method or automatically created "online" first time they are rendered on a screen. The textures are always created with SDL_TEXTUREACCESS_TARGET flag. |
Attributes: |
|
There are some filters that can be applied to the images (it will affect the source surface and all textures):
There are four image types:
The images can be rendered to any valid screen or another image using:
This is an advance "cloning" manager: when loading from a CDC file an image which is already loaded/created (using the name as the key), it will create a new "clone"(child) for the image. Only a single instance of the Image Manager exists which is created once Main is instantiated.
You can get a reference to this manager using Main::IImageMgr() method.
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 the screens on the most efficient way. | |
Sint32 | CRM64Pro::Image::rebuild () |
Rebuild the current textures. | |
Sint32 | CRM64Pro::Image::render (Sint32 idRes=0, SDL_Rect *rSrc=nullptr, SDL_Rect *rDst=nullptr) |
Render the image to the screen. | |
Sint32 | CRM64Pro::Image::renderEx (const double dAngle, const SDL_Point *poCenter=nullptr, const SDL_FlipMode rf=SDL_FLIP_NONE, Sint32 idRes=0, SDL_Rect *rSrc=nullptr, SDL_Rect *rDst=nullptr) |
Render the image to the screen with extended attributes: can rotate and flipping 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 idImg=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 () |
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 dependant 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.
For displaying the information, it uses 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.
It is used for loading the source surface to images created with ImageMgr::create().
pSurf | SDL_Surface pointer. |
iOwnership | 0 for creating an internal copy of the surface(the one passed to this method can be safetely removed) or any other integer for taking the ownership of the surface(the surface must not be removed if the call to this method return a success code). By default it is set to 0. |
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 the screens on the most efficient way.
idScreen | a valid screen handle used for convert the loaded 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_Rect * | rSrc = nullptr , |
||
SDL_Rect * | rDst = nullptr |
||
) |
Render the image to the screen.
idRes | a valid screen or image handle. By default it tries to use the default screen. |
rSrc | the source SDL_Rect structure or nullptr for the entire image. By default, it is set to nullptr. |
rDst | the destination SDL_Rect structure or nullptr for rendering the image matching the rSrc. It can stretch or shrink the image. By default, it is set to nullptr. |
Sint32 CRM64Pro::Image::renderEx | ( | const double | dAngle, |
const SDL_Point * | poCenter = nullptr , |
||
const SDL_FlipMode | rf = SDL_FLIP_NONE , |
||
Sint32 | idRes = 0 , |
||
SDL_Rect * | rSrc = nullptr , |
||
SDL_Rect * | rDst = nullptr |
||
) |
Render the image to the screen with extended attributes: can rotate and flipping the image.
dAngle | an angle in degrees that indicates the rotation that will be applied. |
poCenter | SDL_Point pointer indicating the point around which the image will be rotated. By default, it is set to nullptr and the rotation will be done around rDst.w/2 and rDst.h/2. |
rf | SDL_FlipMode value stating which flipping actions should be performed. |
idRes | a valid screen or image handle. By default it tries to use the default screen. |
rSrc | the source SDL_Rect structure or nullptr for the entire image. By default, it is set to nullptr. |
rDst | the destination SDL_Rect structure or nullptr for rendering the image matching the rSrc. It can stretch or shrink the image. By default, it is set to nullptr. |
Sint32 CRM64Pro::Image::applyFilter | ( | eImageFilter | eFilter, |
Sint32 | iValue = 0 |
||
) |
Apply a filter to this image.
Works on stand-alone and parents images, children can not apply a filter.
As the image is shared between parent and children, applying a filter to a parent image will affect all the children ones.
eFilter | Check eImageFilter enum for further information. |
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, it is emulated using blending modes, if it is already set, will not be modified, otherwise, SDL_BLENDMODE_BLEND is set.
iR | red color component value from 0 to 255. A negative value will disable the colorkey. |
iG | green color component value from 0 to 255. A negative value will disable the colorkey. |
iB | blue color component value from 0 to 255. A negative value will disable the colorkey. |
Sint32 CRM64Pro::Image::getColorKey | ( | Sint16 & | iR, |
Sint16 & | iG, | ||
Sint16 & | iB | ||
) |
Get colorkey used for rendering this image.
iR | red color component value from 0 to 255. A negative value set the colorkey is disabled. |
iG | green color component value from 0 to 255. A negative value set the colorkey is disabled. |
iB | blue color component value from 0 to 255. A negative value set the 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 the [directory]+filename+[extension]. Ideally, it should have the .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 the [directory]+filename+[extension]. Ideally, it should have the .png extension. Directory separators '\' and '/' are supported. |
Sint32 CRM64Pro::Image::save | ( | const string & | sFileCDC | ) |
Save the image to a CDC file.
sFileCDC | string containing the [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 | ) |
Request Image Manager information.
For displaying the information, it uses the default log.
iMode | -1 for displaying only Manager information. 0 for displaying Manager and all Objects information. This is the default value. idImage for displaying Manager and given Image id information. |
Sint32 CRM64Pro::ImageMgr::create | ( | const string & | sName, |
Uint32 | iVersion = 10 |
||
) |
Creates a new image.
This method will create an empty image (no source surface assigned), use Image::assignSurface() method for assigning the source surface.
sName | The name to give to the image e.g. 'myImage'. The object name must be unique and with a maximum size of 64 characters or will be truncated. The name can not start with the reserved character '#'. |
iVersion | Image version. 10 means 1.0 which is the only version supported (as of now). v1.0 is set by default. |
Sint32 CRM64Pro::ImageMgr::close | ( | Sint32 | idImg | ) |
Close and destroy an image.
This method can only close images that belongs to the default owner (ImageMgr).
idImg | 0 for closing all images or the Image id. Stand-alone and child images can be closed but parent ones, can not as they have at least one dependency(a child). |
Sint32 CRM64Pro::ImageMgr::getNum | ( | ) |
Get number of loaded objects.
Sint32 CRM64Pro::ImageMgr::setName | ( | Sint32 | idImg, |
const string & | sName | ||
) |
Change the object name.
idImg | Image id. |
sName | The name to give to the image e.g. 'myImage'. The object name must be unique and with a maximum size of 64 characters or will be truncated. The name can not start with the reserved character '#'. |
Sint32 CRM64Pro::ImageMgr::closeEx | ( | Sint32 | idImg, |
Uint32 | iOwner | ||
) |
Close and destroy an image.
This method can close images that belongs to any owner but as a security check, the owner must be provided.
idImg | 0 for closing all images or the Image id. Stand-alone and child images can be closed but parent ones, can not as they have at least one dependency(a child). |
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 name to give to the image e.g. 'myImage'. The object name must be unique and with a maximum size of 64 characters or will be truncated. The name can not start with the reserved character '#'. |
Sint32 CRM64Pro::ImageMgr::child | ( | Sint32 | idImg | ) |
Create a child image dependant on the provided one(the parent).
A child image uses the source surface and textures for the screens of its parent but can have different attributes. It is useful for saving memory.
idImg | parent Image id. If the provided image is a child, internally it will redirect this request to the parent in order to create the new child. |
Sint32 CRM64Pro::ImageMgr::isBMP | ( | const string & | sFile | ) |
Check if the file is a BMP.
sFile | string containing the [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 the [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 the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
sName | the image object name. By default, it is set to empty to use the filename (without extension) for setting the image object name. The object name must be unique and with a maximum size of 64 characters or will be truncated. |
Sint32 CRM64Pro::ImageMgr::load | ( | const string & | sFileCDC, |
const string & | sName | ||
) |
Load an image stored in a CDC file.
sFileCDC | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
sName | string with the image name (maximum size of 64 characters). If the Image is already created, this method will call child() for creating a child. |
Sint32 CRM64Pro::ImageMgr::load | ( | const Sint32 | idCDC, |
const string & | sName | ||
) |
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. The object name must be unique and with a maximum size of 64 characters or will be truncated. |
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). |