ColorLUT class

An Effect that replaces the value of each colour channel through a lookup table.

A lookup table (LUT) has 256 entries, one for each possible value of a channel. The pixel value v becomes the table entry number v. The effect has one table for blue, green, red and alpha, so it can express any curve, inversion or posterisation of a channel. The class mirrors the GDI+ ColorLUT class and inherits the members of Effect.

Creating

Syntax: fx = ColorLUT( )

Syntax: fx = ColorLUT( params )

Syntax: fx = ColorLUT( lutB, lutG, lutR, lutA )

Each form is also available as New ColorLUT( … ) with the same arguments.

params
required A ColorLUTParams for the parameters.
lutB, lutG, lutR, lutA
required Arrays of 256 Byte values, any lower bound: the tables for blue, green, red and alpha. An array of another length leaves the tables unchanged.

A constructor that fails creates an unusable object whose LastResult tells why.

Parameters

Syntax: fx.Parameters [ = params ]

Syntax: params = fx.Parameters( size )

Gets or sets the ColorLUTParams.

Dim user As GdiPlusUser = GdiPlusUser()

Dim tables As ColorLUTParams
Dim i As Long
For i = 0 To 255
    tables.lutB.b(i) = 255 - i              ' invert blue
    tables.lutG.b(i) = i
    tables.lutR.b(i) = i
    tables.lutA.b(i) = i
Next

Dim fx As ColorLUT = ColorLUT()
fx.Parameters = tables
Dim p As ColorLUTParams = fx.Parameters(LenB(Of ColorLUTParams))
Debug.Print fx.LastResult & " " & p.lutB.b(10) & " " & p.lutG.b(10) & " " & p.lutA.b(10)
' Output:
' 0 245 10 10

Example

The example inverts the blue channel and leaves the others alone.

Dim user As GdiPlusUser = GdiPlusUser()

Dim bmp As Bitmap = Bitmap(4!, 4!)
Graphics(bmp).Clear(Color(255, 200, 100, 50))

Dim tables As ColorLUTParams
Dim i As Long
For i = 0 To 255
    tables.lutB.b(i) = 255 - i
    tables.lutG.b(i) = i
    tables.lutR.b(i) = i
    tables.lutA.b(i) = i
Next

Dim fx As ColorLUT = ColorLUT()
fx.Parameters = tables

Debug.Print bmp.ApplyEffect(fx, GpRect(0, 0, 4, 4))
Debug.Print Hex$(bmp.Pixel(1, 1).argb)
' Output:
' 0
' FFC864CD

See Also