AVIR
High-quality pro image resizing library
 
Loading...
Searching...
No Matches
avir.h File Reference

The "main" inclusion file with all required classes and functions. More...

#include <cstring>
#include <cmath>
#include <stdint.h>

Go to the source code of this file.

Classes

class  avir::CBuffer< T, capint >
 Memory buffer class for element array storage, with capacity tracking. More...
 
class  avir::CDSPFIREQ
 FIR filter-based equalizer generator. More...
 
class  avir::CDSPFracFilterBankLin< fptype >
 Sinc function-based fractional delay filter bank. More...
 
class  avir::CDSPPeakedCosineLPF
 Low-pass filter windowed by Peaked Cosine window function. More...
 
class  avir::CDSPWindowGenPeakedCosine
 Peaked Cosine window function generator class. More...
 
class  avir::CFltBuffer
 Buffer class for parametrized low-pass filter. More...
 
class  avir::CImageResizer< fpclass >
 Image resizer class. More...
 
class  avir::CImageResizerDithererDefINL< fptype >
 Image resizer's default dithering class. More...
 
class  avir::CImageResizerDithererErrdINL< fptype >
 Image resizer's error-diffusion dithering class, interleaved mode. More...
 
class  avir::CImageResizerFilterStep< fptype, fptypeatom >
 Image resizer's filtering step class. More...
 
class  avir::CImageResizerFilterStepINL< fptype, fptypeatom >
 Interleaved filtering steps implementation class. More...
 
struct  avir::CImageResizerParams
 Resizing algorithm parameters structure. More...
 
struct  avir::CImageResizerParamsDef
 The default set of resizing algorithm parameters (10.06/1.88/1.029(256064.90)/0.000039). More...
 
struct  avir::CImageResizerParamsHigh
 Set of resizing algorithm parameters for low-aliasing resizing (11.59/1.84/1.015(73054.59)/0.000159). More...
 
struct  avir::CImageResizerParamsLow
 Set of resizing algorithm parameters for lower-ringing performance (9.21/1.91/1.040(391960.71)/0.000023). More...
 
struct  avir::CImageResizerParamsLR
 Set of resizing algorithm parameters for low-ringing performance (7.91/1.96/1.065(1980857.66)/0.000004). More...
 
struct  avir::CImageResizerParamsULR
 Set of resizing algorithm parameters for ultra-low-ringing performance (7.50/2.01/1.083(11568559.86)/0.000001). More...
 
struct  avir::CImageResizerParamsUltra
 Set of resizing algorithm parameters for ultra low-aliasing resizing (13.68/1.79/1.000(521792.07)/0.000026). More...
 
class  avir::CImageResizerThreadPool
 Thread pool for multi-threaded image resizing operation. More...
 
class  avir::CImageResizerVars
 Image resizing variables. More...
 
class  avir::CImageResizerVarsBase
 Image resizing variables (base class). More...
 
struct  avir::CImageResizerFilterStep< fptype, fptypeatom >::CResizePos
 Resizing position structure. More...
 
class  avir::CImageResizerFilterStep< fptype, fptypeatom >::CRPosBuf
 Resizing positions buffer class. More...
 
class  avir::CImageResizerFilterStep< fptype, fptypeatom >::CRPosBufArray
 Resizing positions buffer array class. More...
 
class  avir::CSineGen
 Sine signal generator class. More...
 
class  avir::CStructArray< T >
 Array of structured objects. More...
 
class  avir::CImageResizerThreadPool::CWorkload
 Thread pool's workload object class. More...
 
class  avir::fpclass_def< afptype, afptypeatom, adith >
 Floating-point processing definition and abstraction class. More...
 

Macros

#define AVIR_NOCTOR(ClassName)
 Macro that defines empty copy-constructor and copy operator, with the private: prefix.
 
#define AVIR_NULLPTR
 Macro is defined, if nullptr workaround is in use, for pre-C++11 compilers. Undefined at the end of file.
 
#define AVIR_PI   3.1415926535897932
 The macro equals to pi constant, fills 53-bit floating point mantissa. Undefined at the end of file.
 
#define AVIR_PId2   1.5707963267948966
 The macro equals to pi divided by 2 constant, fills 53-bit floating point mantissa. Undefined at the end of file.
 
#define AVIR_RESIZE_PART1
 
#define AVIR_RESIZE_PART1
 
#define AVIR_RESIZE_PART1nx
 
#define AVIR_RESIZE_PART1nx
 
#define AVIR_RESIZE_PART2
 
#define AVIR_RESIZE_PART2
 
#define AVIR_VERSION   "3.1"
 The macro defines AVIR version string.
 
#define nullptr   NULL
 

Functions

template<typename T1, typename T2>
void avir::addArray (const T1 *ip, T2 *op, int l, const int ipinc=1, const int opinc=1)
 Adds values located in array ip, to array op.
 
