Core functions

LMF_STATUS generate_mips()

Generate coverage-weighted mip maps.

Generates coverage-weighted mip maps and outputs them as a list of float (0..1) arrays (excluding input image / mip 0)

The mips and masks memory allocated here needs to be freed after use (e.g. after composite_mips() and saving), see free_mips_memory().

Template Parameters:

ImageT

:

uint8_t/uint16_t/float

MaskT

:

uint8_t/uint16_t/float

Parameters:

ImageT* image_in_out

,:

Input image of type uint8_t/uint16_t/float

const uint_fast16_t image_width

,:

Input image width in pixels (must be power of 2)

const uint_fast16_t image_height

,:

Input image height pixels (must be power of 2)

const uint_fast8_t channel_stride

,:

Number of total channels in image data

const MaskT* image_mask

,:

(optional) Coverage mask of type uint8_t/uint16_t/float. Pass nullptr to use last channel of input image instead.

float** mips_output

,:

Array of pointers (float*) that is filled with pointers to the generated mip maps

uint8_t** masks_output

,:

Array of pointers (uint8_t*) that is filled with pointers to the generated coverage masks

const float coverage_threshold = 0.999f

,:

(optional) Threshold to use for binarizing the input mask. Defaults to 0.999f.

const bool convert_srgb = false

,:

(optional) Convert sRGB to linear before scaling? Mips output will be linear. Necessary when scaling sRGB images, to prevent luminosity shifts. Use convert_to_type() to convert the mips back to sRGB if needed.

const bool is_normal_map = false

,:

(optional) Perform processing for normal maps. Will re-normalize vectors to unit length at the moment, Slerp is planned.

const uint8_t channel_mask = 0

,:

(optional) Bit mask of channels to process, 0 = all channels. You can use channel_mask_from_array() to generate a mask from an array of booleans.

const bool scale_alpha_unweighted = false

,:

(optional) Scale the last channel without coverage weighting? i.e. regular box filtering

const uint_fast8_t max_threads = 0

:

(optional) Number of threads to use. 0 = auto (half of available threads, which amounts to number of hardware cores for machines with SMT/HyperThreading)

Returns:

LMF_STATUS enumerator, LMF_STATUS::SUCCESS / 1 on success

LMF_STATUS composite_mips()

Composite mip levels to fill holes.

From smallest to largest, mip levels are consecutively scaled (nearest neighbor) and composited into each other.

Parameters:

float** mips_in_out

,:

Array of pointers to the mip maps (float, 0..1 range), compositing is done in-place

const uint8_t** masks_input

,:

Array of pointers to the mip coverage masks (uint8_t, treated as binary 0/1). Used for compositing.

const uint_fast16_t image_width

,:

Width of original image (i.e. double the width of the largest mip map)

const uint_fast16_t image_height

,:

Height of original image (i.e. double the height of the largest mip map)

const uint_fast8_t channel_stride

,:

Number of total channels in image data

const uint8_t channel_mask = 0

,:

(optional) Bit mask of channels to process, 0 = all channels. You can use channel_mask_from_array() to generate a mask from an array of booleans.

const uint_fast8_t max_threads = 0

:

(optional) Number of threads to use. 0 = auto (half of available threads, which amounts to number of hardware cores for machines with SMT/HyperThreading)

Returns:

LMF_STATUS enumerator, LMF_STATUS::SUCCESS / 1 on success

LMF_STATUS flood_image()

Mip-flood an image.

Generates a mip-flooded image by generating and compositing coverage-scaled mip maps, and then compositing the unmodified original image on top.

Parameters:

ImageT* image_in_out

,:

Input image of type uint8_t/uint16_t/float

const uint_fast16_t image_width

,:

Input image width in pixels (must be power of 2)

const uint_fast16_t image_height

,:

Input image height pixels (must be power of 2)

const uint_fast8_t channel_stride

,:

Number of total channels in image data

const MaskT* image_mask = nullptr

,:

(optional) Coverage mask of type uint8_t/uint16_t/float. Pass nullptr to use last channel of input image instead.

const float coverage_threshold = 0.999f

,:

(optional) Threshold to use for binarizing the input mask. Defaults to 0.999f.

const bool convert_srgb = false

,:

(optional) Convert sRGB to linear and back for correct scaling of sRGB textures?

const bool is_normal_map = false

,:

(optional) Perform processing for normal maps. Will re-normalize vectors to unit length at the moment, Slerp is planned.

const uint8_t channel_mask = 0

,:

(optional) Bit mask of channels to process, 0 = all channels. You can use channel_mask_from_array() to generate a mask from an array of booleans.

const bool scale_alpha_unweighted = false

,:

(optional) Scale the last channel without coverage weighting? i.e. regular box filtering

const uint_fast8_t max_threads = 0

:

(optional) Number of threads to use. 0 = auto (half of available threads, which amounts to number of hardware cores for machines with SMT/HyperThreading)

Returns:

LMF_STATUS enumerator, LMF_STATUS::SUCCESS / 1 on success