AVIR
High-quality pro image resizing library
 
All Classes Files Functions Variables Typedefs Macros Pages
Loading...
Searching...
No Matches
avir::CLancIR Class Reference

LANCIR image resizer class. More...

#include <lancir.h>

Classes

class  CResizeFilters
 Class for fractional delay filter bank storage and calculation. More...
 
struct  CResizePos
 Structure defines source scanline positions and filters for each destination pixel. More...
 
class  CResizeScanline
 Scanline resizing positions class. More...
 

Public Member Functions

template<typename Tin, typename Tout>
int resizeImage (const Tin *const SrcBuf, const int SrcWidth, const int SrcHeight, const int SrcSSize, Tout *const NewBuf, const int NewWidth, const int NewHeight, const int NewSSize, const int ElCount, const double kx0=0.0, const double ky0=0.0, double ox=0.0, double oy=0.0)
 Legacy image resizing function.
 
template<typename Tin, typename Tout>
int resizeImage (const Tin *const SrcBuf, const int SrcWidth, const int SrcHeight, Tout *const NewBuf, const int NewWidth, const int NewHeight, const int ElCount, const CLancIRParams *const aParams=NULL)
 Function resizes an image.
 

Static Protected Member Functions

template<bool IsOutFloat, bool IsUnityMul, typename T>
static void outputScanline (const float *ip, T *op, int l, const int Clamp, const float OutMul)
 Scanline output function.
 
template<typename Tb, typename Tl>
static void reallocBuf (Tb *&buf, Tl &len, const Tl newlen)
 Typed buffer reallocation function.
 
template<typename Tb, typename Tl>
static void reallocBuf (Tb *&buf0, Tb *&buf, Tl &len, Tl newlen)
 Typed buffer reallocation function, with address alignment.
 
static int roundclamp (const float v, const int Clamp)
 Function rounds a value and applies clamping.
 
template<typename T>
static void copyScanline1v (const T *ip, const size_t ipinc, float *op, int cc, int repl, int repr)
 Scanline copying function, for vertical resizing.
 
template<typename T>
static void copyScanline2v (const T *ip, const size_t ipinc, float *op, int cc, int repl, int repr)
 
template<typename T>
static void copyScanline3v (const T *ip, const size_t ipinc, float *op, int cc, int repl, int repr)
 
template<typename T>
static void copyScanline4v (const T *ip, const size_t ipinc, float *op, int cc, int repl, int repr)
 
static void padScanline1h (float *op, CResizeScanline &rs, const int l)
 Scanline padding function, for horizontal resizing.
 
static void padScanline2h (float *op, CResizeScanline &rs, const int l)
 
static void padScanline3h (float *op, CResizeScanline &rs, const int l)
 
static void padScanline4h (float *op, CResizeScanline &rs, const int l)
 
template<bool UseSP>
static void resize1 (const float *const sp, float *op, const size_t opinc, const CResizePos *rp, const int kl, const int DstLen)
 Function performs scanline resizing. Variants for 1-4-channel images.
 
template<bool UseSP>
static void resize2 (const float *const sp, float *op, const size_t opinc, const CResizePos *rp, const int kl, const int DstLen)
 
template<bool UseSP>
static void resize3 (const float *const sp, float *op, const size_t opinc, const CResizePos *rp, const int kl, const int DstLen)
 
template<bool UseSP>
static void resize4 (const float *const sp, float *op, const size_t opinc, const CResizePos *rp, const int kl, const int DstLen)
 

Protected Attributes

float * FltBuf
 Address-aligned FltBuf0.
 
float * FltBuf0
 Intermediate resizing buffer.
 
size_t FltBuf0Len
 Length of FltBuf0.
 
CResizeFilters rfh0
 Resizing filters for horizontal resizing (may not be in use).
 
CResizeFilters rfv
 Resizing filters for vertical resizing.
 