template<typename T>
void avir::calcFIRFilterResponse (const T *flt, int fltlen, const double th, double &re0, double &im0, const int fltlat=0)
 Calculates frequency response of the specified FIR filter at the specified circular frequency.
 
template<typename T>
avir::clamp (const T &Value, const T minv, const T maxv)
 "Clamps" (clips) the specified value so that it is not lesser than minv, and not greater than maxv.
 
template<typename T>
avir::convertLin2SRGB (const T s)
 Approximately de-linearizes the linear gamma value.
 
template<typename T, typename Tin>
avir::convertSRGB2Lin (const Tin &s0, const T m)
 Approximately linearizes the sRGB gamma value.
 
template<typename T>
avir::convertSRGB2Lin (const unsigned char &s0, const T)
 Approximately linearizes the sRGB gamma value. Fast specialization for uint8_t and unsigned char input.
 
template<typename T1, typename T2>
void avir::copyArray (const T1 *ip, T2 *op, int l, const int ipinc=1, const int opinc=1)
 Converts (via typecast) specified array of type T1 values of length l into array of type T2 values.
 
template<typename T>
void avir::normalizeFIRFilter (T *const p, const int l, const double DCGain, const int pstep=1)
 Normalizes FIR filter so that its frequency response at DC is equal to DCGain.
 
template<typename T>
avir::pow24_sRGB (const T x0)
 Power 2.4 approximation, designed for sRGB gamma correction.
 
template<typename T>
avir::pow24i_sRGB (const T x0)
 Power 1/2.4 approximation function, designed for sRGB gamma correction.
 
template<typename T1, typename T2>
void avir::replicateArray (const T1 *const ip, const int ipl, T2 *op, int l, const int opinc)
 Replicates a set of adjacent elements several times in a row.
 
template<typename T>
avir::round (const T d)
 Rounding function, based on the (int) typecast. Biased result. Not suitable for numbers greater than 2^31 - 1.
 

Detailed Description

The "main" inclusion file with all required classes and functions.

Version
3.1

This is the "main" inclusion file for the "AVIR" image resizer. This inclusion file contains implementation of the AVIR image resizing algorithm in its entirety. Also includes several classes and functions that can be useful elsewhere.

AVIR Copyright (c) 2015-2025 Aleksey Vaneev

Macro Definition Documentation

◆ AVIR_NOCTOR

#define AVIR_NOCTOR ( ClassName)
Value:
private: \
ClassName( const ClassName& ) { } \
ClassName& operator = ( const ClassName& ) { return( *this ); }

Macro that defines empty copy-constructor and copy operator, with the private: prefix.

This macro should be used in classes that cannot be copied in a standard C++ way.

◆ AVIR_RESIZE_PART1 [1/2]

