Unit BGRAResample

📄 Source code

Description

This unit provides resampling functions, i.e. resizing of bitmaps with or without interpolation filters.

Uses

Overview

Structures

Name Description
Class TCubicKernel Cubic interpolation is very smooth but can be a bit blurry
Class TLanczosKernel Lanczos kernel provides smooth but contrasted interpolation
Class TMitchellKernel Filter that provides smooth interpolation but less blurry than TCubicKernel
Class TSplineKernel Spline kernel provides customizable wide interpolation filter using Coeff property
Class TWideKernelFilter Abstract class to define a wide kernel.

Functions and Procedures

function CreateInterpolator(style: TSplineStyle): TWideKernelFilter;
function DownSample(source: TBGRACustomBitmap; factorX,factorY: integer): TBGRACustomBitmap;
procedure DownSamplePutImage(source: TBGRACustomBitmap; factorX,factorY: integer; dest: TBGRACustomBitmap; OffsetX,OffsetY: Integer; ADrawMode: TDrawMode);
function FineInterpolation(t: single; ResampleFilter: TResampleFilter): single;
function FineInterpolation256(t256: integer; ResampleFilter: TResampleFilter): integer;
function FineResample(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer; ResampleFilter: TResampleFilter): TBGRACustomBitmap;
function SimpleStretch(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer): TBGRACustomBitmap;
procedure StretchPutImage(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer; dest: TBGRACustomBitmap; OffsetX,OffsetY: Integer; ADrawMode: TDrawMode; AOpacity: byte; ANoTransition: boolean = false);
function WideKernelResample(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer; ResampleFilterSmaller, ResampleFilterLarger: TWideKernelFilter): TBGRACustomBitmap;

Description

Functions and Procedures

function CreateInterpolator(style: TSplineStyle): TWideKernelFilter;

Create an instance of a predefined kernel matching spline style

function DownSample(source: TBGRACustomBitmap; factorX,factorY: integer): TBGRACustomBitmap;

Computes a resampled image, downsampling by the provided factorX and factorY

procedure DownSamplePutImage(source: TBGRACustomBitmap; factorX,factorY: integer; dest: TBGRACustomBitmap; OffsetX,OffsetY: Integer; ADrawMode: TDrawMode);

Puts a resampled image on the destination, downsampling by the provided factorX and factorY

function FineInterpolation(t: single; ResampleFilter: TResampleFilter): single;

Computes fine interpolation between 0 and 1 for rfBox, rfLinear, rfHalfCosine and rfCosine filters.

function FineInterpolation256(t256: integer; ResampleFilter: TResampleFilter): integer;

Computes fine interpolation between 0 and 256 for rfBox, rfLinear, rfHalfCosine and rfCosine filters.

function FineResample(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer; ResampleFilter: TResampleFilter): TBGRACustomBitmap;

Uses floating point coordinates to get an antialiased resample.

It can use minimal interpolation (4 pixels when upsizing) for simple interpolation filters (linear and cosine-like) or wide kernel resample for complex interpolation. In this cas, it calls WideKernelResample.

function SimpleStretch(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer): TBGRACustomBitmap;

Computes a resampled image with pixels are boxes, with antialising between boxes. For example, a 2x2 image will be stretched as four boxes, one for each pixel

procedure StretchPutImage(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer; dest: TBGRACustomBitmap; OffsetX,OffsetY: Integer; ADrawMode: TDrawMode; AOpacity: byte; ANoTransition: boolean = false);

Puts a resampled image on the destination. Pixels are boxes, with antialising between boxes.

function WideKernelResample(bmp: TBGRACustomBitmap; NewWidth, NewHeight: integer; ResampleFilterSmaller, ResampleFilterLarger: TWideKernelFilter): TBGRACustomBitmap;

WideKernelResample can be called for custom filter kernel, derived from TWideKernelFilter. It is slower of course than simple interpolation.