CResizeScanline rsh
 Horizontal resize scanline.
 
CResizeScanline rsv
 Vertical resize scanline.
 
float * spv
 Address-aligned spv0.
 
float * spv0
 Scanline buffer for vertical resizing, also used at the output stage.
 
int spv0len
 Length of spv0.
 

Detailed Description

LANCIR image resizer class.

The object of this class can be used to resize 1-4 channel images to any required size. Resizing is performed by utilizing Lanczos filters, with 8-bit precision. This class offers a kind of "optimal" Lanczos resampling implementation.

Object of this class can be allocated on stack.

Note that object of this class does not free temporary buffers and variables after the resizeImage() function call (until object's destruction): these buffers are reused (or reallocated) on subsequent calls, thus making batch resizing of images faster. This means resizing is not thread-safe: a separate CLancIR object should be created for each thread.

Member Function Documentation

◆ copyScanline1v()

template<typename T>
static void avir::CLancIR::copyScanline1v ( const T * ip,
const size_t ipinc,
float * op,
int cc,
int repl,
int repr )
staticprotected

Scanline copying function, for vertical resizing.

Function copies scanline (fully or partially) from the source buffer, in its native format, to the internal scanline buffer, in preparation for vertical resizing. Variants for 1-4-channel images.

Parameters
ipSource scanline buffer pointer.
ipincip increment per pixel.
opOutput scanline pointer.
ccSource pixel copy count.
replLeftmost pixel's replication count.
reprRightmost pixel's replication count.
Template Parameters
TSource buffer's element type.

◆ outputScanline()

template<bool IsOutFloat, bool IsUnityMul, typename T>
static void avir::CLancIR::outputScanline ( const float * ip,
T * op,
int l,
const int Clamp,
const float OutMul )
staticprotected

Scanline output function.

Function performs output of the scanline pixels to the destination image buffer, with type conversion, scaling, clamping, if necessary.

Parameters
[in]ipInput (resized) scanline. Pointer must be aligned to LANCIR_ALIGN bytes.
[out]opOutput image buffer. Must be different to ip.
lOutput scanline's length, in elements (not pixel count).
ClampClamp high level, used if IsOutFloat is false.
OutMulOutput multiplier, for value range conversion, applied before clamping.
Template Parameters
IsOutFloattrue if floating-point output, and no clamping is necessary.
IsUnityMultrue if multiplication is optional. However, even if this parameter was specified as true, OutMul must be 1.
TOutput buffer's element type. Acquired implicitly.

◆ padScanline1h()

static void avir::CLancIR::padScanline1h ( float * op,
CResizeScanline & rs,
const int l )
staticprotected

Scanline padding function, for horizontal resizing.

Function pads the specified scanline buffer to the left and right by replicating its first and last available pixels, in preparation for horizontal resizing. Variants for 1-4-channel images.

Parameters
[in,out]opScanline buffer to pad.
rsScanline resizing positions object.
lSource scanline's length, in pixels.

◆ reallocBuf() [1/2]

template<typename Tb, typename Tl>
static void avir::CLancIR::reallocBuf ( Tb *& buf,
Tl & len,
const Tl newlen )
staticprotected

Typed buffer reallocation function.

Function reallocates a typed buffer if its current length is smaller than the required length.

Parameters
bufReference to the pointer of the previously allocated buffer; address alignment will not be applied.
lenThe current length of the buf0.
newlenA new required length.
Template Parameters
TbBuffer element type.
TlLength variable type.

◆ reallocBuf() [2/2]

template<typename Tb, typename Tl>
static void avir::CLancIR::reallocBuf ( Tb *& buf0,
Tb *& buf,
Tl & len,
Tl newlen )
staticprotected

Typed buffer reallocation function, with address alignment.

Function reallocates a typed buffer if its current length is smaller than the required length, applies LANCIR_ALIGN address alignment to the buffer pointer.

Parameters
buf0Reference to the pointer of the previously allocated buffer.
bufReference to address-aligned buf0 pointer.
lenThe current length of the buf0.
newlenA new required length.
Template Parameters
TbBuffer element type.
TlLength variable type.

◆ resize1()

template<bool UseSP>
static void avir::CLancIR::resize1 ( const float *const sp,
float * op,
const size_t opinc,
const CResizePos * rp,
const int kl,
const int DstLen )
staticprotected

Function performs scanline resizing. Variants for 1-4-channel images.

Parameters
[in]spSource scanline buffer.
[out]opDestination buffer.
opincop increment.
rpSource scanline offsets and resizing filters.
klFilter kernel's length, in taps (always an even value).
DstLenDestination length, in pixels.
Template Parameters
UseSPtrue if sp pointer should be added to spo.

◆ resizeImage() [1/2]

template<typename Tin, typename Tout>
int avir::CLancIR::resizeImage ( const Tin *const SrcBuf,
const int SrcWidth,
const int SrcHeight,
const int SrcSSize,
Tout *const NewBuf,
const int NewWidth,
const int NewHeight,
const int NewSSize,
const int ElCount,
const double kx0 = 0.0,
const double ky0 = 0.0,
double ox = 0.0,
double oy = 0.0 )

Legacy image resizing function.

Not recommended for new projects. See the prior resizeImage() function and CLancIRParams class for details.

Parameters
[in]SrcBufSource image buffer.
SrcWidthSource image width, in pixels.
SrcHeightSource image height, in pixels.
SrcSSizePhysical size of the source scanline, in elements (not bytes).
[out]NewBufBuffer to accept the resized image. Cannot be equal to SrcBuf.
NewWidthNew image width, in pixels.
NewHeightNew image height, in pixels.
NewSSizePhysical size of the destination scanline, in elements (not bytes).
ElCountThe number of elements (channels) used to store each source and destination pixel (1-4).
kx0Resizing step - horizontal.
ky0Resizing step - vertical. Same as kx0.
oxStart X pixel offset within the source image.
oyStart Y pixel offset within the source image.
Template Parameters
TinInput buffer's element type.
ToutOutput buffer's element type.
Returns
The number of available output scanlines. Equals to NewHeight, or 0 on function parameters error.

◆ resizeImage() [2/2]

template<typename Tin, typename Tout>
int avir::CLancIR::resizeImage ( const Tin *const SrcBuf,
const int SrcWidth,
const int SrcHeight,
Tout *const NewBuf,
const int NewWidth,
const int NewHeight,
const int ElCount,
const CLancIRParams *const aParams = NULL )

Function resizes an image.

Performs input-to-output type conversion, if necessary.

Parameters
[in]SrcBufSource image buffer.
SrcWidthSource image width, in pixels.
SrcHeightSource image height, in pixels.
[out]NewBufBuffer to accept the resized image. Cannot be equal to SrcBuf.
NewWidthNew image width, in pixels.
NewHeightNew image height, in pixels.
ElCountThe number of elements (channels) used to store each source and destination pixel (1-4).
Template Parameters
TinInput buffer's element type. Can be uint8_t (0-255 value range), uint16_t (0-65535 value range), float (0-1 value range), double (0-1 value range). uint32_t type is treated as uint16_t. Signed integer types and larger integer types are unsupported.
ToutOutput buffer's element type, treated like Tin. If Tin and Tout types do not match, an output value scaling will be applied. Floating-point output will not be clamped/clipped/saturated, integer output is always rounded and clamped.
Returns
The number of available output scanlines. Equals to NewHeight, or 0 on function parameters error.

◆ roundclamp()

static int avir::CLancIR::roundclamp ( const float v,
const int Clamp )
staticprotected

Function rounds a value and applies clamping.

Parameters
vValue to round and clamp.
ClampHigh clamp level; low level is 0.
Returns
Rounded and clamped value.