| CRM64Pro GDK v0.19.0 A free cross-platform game development kit built on top of SDL 3.0

Loading...
Searching...
No Matches
CRM64Pro::ImageMgrfinal
Graphics modules » Image

Image Manager class. More...

## Detailed Description

Image Manager class.

## Public Member Functions
bool | info (Sint32 iMode=0) override
| Request Image Manager information.
Sint32 | create (const string &sName, Uint32 iVersion=10) override
| Creates a new image.
Sint32 | close (Sint32 idImg) override
| Close and destroy an image.
Sint32 | getCount () const override
| Get number of loaded objects.
Sint32 | setName (Sint32 idImg, const string &sName) override
| Change the object name.
Sint32 | closeEx (Sint32 idImg, Uint32 iOwner)
| Close and destroy an image.
Image * | get (Sint32 idImg)
| Get a pointer to the image using its handle.
Sint32 | duplicate (Sint32 idImg, const string &sName)
| Duplicate an image creating a new, identical and independent one.
Sint32 | child (Sint32 idImg)
| Create a child image dependent on the provided one (the parent).
bool | isBMP (const string &sFile) const
| Check if the file is a BMP.
bool | isPNG (const string &sFile) const
| Check if the file is a PNG.
Sint32 | loadFromFile (const string &sFile, const string &sName="")
| Load an image from an external file (BMP or PNG formats).
Sint32 | load (const string &sCDCFile, const string &sName)
| Load an image stored in a CDC file.
Sint32 | load (Sint32 idCDC, const string &sName)
| Load an image stored in a CDC file.
Sint32 | loadFromBuffer (const void *pBuffer, Sint32 iSize, const string &sName)
| Load an image (BMP or PNG formats) stored on a memory buffer.
Sint32 | loadFromSurface (SDL_Surface *pSurface, const string &sName)
| Load an image from an existing SDL_Surface.
Sint32 | remove (Sint32 idCDC, const string &sName)
| Remove an image stored in a CDC file.
bool | exists (Sint32 idCDC, const string &sName) const
| Check if an image is stored in a CDC file.
bool | exists (const string &sCDCFile, const string &sName) const
| Check if an image is stored in a CDC file.

## Member Function Documentation

## ◆ info()

bool CRM64Pro::ImageMgr::info | ( | Sint32 | iMode = 0 | ) |
| override

Request Image Manager information.

Writes manager information to the default log.

Parameters

  iMode | -1 to display only manager information. 0 (default) to display manager and all objects. A specific object ID displays manager information and only that object.

Returns
  true on success, or false on failure.

## ◆ create()

Sint32 CRM64Pro::ImageMgr::create | ( | const string & | sName,
|  | Uint32 | iVersion = 10 )
| override

Creates a new image.

Creates an empty image (no source surface). Use Image::assignSurface() to assign the source surface.

Parameters

  sName | The image name (e.g. 'pImage'). Must be unique and shorter than 64 characters.
  iVersion | Image version. 10 means v1.0 (only version supported). Default v1.0.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

Note
  Returns error if name already exists.

## ◆ close()

Sint32 CRM64Pro::ImageMgr::close | ( | Sint32 | idImg | ) |
| override

Close and destroy an image.

This method can only close images belonging to the default owner (ImageMgr).

Parameters

  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.

Returns
  0 on success, or a negative error code on failure.

Note
  Unclosed images are automatically closed when the GDK terminates.

## ◆ getCount()

Sint32 CRM64Pro::ImageMgr::getCount | ( |  | ) | const
| override

Get number of loaded objects.

Returns
  the number of images.

## ◆ setName()

Sint32 CRM64Pro::ImageMgr::setName | ( | Sint32 | idImg,
|  | const string & | sName )
| override

Change the object name.

Parameters

  idImg | Image id.
  sName | The image name (e.g. 'pImage'). Must be unique and shorter than 64 characters.

Returns
  0 on success, or a negative error code on failure.

## ◆ closeEx()

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.

Parameters

  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.

Returns
  0 on success, or a negative error code on failure.

Note
  Unclosed images are automatically closed when the GDK terminates.

## ◆ get()

Image * CRM64Pro::ImageMgr::get | ( | Sint32 | idImg | ) |

Get a pointer to the image using its handle.

