< Previous | Contents | Next >

Using Methods

local img = InImg:GetValue(req)

image

m:Scale(0.5, 0.5, 0.5)

m = ColorMatrix()

The ColorMatrix and ColorMatrixFull objects expose several methods that can make common operations much simpler. For example, we can use the Scale function to simplify the Gain example in the section above.



The advantage to this approach is that the Scale method takes care of preserving the existing transformations applied to the Matrix. Our original example would have overwritten any existing transformations.

image

local m = ColorMatrixFull()

m:Offset(r, g, b, a)

Using a similar technique, the Offset method can be used to perform a brightness operation.



You can combine operations by simply applying them in turn.


local m = ColorMatrixFull()

m:Offset(-0.5, -0.5, -0.5, 0)

m:Scale(1, 0.5, 0.25, 1)


m:Offset(0.5, 0.5, 0.5, 0)



You can also combine the operations in separate matrices by multiplying them together.


local m1 = ColorMatrixFull()

m1:Offset(-0.5,

-0.5,

-0.5,

0)

local m2 = ColorMatrixFull()

m2:Scale(1, 0.5, 0.25, 1)


local m = m1 * m2



You can find a complete list of the methods available at the ColorMatrix and ColorMatrixFull object reference pages.