Blitz3D+ Command Reference

TFormFilter enable

Parameters

enable - 1 turns bilinear filtering on (default at startup); 0 turns it off

Description

Turns bilinear filtering on or off for the image-transform commands.

When an image is reshaped by RotateImage, ScaleImage, ResizeImage or TFormImage, the new pixels have to be sampled from the old ones. With filtering on (the default) each pixel blends the surrounding pixels, giving smooth edges and gradients; with it off the nearest pixel is copied, which is faster and keeps hard pixel-art edges - but rotations look jagged.

The switch is global: it applies to every transform command run after it, so you can turn it off for crisp pixel art, or around a batch of transforms you need fast, and back on for smooth ones. It has no effect on ordinary drawing or on DrawImage itself - only on commands that rebuild an image's pixels.

One gotcha with masked images: filtering blends edge pixels with their surroundings, which can smear a fringe of the mask colour around transparent edges. If rotated sprites grow a halo, try TFormFilter 0.

See also: RotateImage, ScaleImage, ResizeImage, TFormImage.

Example

; TFormFilter Example
; -------------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; A detailed photo shows the filtering difference clearly
logo=LoadImage("media/b3dlogo.jpg")

; Rotate around the image's centre
MidHandle logo

filter=1
angle#=0

While Not KeyDown(1)

    Cls

    ; Space toggles bilinear filtering for image transforms
    If KeyHit(57) Then filter=1-filter

    ; TFormFilter affects the NEXT RotateImage/TFormImage calls
    TFormFilter filter

    ; Rotate a fresh copy each frame so the source stays clean
    angle=angle+1
    tmp=CopyImage(logo)
    RotateImage tmp,angle
    DrawImage tmp,320,260
    FreeImage tmp

    Color 255,255,255
    Text 0,0,"Space: toggle filtering   Esc: exit"
    If filter Then
        Text 0,20,"TFormFilter 1 - smooth (bilinear filtered) edges"
    Else
        Text 0,20,"TFormFilter 0 - fast but jagged edges"
    EndIf

    Flip

Wend

End

Index