class RED::ImageTools

Image saving and loading API. More...

#include <REDImageTools.h>

Inherits: Object.

Public static functions:

static RED_RCClearCustomLoadCallback ( )
static RED_RCConvertFormat ( RED::Object * iImage, const RED::Object * iSourceImage, bool iLocalStorage, RED::FORMAT iFormat )
static RED_RCConvertMetallicToRealisticMaterial ( RED::Object * iDiffuseTexture, int iDiffuseTextureWidth, int iDiffuseTextureHeight, RED::Object * iReflectionTexture, int iReflectionTextureWidth, int iReflectionTextureHeight, RED::Object * iAnisotropyTexture, int iAnisotropyTextureWidth, int iAnisotropyTextureHeight, RED::Object * iIORTexture, int iIORTextureWidth, int iIORTextureHeight, RED::Object * iGlossyEnvironmentalTexture, int iGlossyEnvironmentalTextureSize, const RED::Object * iAlbedoTexture, const RED::Color & iAlbedoColor, const RED::Object * iRoughnessTexture, float iRoughnessValue, const RED::Object * iMetalnessTexture, float iMetalnessValue, const RED::Object * iAOTexture, float iAOStrength, const RED::Object * iAlphaMask, float iAlphaThreshold, bool iAlphaFromAlbedo, const RED::Object * iEnvironmentalTexture, RED::Object * iResMgr, const RED::State & iState )
static RED_RCCopyFrom ( RED::Object * iImage, const RED::Object * iSourceImage, bool iLocalStorage )
static RED_RCGetMeanColor ( RED::Color & oMinColor, RED::Color & oMaxColor, RED::Color & oMeanColor, RED::Object * ioImage, bool iLocalStorage )
static RED_RCLoad ( RED::Object * oImage, const RED::String & iFilePath, RED::FORMAT iPixelFormat, bool iVerticalFlip, bool iLocal, RED::TARGET iTarget, const RED::State & iState )
static RED_RCLoad ( RED::Object * oImage, RED::IStream & iInput, IMAGE_FILE_FORMAT iImageFormat, RED::FORMAT iPixelFormat, bool iVerticalFlip, bool iLocal, RED::TARGET iTarget, const RED::State & iState )
static RED_RCRegisterCustomLoadCallback ( bool & oRegistered, const RED::String & iFileExtension, RED::IMAGE_TOOLS_LOAD_CALLBACK iCallback )
static RED_RCResize ( RED::Object * iImage, const RED::Object * iSourceImage, bool iLocalStorage, int iWidth, int iHeight )
static RED_RCSave ( RED::Object * iImage, bool iLocalStorage, const RED::String & iFilePath, bool iDiscardAlpha, bool iVerticalFlip, float iQuality )
static RED_RCSave ( RED::Object * iImage, bool iLocalStorage, RED::IStream & iOutput, IMAGE_FILE_FORMAT iImageFormat, bool iDiscardAlpha, bool iVerticalFlip, float iQuality )
static RED_RCUnregisterCustomLoadCallback ( const RED::String & iFileExtension )

Public enumerations:

enumIMAGE_FILE_FORMAT { IFF_JPEG =  0, IFF_PNG =  1, IFF_HDR =  2, IFF_TGA =  3, IFF_COUNT =  4 }

Protected static variables:

static RED::Map< RED::String, RED::IMAGE_TOOLS_LOAD_CALLBACK >_custom_load_callback

Detailed description:

Image saving and loading API.

The RED::ImageTools class defines the I/O methods to save or load images through commonly used image file formats.

Currently supported formats are JPEG, PNG, TGA and HDR.

All the API methods take a "vertical flip" flag to reverse the order of the image lines (either at loading or at saving time). This is because while most image formats expect the image origin to be in the top left corner, OpenGL (and so REDsdk) considers the image origin to be in the bottom left corner.

Functions documentation

Clears all the custom callback for image loading.

see RED::ImageTools::RegisterCustomLoadCallback for details about custom callback.

Returns:

RED_OK on success.
public static RED_RC RED::ImageTools::ConvertFormat(RED::Object *iImage,
const RED::Object *iSourceImage,
booliLocalStorage,
RED::FORMATiFormat
)

