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 . | |
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.
|
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.
ip | Source scanline buffer pointer. |
ipinc | ip increment per pixel. |
op | Output scanline pointer. |
cc | Source pixel copy count. |
repl | Leftmost pixel's replication count. |
repr | Rightmost pixel's replication count. |
T | Source buffer's element type. |
|
staticprotected |
Scanline output function.
Function performs output of the scanline pixels to the destination image buffer, with type conversion, scaling, clamping, if necessary.
[in] | ip | Input (resized) scanline. Pointer must be aligned to LANCIR_ALIGN bytes. |
[out] | op | Output image buffer. Must be different to ip . |
l | Output scanline's length, in elements (not pixel count). | |
Clamp | Clamp high level, used if IsOutFloat is false . | |
OutMul | Output multiplier, for value range conversion, applied before clamping. |
IsOutFloat | true if floating-point output, and no clamping is necessary. |
IsUnityMul | true if multiplication is optional. However, even if this parameter was specified as true , OutMul must be 1. |
T | Output buffer's element type. Acquired implicitly. |
|
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.
[in,out] | op | Scanline buffer to pad. |
rs | Scanline resizing positions object. | |
l | Source scanline's length, in pixels. |
|
staticprotected |
Typed buffer reallocation function.
Function reallocates a typed buffer if its current length is smaller than the required length.
buf | Reference to the pointer of the previously allocated buffer; address alignment will not be applied. |
len | The current length of the buf0 . |
newlen | A new required length. |
Tb | Buffer element type. |
Tl | Length variable type. |
|
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.
buf0 | Reference to the pointer of the previously allocated buffer. |
buf | Reference to address-aligned buf0 pointer. |
len | The current length of the buf0 . |
newlen | A new required length. |
Tb | Buffer element type. |
Tl | Length variable type. |
|
staticprotected |
Function performs scanline resizing. Variants for 1-4-channel images.
[in] | sp | Source scanline buffer. |
[out] | op | Destination buffer. |
opinc | op increment. | |
rp | Source scanline offsets and resizing filters. | |
kl | Filter kernel's length, in taps (always an even value). | |
DstLen | Destination length, in pixels. |
UseSP | true if sp pointer should be added to spo . |
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.
[in] | SrcBuf | Source image buffer. |
SrcWidth | Source image width, in pixels. | |
SrcHeight | Source image height, in pixels. | |
SrcSSize | Physical size of the source scanline, in elements (not bytes). | |
[out] | NewBuf | Buffer to accept the resized image. Cannot be equal to SrcBuf. |
NewWidth | New image width, in pixels. | |
NewHeight | New image height, in pixels. | |
NewSSize | Physical size of the destination scanline, in elements (not bytes). | |
ElCount | The number of elements (channels) used to store each source and destination pixel (1-4). | |
kx0 | Resizing step - horizontal. | |
ky0 | Resizing step - vertical. Same as kx0 . | |
ox | Start X pixel offset within the source image. | |
oy | Start Y pixel offset within the source image. |
Tin | Input buffer's element type. |
Tout | Output buffer's element type. |
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.
[in] | SrcBuf | Source image buffer. |
SrcWidth | Source image width, in pixels. | |
SrcHeight | Source image height, in pixels. | |
[out] | NewBuf | Buffer to accept the resized image. Cannot be equal to SrcBuf. |
NewWidth | New image width, in pixels. | |
NewHeight | New image height, in pixels. | |
ElCount | The number of elements (channels) used to store each source and destination pixel (1-4). |
Tin | Input 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. |
Tout | Output 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. |
|
staticprotected |
Function rounds a value and applies clamping.
v | Value to round and clamp. |
Clamp | High clamp level; low level is 0. |