#define AVIR_RESIZE_PART1
Value:
while( rpos < rpose ) \
{ \
const fptype x = (fptype) rpos -> x; \
const fptype* const ftp = rpos -> ftp; \
const fptype* const ftp2 = ftp + IntFltLen; \
const fptype* Src = SrcLine + rpos -> SrcOffs; \
int i;

◆ AVIR_RESIZE_PART1 [2/2]

#define AVIR_RESIZE_PART1
Value:
while( rpos < rpose ) \
{ \
const fptype x = (fptype) rpos -> x; \
const fptype* const ftp = rpos -> ftp; \
const fptype* const ftp2 = ftp + IntFltLen0; \
const fptype* Src = SrcLine + rpos -> SrcOffs; \
const int IntFltLen = rpos -> fl; \
int i;

◆ AVIR_RESIZE_PART1nx [1/2]

#define AVIR_RESIZE_PART1nx
Value:
while( rpos < rpose ) \
{ \
const fptype* const ftp = rpos -> ftp; \
const fptype* Src = SrcLine + rpos -> SrcOffs; \
int i;

◆ AVIR_RESIZE_PART1nx [2/2]

#define AVIR_RESIZE_PART1nx
Value:
while( rpos < rpose ) \
{ \
const fptype* const ftp = rpos -> ftp; \
const fptype* Src = SrcLine + rpos -> SrcOffs; \
const int IntFltLen = rpos -> fl; \
int i;

◆ AVIR_RESIZE_PART2 [1/2]

#define AVIR_RESIZE_PART2
Value:
DstLine += DstLineIncr; \
rpos++; \
}

◆ AVIR_RESIZE_PART2 [2/2]

#define AVIR_RESIZE_PART2
Value:
DstLine += DstLineIncr; \
rpos++; \
}

Function Documentation

◆ addArray()

template<typename T1, typename T2>
void avir::addArray ( const T1 * ip,
T2 * op,
int l,
const int ipinc = 1,
const int opinc = 1 )

Adds values located in array ip, to array op.

Parameters
ipInput buffer.
[out]opOutput buffer.
lThe number of elements to add.
ipincInput buffer pointer increment.
opincOutput buffer pointer increment.

◆ calcFIRFilterResponse()

template<typename T>
void avir::calcFIRFilterResponse ( const T * flt,
int fltlen,
const double th,
double & re0,
double & im0,
const int fltlat = 0 )

Calculates frequency response of the specified FIR filter at the specified circular frequency.

Phase can be calculated as atan2( im, re ). Function uses computationally-efficient oscillators instead of cos() and sin() functions.

Parameters
fltFIR filter's coefficients.
fltlenNumber of coefficients (taps) in the filter.
thCircular frequency, [0; pi].
[out]re0Resulting real part of the complex frequency response.
[out]im0Resulting imaginary part of the complex frequency response.
fltlatFilter's latency in samples (taps).
Template Parameters
TFilter coefficients' type.

◆ clamp()

template<typename T>
T avir::clamp ( const T & Value,
const T minv,
const T maxv )

"Clamps" (clips) the specified value so that it is not lesser than minv, and not greater than maxv.

Parameters
ValueValue to clamp.
minvMinimal allowed value.
maxvMaximal allowed value.
Returns
Clamped value.
Template Parameters
TValue's type.

◆ convertLin2SRGB()

template<typename T>
T avir::convertLin2SRGB ( const T s)

Approximately de-linearizes the linear gamma value.

Parameters
sLinear gamma value, in the range 0 to 1.
Returns
sRGB gamma value, approximated.
Template Parameters
TValue's type.

◆ convertSRGB2Lin() [1/2]

template<typename T, typename Tin>
T avir::convertSRGB2Lin ( const Tin & s0,
const T m )

Approximately linearizes the sRGB gamma value.

Parameters
s0sRGB gamma value, in the range 0 to 1.
mPreliminary multiplier, usually a value equal to input type range.
Returns
Linearized sRGB gamma value, approximated.
Template Parameters
TOutput type.
TinInput value type.

◆ convertSRGB2Lin() [2/2]

template<typename T>
T avir::convertSRGB2Lin ( const unsigned char & s0,
const T  )

Approximately linearizes the sRGB gamma value. Fast specialization for uint8_t and unsigned char input.

Parameters
s0sRGB gamma value, in the range 0 to 255.
Returns
Linearized sRGB gamma value, approximated.
Template Parameters
TOutput type.

◆ copyArray()

template<typename T1, typename T2>
void avir::copyArray ( const T1 * ip,
T2 * op,
int l,
const int ipinc = 1,
const int opinc = 1 )

Converts (via typecast) specified array of type T1 values of length l into array of type T2 values.

If T1 is the same as T2, copy operation is performed. When copying data at overlapping address spaces, op should be lower than ip.

Parameters
ipInput buffer.
[out]opOutput buffer.
lThe number of elements to copy.
ipincInput buffer pointer increment.
opincOutput buffer pointer increment.

◆ normalizeFIRFilter()

template<typename T>
void avir::normalizeFIRFilter ( T *const p,
const int l,
const double DCGain,
const int pstep = 1 )

Normalizes FIR filter so that its frequency response at DC is equal to DCGain.

Parameters
[in,out]pFilter coefficients.
lFilter length.
DCGainFilter's gain at DC.
pstepp array step.
Template Parameters
TFilter coefficients' type.

◆ pow24_sRGB()

template<typename T>
T avir::pow24_sRGB ( const T x0)

Power 2.4 approximation, designed for sRGB gamma correction.

Parameters
x0Argument, in the range 0.09 to 1.
Returns
Value raised into power 2.4, approximate.
Template Parameters
TValue's type.

◆ pow24i_sRGB()

template<typename T>
T avir::pow24i_sRGB ( const T x0)

Power 1/2.4 approximation function, designed for sRGB gamma correction.

Parameters
x0Argument, in the range 0.003 to 1.
Returns
Value raised into power 1/2.4, approximate.
Template Parameters
TValue's type.

◆ replicateArray()

template<typename T1, typename T2>
void avir::replicateArray ( const T1 *const ip,
const int ipl,
T2 * op,
int l,
const int opinc )

Replicates a set of adjacent elements several times in a row.

This operation is usually used to replicate pixels at the start or end of image's scanline.

Parameters
ipSource array.
iplSource array length (usually 1..4, but can be any number).
[out]opDestination buffer.
lNumber of times the source array should be replicated (the destination buffer should be able to hold ipl * l number of elements).
opincDestination buffer position increment after replicating the source array. This value should be equal to at least ipl.

◆ round()

template<typename T>
T avir::round ( const T d)

Rounding function, based on the (int) typecast. Biased result. Not suitable for numbers greater than 2^31 - 1.

Parameters
dValue to round.
Returns
Rounded value. Some bias may be introduced.
Template Parameters
TValue's type.