Converts an image from one format to another.

The result is stored in the local storage of the returned iImage. The source image can't be the same as the destination image.

  • When the source format has 4 channels and the result format has 3 channels, the alpha component is lost.
  • When the source format has 3 or 4 channels and the result format has 1 channel, the channel is filled with (R + G + B) / 3.
  • When the source format has 1 channel and the result format has 3 or 4 channels, they are all filled with the same value.

Float and half float channels have normalized values between 0 and 1. Other formats have values between 0 and 255.

Parameters:

iImage:pointer to the returned image. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iSourceImage:pointer to the image to convert.
iLocalStorage:true to get the content from the local storage of the image, false to get pixels back from video memory.
iFormat:format of the returned image after the conversion.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::ConvertMetallicToRealisticMaterial(RED::Object *iDiffuseTexture,
intiDiffuseTextureWidth,
intiDiffuseTextureHeight,
RED::Object *iReflectionTexture,
intiReflectionTextureWidth,
intiReflectionTextureHeight,
RED::Object *iAnisotropyTexture,
intiAnisotropyTextureWidth,
intiAnisotropyTextureHeight,
RED::Object *iIORTexture,
intiIORTextureWidth,
intiIORTextureHeight,
RED::Object *iGlossyEnvironmentalTexture,
intiGlossyEnvironmentalTextureSize,
const RED::Object *iAlbedoTexture,
const RED::Color &iAlbedoColor,
const RED::Object *iRoughnessTexture,
floatiRoughnessValue,
const RED::Object *iMetalnessTexture,
floatiMetalnessValue,
const RED::Object *iAOTexture,
floatiAOStrength,
const RED::Object *iAlphaMask,
floatiAlphaThreshold,
booliAlphaFromAlbedo,
const RED::Object *iEnvironmentalTexture,
RED::Object *iResMgr,
const RED::State &iState
)

Converts PBR metallic material parameters into realistic material parameters.

From a set of metallic material parameters, this function outputs ready-to-use textures to use with RED::IMaterial::SetupRealisticMaterial.

Metallic material inputs are:

  • albedo texture and color;
  • roughness texture and value;
  • metalness texture and value;
  • AO texture and strength.

Albedo, roughness and metalness textures are optional. If NULL, the associated color or value is used instead. If the texture is valid, its data is modulated by the associated color or value following the formula: result = texture * color.

AO texture is optionnal. iAOStrength controls how much of the AO is applied. A value of 0.0 means no occlusion. A value of 1.0 means full occlusion. This value affects the resulting diffuse using the formula: diffuse = lerp( color, color * iAOTexture, iAOStrength ). iAOStrength is ignored if the AO texture is NULL.

Note:

This function works with image local storage. Make sure that the texture data are in the local storage before calling it. Also make sure to call RED::IImage2D::SetPixels before using the output images in the realistic material.

Output realistic material parameters are:

  • diffuse texture;
  • reflection texture;
  • reflection anisotropy texture;
  • IOR texture.

Note:

The Fresnel parameter of the realistic material must be turned ON when using this function.

All the textures implement the RED::IImage2D interface except iGlossyEnvironmentalTexture which is a RED::IImageCube.

All textures are set with the wrapping mode of the first input texture found (iAlbedoTexture, iRoughnessTexture, iMetalnessTexture, iAOTexture). If no input textures are supplied, then the wrap mode is set to RED::WM_REPEAT by default.

When iAlphaMask is provided, the output reflection is discarded where the value of the mask is under iAlphaThreshold and the oIOR is set to 1. It allows to have a perfect transparency without any refraction effect where the mask is off.

Note:

iAlphaThreshold can be negative. If so, the comparison is inverted and the values are discarded where the mask is over the absolute value of iThreshold.

The alpha mask can also be taken from the albedo alpha channel when iAlphaFromAlbedo parameter is true. In this case, no separate alpha mask texture should be provided.

In addition to the traditionnal PBR inputs, the function can convert an environmental texture used for realtime reflections. The texture is blurred according to the average roughness of the material. iEnvironmentalTexture can be provided as a cube map implementing RED::IImageCube or as a latitude / longitude environment map implementing RED::IImage2D. iGlossyEnvironmentalTexture implements the RED::IImageCube interface.