Parameters

  idImg | Image id.

Returns
  Borrowed pointer to the Image object, or nullptr if not found.

Note
  The returned pointer must not be deleted. It remains valid until the Image is closed or ImageMgr is reset or terminated.

## ◆ duplicate()

Sint32 CRM64Pro::ImageMgr::duplicate | ( | Sint32 | idImg,
|  | const string & | sName )

Duplicate an image creating a new, identical and independent one.

Parameters

  idImg | Image id to be duplicated.
  sName | The image name (e.g. 'pImage'). Must be unique and shorter than 64 characters.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

Note
  Returns error if name already exists. New image is not optimized; call Image::optimize() if needed.

## ◆ child()

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.

Parameters

  idImg | parent Image id. If the provided image is a child, the request is redirected to its parent.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

Note
  The child uses the parent's name.

## ◆ isBMP()

bool CRM64Pro::ImageMgr::isBMP | ( | const string & | sFile | ) | const

Check if the file is a BMP.

Parameters

  sFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported.

Returns
  true if it is a BMP or false on failure.

## ◆ isPNG()

bool CRM64Pro::ImageMgr::isPNG | ( | const string & | sFile | ) | const

Check if the file is a PNG.

Parameters

  sFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported.

Returns
  true if it is a PNG or false on failure.

## ◆ loadFromFile()

Sint32 CRM64Pro::ImageMgr::loadFromFile | ( | const string & | sFile,
|  | const string & | sName = "" )

Load an image from an external file (BMP or PNG formats).

Parameters

  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 and shorter than 64 characters.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

## ◆ load() [1/2]

Sint32 CRM64Pro::ImageMgr::load | ( | const string & | sCDCFile,
|  | const string & | sName )

Load an image stored in a CDC file.

Parameters

  sCDCFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported.
  sName | string with the image name (shorter than 64 characters). If already exists, creates a child instead.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

## ◆ load() [2/2]

Sint32 CRM64Pro::ImageMgr::load | ( | Sint32 | idCDC,
|  | const string & | sName )

Load an image stored in a CDC file.

Parameters

  idCDC | CDC id.
  sName | string with the image name (shorter than 64 characters). If already exists, creates a child instead.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

## ◆ loadFromBuffer()

Sint32 CRM64Pro::ImageMgr::loadFromBuffer | ( | const void * | pBuffer,
|  | Sint32 | iSize,
|  | const string & | sName )

Load an image (BMP or PNG formats) stored on a memory buffer.

Parameters

  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 and shorter than 64 characters.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

## ◆ loadFromSurface()

Sint32 CRM64Pro::ImageMgr::loadFromSurface | ( | SDL_Surface * | pSurface,
|  | const string & | sName )

Load an image from an existing SDL_Surface.

Useful for procedurally generated images.

Parameters

  pSurface | Pointer to the SDL_Surface.
  sName | string with the image object name.

Returns
  Greater than 0 on success (the Image id), or a negative error code on failure.

## ◆ remove()

Sint32 CRM64Pro::ImageMgr::remove | ( | Sint32 | idCDC,
|  | const string & | sName )

Remove an image stored in a CDC file.

Parameters

  idCDC | CDC id.
  sName | string with the image name (shorter than 64 characters).

Returns
  0 on success, or a negative error code on failure.

Note
  The image must be closed before trying to remove it from the CDC.

## ◆ exists() [1/2]

bool CRM64Pro::ImageMgr::exists | ( | Sint32 | idCDC,
|  | const string & | sName ) const

Check if an image is stored in a CDC file.

Parameters

  idCDC | CDC id.
  sName | string with the image name (shorter than 64 characters).

Returns
  true if the resource is stored in the CDC file, or false otherwise. No error is reported.

Note
  It is normally used for checking if an image is present without throwing any error.

## ◆ exists() [2/2]

bool CRM64Pro::ImageMgr::exists | ( | const string & | sCDCFile,
|  | const string & | sName ) const

Check if an image is stored in a CDC file.

Parameters

  sCDCFile | Path to the CDC archive file.
  sName | string with the image name (shorter than 64 characters).

Returns
  true if the resource is stored in the CDC file, or false otherwise. No error is reported.

Note
  It is normally used for checking if an image is present without throwing any error.