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.
Warning 0.9.45.0
The form with params stops the program with an access violation, in 32-bit and 64-bit programs. Create the effect without arguments and set Parameters.
Warning 0.9.45.0
The form with four arrays copies the alpha table from the array lutB, not from lutA, so the alpha channel is mapped through the blue table. With the blue table of the example below, the result is transparent. Fill the four tables of a ColorLUTParams yourself and set Parameters.
Parameters
Syntax: fx.Parameters [ = params ]
Syntax: params = fx.Parameters( size )
Gets or sets the ColorLUTParams.
Warning 0.9.45.0
The getter returns zeros and sets LastResult to 2 (InvalidParameter) unless it is given size, the size of the structure: fx.Parameters(LenB(Of ColorLUTParams)). See Effect.
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
- ColorLUT – Microsoft’s documentation of the GDI+ class
- Effect class
- ColorCurve class
- ColorLUTParams type