task

Task: Converting PBR metallic data to the realistic material

REDsdk provides a helper function to convert data from a PBR metallic workflow into its realistic material.

Here is how to use it:

// Create the images.
RED::Object *diffuse, *reflection, *anisotropy, *ior;
RC_TEST( iresmgr->CreateImage2D( diffuse, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( reflection, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( anisotropy, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( ior, iresmgr->GetState() ) );

RED::Object *albedo, *roughness, *metalness, *normal;
RC_TEST( iresmgr->CreateImage2D( albedo, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( roughness, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( metalness, iresmgr->GetState() ) );
RC_TEST( iresmgr->CreateImage2D( normal, iresmgr->GetState() ) );

// Load the images. Use the local storage.
RC_TEST( RED::ImageTools::Load( albedo, "albedo.png", RED::FMT_RGB, true, true, RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( RED::ImageTools::Load( roughness, "roughness.png", RED::FMT_FLOAT, true, true, RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( RED::ImageTools::Load( metalness, "metalness.png", RED::FMT_FLOAT, true, true, RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( RED::ImageTools::Load( normal, "normal.png", RED::FMT_RGB, true, true, RED::TGT_TEX_2D, iresmgr->GetState() ) );

// Convert metallic workflow images into realistic material data.
RC_TEST( RED::ImageTools::ConvertMetallicToRealisticMaterial( diffuse, 2048, 2048,        // Returned diffuse
                                                              reflection, 2048, 2048,     // Returned reflection
                                                              anisotropy, 2048, 2048,     // Returned anisotropy
                                                              ior, 2048, 2048,            // Returned IOR
                                                              NULL, 0,                    // No environment map.
                                                              albedo, RED::Color::WHITE,  // PBR Albedo
                                                              roughness, 1.f,             // PBR roughness
                                                              metalness, 1.f,             // PBR metallic
                                                              NULL, 1.f,                  // No PBR ambient occlusion
                                                              NULL, 0.5f, false,          // No alpha mask
                                                              NULL,                       // No environment texture
                                                              resmgr, iresmgr->GetState() ) );

// The convert function works in local storage, don't forget RED::IImage2D::SetPixels.
RC_TEST( diffuse->As< RED::IImage2D >()->SetPixels( RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( reflection->As< RED::IImage2D >()->SetPixels( RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( anisotropy->As< RED::IImage2D >()->SetPixels( RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( ior->As< RED::IImage2D >()->SetPixels( RED::TGT_TEX_2D, iresmgr->GetState() ) );
RC_TEST( normal->As< RED::IImage2D >()->SetPixels( RED::TGT_TEX_2D, iresmgr->GetState() ) );

// Use the textures in the realistic material: diffuse, reflection, anisotropy and normal.
// Use the returned IOR and set Fresnel on.
RC_TEST( imaterial->SetupRealisticMaterial(
  false,                                                                // Double sided
  true,                                                                 // Fresnel
  RED::Color::RED, diffuse, RED::Matrix::IDENTITY, RED::MCL_TEX0,       // Diffusion
  RED::Color::WHITE, reflection, RED::Matrix::IDENTITY, RED::MCL_TEX0,  // Reflection
  RED::Color::WHITE, FLT_MAX,                                           // Reflection fog
  false, false, NULL, RED::Matrix::IDENTITY,                            // Environment
  RED::Color::BLACK, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,        // Transmission
  0.0f, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,                     // Transmission glossiness
  1.0f, ior, RED::Matrix::IDENTITY, RED::MCL_TEX0,                      // IOR
  RED::Color::WHITE, 1.0f,                                              // Transmission scattering
  false, false,                                                         // Caustics
  RED::Color::BLACK, anisotropy, RED::Matrix::IDENTITY, RED::MCL_TEX0,  // Reflection anisotropy
  0.0f, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,                     // Reflection anisotropy orientation
  normal, RED::Matrix::IDENTITY, RED::MCL_TEX0, RED::MCL_USER0,         // Bump
  0.0f, 0.0f, NULL, RED::Matrix::IDENTITY, RED::MCL_TEX0,               // Displacement
  NULL, &RED::LayerSet::ALL_LAYERS,                                     // Layersets
  resmgr, iresmgr->GetState() ) );                                      // Engine stuff

In this sample, neither AO texture nor environment texture are used. They can be set to NULL.

Parameters:

iDiffuseTexture:pointer to the returned diffuse image. RED::FMT_RGB format. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iDiffuseTextureWidth:width of the returned diffuse image.
iDiffuseTextureHeight:height of the returned diffuse image.
iReflectionTexture:pointer to the returned reflection image. RED::FMT_RGB format. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iReflectionTextureWidth:width of the returned reflection image.
iReflectionTextureHeight:height of the returned reflection image.
iAnisotropyTexture:pointer to the returned anisotropy image. RED::FMT_RGB format. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iAnisotropyTextureWidth:width of the returned anisotropy image.
iAnisotropyTextureHeight:height of the returned anisotropy image.
iIORTexture:pointer to the returned IOR image. RED::FMT_HALF_FLOAT format. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iIORTextureWidth:width of the returned IOR image.
iIORTextureHeight:height of the returned IOR image.
iGlossyEnvironmentalTexture:environmental texture used for realtime reflections. RED::FMT_RGB format. Can be NULL.
iGlossyEnvironmentalTextureSize:environmental texture cube size. Must be power of two.
iAlbedoTexture:albedo texture from the metallic material. Can be NULL.
iAlbedoColor:albedo color from the metallic material.
iRoughnessTexture:roughness texture from the metallic material. Can be NULL.
iRoughnessValue:roughness value from the metallic material.
iMetalnessTexture:metalness texture from the metallic material. Can be NULL.
iMetalnessValue:metalness value from the metallic material.
iAOTexture:ambient occlusion texture from the metallic material. Can be NULL.
iAOStrength:controls the amount of AO applied. Range from 0 (no AO) to 1(full AO).
iAlphaMask:alpha mask texture. Allows to "cancel" refraction effect under transparency pixels. Can be NULL.
iAlphaThreshold:controls the threshold value of the alpha mask under which a pixel is rejected.
iAlphaFromAlbedo:true to take the alpha mask from the albedo alpha channel. false to take it from iAlphaMask.
iEnvironmentalTexture:environmental texture. Can be NULL.
iResMgr:resource manager implementing RED::IResourceManager.
iState:current transaction parameter.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::CopyFrom(RED::Object *iImage,
const RED::Object *iSourceImage,
booliLocalStorage
)

Copy a source content pixels into a destination image. 2D images only.

The result is stored in the local storage of the returned iImage. The source image can't be the same as the destination image. Target, pixels, anisotropy, wrap modes, filter modes and mimmap modes are copied.

Parameters:

iImage:pointer to the returned image. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iSourceImage:pointer to the source image.
iLocalStorage:true to get the content from the local storage of the souce image, false to get pixels back from video memory.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value, or if an image is not a 2D image,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::GetMeanColor(RED::Color &oMinColor,
RED::Color &oMaxColor,
RED::Color &oMeanColor,
RED::Object *ioImage,
booliLocalStorage
)

Calculates the mean color of an image.

This method calculates the mean color of an image. ioImage must be a valid RED::IImage2D image. It's local pixel storage will be overwritten by the operation unless iLocalStorage is set to true.

Please note that DXT based compressed formats are ignored by the method.

Parameters:

oMinColor:The minimal color in the image (e.g. the lowest RGBA intensity pixel as defined by RED::Color::Intensity).
oMaxColor:The maximal color in the image (e.g. the highest RGBA luminance pixel as defined by RED::Color::Intensity).
oMeanColor:The average color in the image.
ioImage:Source image to read from. Must implement RED::IImage2D.
iLocalStorage:True to read from the image local storage, false to first retrieve image pixels on the CPU.

Returns:

RED_OK on success,
RED_BAD_PARAM if ioImage is not valid or not of the expected kind,
Other RED_RCs can be returned by image function tools.
public static RED_RC RED::ImageTools::Load(RED::Object *oImage,
const RED::String &iFilePath,
RED::FORMATiPixelFormat,
booliVerticalFlip,
booliLocal,
RED::TARGETiTarget,
const RED::State &iState
)

Loads an image from a file. This is a helper method; for full documentation, please refer to the stream version of the Load method.

If iLocal is true, the loaded image is stored in the local storage of the RED image and is not sent to the GPU by default. It's up to the user to decide or not to synchronize the GPU version of the image with the local one by calling SetPixels on it. If iLocal is false, the image is directly uploaded into the graphics card memory and ready to use by the hardware.

Files ending with the '.jpeg' or '.jpg' extensions are loaded as JPEG files. Files ending with the '.png' extension are loaded as PNG files. Files ending with the '.hdr' or '.rgbe' extensions are loaded as HDR files. Files ending with the '.tga' extensions are loaded as TGA files.

The method is not case sensitive.

Note:

Some restrictions apply to the HDR format support: only HDR files using the 'bit_rle_rgbe' format and oriented along '-y +x' are supported.

See also How to load and save image to file?.

Parameters:

oImagepointer to the returned image. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iFilePathfull path to the source file.
iPixelFormatrequested pixel format for the returned image.
iVerticalFliptrue to flip the loaded image lines of pixels vertically, false to let it unchanged.
iLocaltrue to load the image in the local (CPU memory) storage of the image, false to load it directly in the graphics card memory.
iTargetthis specifies the target of the loaded image once in the graphics card memory. Note that the target must be chosen in accordance with the requested iPixelFormat.
iStatecurrent transaction.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_IMAGE_UNSUPPORTED_FORMAT on an unsupported file format,
RED_IMAGE_UNSUPPORTED_EXTENSION on an unsupported file extension,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::Load(RED::Object *oImage,
RED::IStream &iInput,
IMAGE_FILE_FORMATiImageFormat,
RED::FORMATiPixelFormat,
booliVerticalFlip,
booliLocal,
RED::TARGETiTarget,
const RED::State &iState
)

Loads an image from a stream.

The method loads an image from a stream and fills a provided RED::Object with its content. The oImage instance must implement the RED::IImage2D and RED::IImage interfaces.

Note:

Some restrictions apply to the HDR format support: only HDR files using the 'bit_rle_rgbe' format and oriented along '-y +x' are supported.

If iLocal is true, the loaded image is stored in the local storage of the RED image and is not sent to the GPU by default. It's up to the user to decide or not to synchronize the GPU version of the image with the local one by calling SetPixels on it. If iLocal is false, the image is directly uploaded into the graphics card memory and is ready to use by the hardware. The GPU texture target is set to iTarget.

If the input stream is not opened, the method opens it in RED::AM_READ mode. The stream cursor is left at the last read position when leaving the method and the stream is not closed.

The user can specify in which pixel format the returned image must be set. Depending on the image file format, some components of the returned image may be initialized to default values.

The table below summarizes the translations which can occur between image file formats and requested pixel formats:

Image file format Pixel format Conversion
JPEG/PNG/TGA - RGB RED::FMT_RGBAR, G, B, 1
JPEG/PNG/TGA - RGB RED::FMT_RGBR, G, B
JPEG/PNG/TGA - RGB RED::FMT_FLOAT( R + G + B ) / ( 3 * 255 )
JPEG/PNG/TGA - RGB RED::FMT_FLOAT_RGBAR / 255, G / 255, B / 255, 1
JPEG/PNG/TGA - RGB RED::FMT_FLOAT_RGBR / 255, G / 255, B / 255
JPEG/PNG/TGA - RGB RED::FMT_L8( R + G + B ) / 3
JPEG/PNG/TGA - RGB RED::FMT_A8( R + G + B ) / 3
JPEG/PNG/TGA - RGB RED::FMT_RGBA_DXT1fail
JPEG/PNG/TGA - RGB RED::FMT_RGBA_DXT3fail
JPEG/PNG/TGA - RGB RED::FMT_RGBA_DXT5fail
JPEG/PNG/TGA - RGB RED::FMT_RGB_DXT1fail
JPEG/PNG/TGA - RGB RED::FMT_HALF_FLOAT( R + G + B ) / ( 3 * 255 )
JPEG/PNG/TGA - RGB RED::FMT_HALF_FLOAT_RGBAR / 255, G / 255, B / 255, 1
JPEG/PNG/TGA - RGB RED::FMT_HALF_FLOAT_RGBR / 255, G / 255, B / 255
JPEG/PNG/TGA - RGB RED::FMT_FLOAT_RGBA_AAfail
PNG/TGA - RGBA RED::FMT_RGBAR, G, B, A
PNG/TGA - RGBA RED::FMT_RGBR, G, B
PNG/TGA - RGBA RED::FMT_FLOAT( R + G + B ) / ( 3 * 255 )
PNG/TGA - RGBA RED::FMT_FLOAT_RGBAR / 255, G / 255, B / 255, A / 255
PNG/TGA - RGBA RED::FMT_FLOAT_RGBR / 255, G / 255, B / 255
PNG/TGA - RGBA RED::FMT_L8( R + G + B ) / 3
PNG/TGA - RGBA RED::FMT_A8( R + G + B ) / 3
PNG/TGA - RGBA RED::FMT_RGBA_DXT1fail
PNG/TGA - RGBA RED::FMT_RGBA_DXT3fail
PNG/TGA - RGBA RED::FMT_RGBA_DXT5fail
PNG/TGA - RGBA RED::FMT_RGB_DXT1fail
PNG/TGA - RGBA RED::FMT_HALF_FLOAT( R + G + B ) / ( 3 * 255 )
PNG/TGA - RGBA RED::FMT_HALF_FLOAT_RGBAR / 255, G / 255, B / 255, A / 255
PNG/TGA - RGBA RED::FMT_HALF_FLOAT_RGBR / 255, G / 255, B / 255
PNG/TGA - RGBA RED::FMT_FLOAT_RGBA_AAfail
HDR - float RGB RED::FMT_RGBAR * 255, G * 255, B * 255, 255
HDR - float RGB RED::FMT_RGBR * 255, G * 255, B * 255
HDR - float RGB RED::FMT_FLOAT( R + G + B ) / 3
HDR - float RGB RED::FMT_FLOAT_RGBAR, G, B, 1
HDR - float RGB RED::FMT_FLOAT_RGBR, G, B
HDR - float RGB RED::FMT_L8255 * ( R + G + B ) / 3
HDR - float RGB RED::FMT_A8255 * ( R + G + B ) / 3
HDR - float RGB RED::FMT_RGBA_DXT1fail
HDR - float RGB RED::FMT_RGBA_DXT3fail
HDR - float RGB RED::FMT_RGBA_DXT5fail
HDR - float RGB RED::FMT_RGB_DXT1fail
HDR - float RGB RED::FMT_HALF_FLOAT( R + G + B ) / 3
HDR - float RGB RED::FMT_HALF_FLOAT_RGBAR, G, B, A
HDR - float RGB RED::FMT_HALF_FLOAT_RGBR, G, B
HDR - float RGB RED::FMT_FLOAT_RGBA_AAfail

where R, G, B, A are the respective red, green, blue and alpha components of the input image file

The conversion columns give the format of the output pixel after conversion.

Please note also that if a conversion occurs, the time to process the whole image can be big depending on the image resolution and the complexity of the conversion.

See also How to load and save image to file?.

Parameters:

oImagepointer to the returned image. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iInputreference to the input stream.
iImageFormatimage file format.
iPixelFormatrequested pixel format for the returned image.
iVerticalFliptrue to flip the loaded image lines of pixels vertically, false to let it unchanged.
iLocaltrue to load the image in the local (CPU memory) storage of the image, false to load it directly in the graphics card memory. If iLocal is true, then the source pixel array is kept in the local storage of the image regardless of the value of iTarget. If iLocal is false, the source pixel array is loaded and then set into the image with possible formats & conversions depending on the hardware backend capabilities and value of iTarget. For instance, a non-power-of-two (NPOTD) image can be loaded and will remain as NPOTD in the local storage while it'll be turned into a power-of-two (POTD) image if iLocal is false and iTarget is RED::TGT_TEX_2D for instance.
iTargetthis specifies the target of the loaded image once in the graphics card memory. Note that the target must be chosen in accordance with the requested iPixelFormat.
iStatecurrent transaction.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_IMAGE_UNSUPPORTED_FORMAT on an unsupported file extension,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::RegisterCustomLoadCallback(bool &oRegistered,
const RED::String &iFileExtension,
RED::IMAGE_TOOLS_LOAD_CALLBACKiCallback
)

Registers a custom callback for image loading.

When calling RED::ImageTools::Load, if a callback has been registered for the file extension, it will be called instead of the regular Load method.

Registering a new loading callback allows to handle files formats that are not supported natively by REDsdk.

The iFileExtension doesn't include the dot (e.g. "png" or "jpg") and the comparison is case insensitive.

Parameters:

oRegistered:Returned true if the callback has been registered, false if this extension was already registered.
iFileExtension:The file extension to register.
iCallback:The callback function to associate to the extension.

Returns:

RED_OK on success,
RED_BAD_PARAM if iCallback is NULL,
RED_ALLOC_FAILURE if an internal allocation did fail.
public static RED_RC RED::ImageTools::Resize(RED::Object *iImage,
const RED::Object *iSourceImage,
booliLocalStorage,
intiWidth,
intiHeight
)

Resizes an image by filtering its content.

The result is stored in the local storage of the returned iImage. The source image can't be the same as the destination image.

The format of the image is not changed during the operation.

Parameters:

iImage:pointer to the returned image. This image must have been properly created before the call (and must implement RED::IImage and RED::IImage2D interfaces).
iSourceImage:pointer to the image to resize.
iLocalStorage:true to get the content from the local storage of the image, false to get pixels back from video memory.
iWidth:width of the returned image after the resizing.
iHeight:height of the returned image after the resizing.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::Save(RED::Object *iImage,
booliLocalStorage,
const RED::String &iFilePath,
booliDiscardAlpha,
booliVerticalFlip,
floatiQuality
)

Saves an image to a file. This is a helper method; for full documentation, please refer to the stream version of the Save method.

The format used to save the image is derived from the given file path extension:

  • '.jpg' and '.jpeg' turn into IFF_JPEG.
  • '.png' turns into IFF_PNG.
  • '.hdr' and '.rgbe' turn into IFF_HDR.
  • '.tga' turns into IFF_TGA.
  • other formats make the method to return with RED_IMAGE_UNSUPPORTED_EXTENSION.

See also How to load and save image to file?.

Parameters:

iImage:Pointer to the image to save. iImage pixels may be downloaded from the GPU.
iLocalStorage:true to save the content of the local storage of the image, false to get pixels back from video memory.
iFilePathfull path to the destination file.
iDiscardAlphatrue to discard the alpha component of the image, false otherwise. If the image has no alpha component, the flag has no effect.
iVerticalFliptrue to flip the saved image lines of pixels vertically, false to let it unchanged.
iQualityquality of the image compression (in [0, 1]). This parameter is meaningful only for lossy compression image formats (like JPEG). It's discarded for other image formats.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_IMAGE_UNSUPPORTED_EXTENSION on an unsupported file extension,
RED_IMAGE_UNSUPPORTED_FORMAT on an unsupported pixel format for the given file extension,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.
public static RED_RC RED::ImageTools::Save(RED::Object *iImage,
booliLocalStorage,
RED::IStream &iOutput,
IMAGE_FILE_FORMATiImageFormat,
booliDiscardAlpha,
booliVerticalFlip,
floatiQuality
)

Saves an image to a stream. The stream can be either a memory or a file stream.

If the output stream is not opened, the method opens it in RED::AM_WRITE mode. The stream cursor is left at the last write position when leaving the method and the stream is not closed.

Depending on the image file format, the alpha component of the source image can be saved or not:

  • the JPEG format can't handle the alpha component and therefore it's discarded (iDiscardAlpha is true whatever the value set by the caller).
  • the same goes for HDR which also discards automatically any alpha component in the input image.
  • the PNG format can handle the alpha component and follows the value of the iDiscardAlpha flag set by the caller.
  • the TGA format can handle the alpha component and follows the value of the iDiscardAlpha flag set by the caller.

An automatic conversion process of the input image can occur if the pixel format does not match the ones supported by the selected image file format. For example, a RED::FMT_FLOAT_RGB image will be first converted to RED::FMT_RGB before being saved to a JPEG file.

A summary of all the conversions is given in the table below:

Input pixel format Conversion for JPEG, PNG and TGA Conversion for HDR
RED::FMT_RGBAR, G, B, A R, G, B
RED::FMT_RGBR, G, B R, G, B
RED::FMT_FLOAT[F]*255, [F]*255, [F]*255 F, F, F
RED::FMT_FLOAT_RGBA[FR]*255, [FG]*255, [FB]*255, [FA]*255 FR, FG, FB
RED::FMT_FLOAT_RGB[FR]*255, [FG]*255, [FB]*255 FR, FG, FB
RED::FMT_L8L8, L8, L8 L8, L8, L8
RED::FMT_A80, 0, 0, A8 0, 0, 0
RED::FMT_RGBA_DXT1fail fail
RED::FMT_RGBA_DXT3fail fail
RED::FMT_RGBA_DXT5fail fail
RED::FMT_RGB_DXT1fail fail
RED::FMT_HALF_FLOAT[HF]*255, [HF]*255, [HF]*255 HF, HF, HF
RED::FMT_HALF_FLOAT_RGBA[HFR]*255, [HFG]*255, [HFB]*255, [HFA]*255HFR, HFG, HFB
RED::FMT_HALF_FLOAT_RGB[HFR]*255, [HFG]*255, [HFB]*255 HFR, HFG, HFB
RED::FMT_FLOAT_RGBA_AApixels are converted to FMT_FLOAT_RGBA and then to the format given in that tablepixels are converted to FMT_FLOAT_RGBA and then to the format given in that table

where R, G, B, A are the respective red, green, blue and alpha 8bit components of the input image file F is the float component of the single component float input image FR, FG, FB, FA are the respective red, green, blue and alpha components of the float input image HF is the half-float component of the single component half-float input image HFR, HFG, HFB, HFA are the respective red, green, blue and alpha components of the half-float input image L8 is the L8 component of the input image A8 is the A8 component of the input image [] is the clamping operator: the input value is clamped to the [0, 1] range.

The conversion columns give the format of the output pixel after conversion.

Please note that due to IP reasons, DXT images are not saved neither load using the RED::ImageTools methods.

Note also that if a conversion occurs, the time to process the whole image can be big depending on the image resolution and the complexity of the conversion.

According to the selected image file format and the value of the iDiscardAlpha flag, the alpha component after conversion is discarded or not of the destination image. Hence, a RED::FMT_A8 image saved to a JPEG file will be totally white.

See also How to load and save image to file?.

Parameters:

iImagepointer to the image to save.
iLocalStoragetrue to save the content of the local storage of the image, false to get pixels back from video memory.
iOutputreference the destination stream.
iImageFormatimage file format.
iDiscardAlphatrue to discard the alpha component of the image, false otherwise. If the image has no alpha component, the flag has no effect.
iVerticalFliptrue to flip the saved image lines of pixels vertically, false to let it unchanged.
iQualityquality of the image compression (in [0, 1]). This parameter is meaningful only for lossy compression image formats (like JPEG). It's discarded for other image formats.

Returns:

RED_OK on success,
RED_BAD_PARAM on an invalid parameter value,
RED_IMAGE_UNSUPPORTED_EXTENSION on an unsupported file extension,
RED_IMAGE_UNSUPPORTED_FORMAT on an unsupported pixel format for the given file extension,
RED_ALLOC_FAILURE on a memory allocation error,
RED_FAIL otherwise.

Unregisters a custom callback for image loading.

see RED::ImageTools::RegisterCustomLoadCallback for details about custom callback.

Parameters:

iFileExtension:The file extension to unregister.

Returns:

RED_OK on success.

Variables documentation

List of custom loading callbacks.

Enumerations documentation

Lists all the supported image file formats.

Enumerator:

IFF_JPEG

Lossy compression in RED::FMT_RGB format.

IFF_PNG

Lossless compression in RED::FMT_RGB or RED::FMT_RGBA format.

IFF_HDR

Radiance's picture format (RED::FMT_FLOAT_RGB) with lossless compression.

IFF_TGA

Lossless compression in RED::FMT_RGB or RED::FMT_RGBA format.

IFF_COUNT