ColorMatrixFilter--color matrix filter

ColorMatrixFilter--The color matrix filter (flash.filters.ColorMatrixFilter) gives you finer control over the particle level. ColorMatrixFilter is a multidimensional matrix (array of 20 elements) with 4 rows and 5 columns. Figure 1 is the matrix equivalent to ColorMatrixFilter:

Figure 1. Matrix equivalent to ColorMatrixFilter

    The values ​​of the red, green, and blue channels are determined by the calculation method shown below:
    CODE:

 

redResult   = a[0] * srcR + a[1] * srcG + a[2] * srcB + a[3] * srcA + a[4]
greenResult = a[5] * srcR + a[6] * srcG + a[7] * srcB + a[8] * srcA + a[9]
blueResult  = a[10] * srcR + a[11] * srcG + a[12] * srcB + a[13] * srcA + a[14]
alphaResult = a[15] * srcR + a[16] * srcG + a[17] * srcB + a[18] * srcA + a[19]

    It can be seen that the value of the first row determines the red value, the second row determines the green value, the third row is blue, and the fourth row is the transparency (Alpha) channel value. It can also be seen that the first four column values ​​are the product of the red, green, blue, and alpha channel values, while the fifth column value is the sum (offset), respectively. Note that the source and result values ​​for each row are in the range 0 to 255. So even if the value of each channel is less than 0 or greater than 255, it will be forced into this range. Let me give some examples to illustrate how it works.  If you want to add 100 (offset) to the red channel, set a[4] to 100, as shown in Figure 2:
   

 

Figure 2. Red value increases by 100

    If you want to double the green channel, set a[6] to 2, as shown in Figure 3:

Figure 3. Green doubling

    If you want to make the amount of blue in the resulting image equal to the amount of red in the original image, set a[10] to 1 and a[12] to 0, as shown in Figure 4:

Figure 4. Red determines blue value

    To change the brightness of an image, you need to change the value in each color channel by the same amount. The easiest way is to set the same offset on each channel. A positive offset increases the brightness and a negative offset decreases the brightness. Figure 5 is an example of increasing brightness:

Figure 5. Increase Brightness

    You can also change the brightness proportionally by multiplying each color channel by a value, greater than 1 increases the brightness and less than 1 decreases the brightness.
In principle, to convert an image to grayscale, you need to make the parts of each channel equal. Since there are three channels, you can multiply each channel by 0.33 and add them to get the resulting value. Figure 6:

Figure 6. Grayscale image matrix

    Due to the relative screen luminosity of the different color channels, however, there do have special "luminance factor" values ​​that provide a more realistic grayscale image. For example, create a solid green block in Photoshop and place it on a solid blue block, then grayscale the image, you will see that the gray in the original green area will be brighter than the original blue area.
    To use these matrices in Flash, create an instance of ColorMatrixFilter and add it to a MovieClip instance. Here is an example of doubling the green color:
    CODE:

 

import flash.filters.ColorMatrixFilter;
var mat:Array = [ 1,0,0,0,0,
                  0,2,0,0,0,
                  0,0,1,0,0,
                  0,0,0,1,0 ];
var colorMat:ColorMatrixFilter = new ColorMatrixFilter(mat);
mc.filters = [colorMat];

 

    ColorMatrixFilter works with a known matrix, and you can perform complex color adjustments in addition to brightness and grayscale. Adjust Contrast, Saturation and Hue etc.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326174126&siteId=291194637