常用ColorMatrixFilter收集(flex)

黑白

0.3086, 0.6094, 0.0820, 0, 0
0.3086, 0.6094, 0.0820, 0, 0
0.3086, 0.6094, 0.0820, 0, 0
0    , 0    , 0    , 1, 0

 

对比度(N取值为0到10)
N,0,0,0,128*(1-N)
0,N,0,0,128*(1-N)
0,0,N,0,128*(1-N)
0,0,0,1,0

 

亮度(N取值为-255到255)  注:一般取值为-100到100(这里是PS中的取值宽度)
1,0,0,0,N
0,1,0,0,N
0,0,1,0,N
0,0,0,1,0

 

颜色反相
-1,  0,  0, 0, 255
0 , -1,  0, 0, 255
0 ,  0, -1, 0, 255
0 ,  0,  0, 1,   0

 

阈值(N取值为-255到255)
0.3086*256,0.6094*256,0.0820*256,0,-256*N
0.3086*256,0.6094*256,0.0820*256,0,-256*N
0.3086*256,0.6094*256,0.0820*256,0,-256*N
0, 0, 0, 1, 0

 

色彩饱和度(N取值为0到255)  注:一般取值为0到100(这里是PS中的取值宽度)
0.3086*(1-N)+ N, 0.6094*(1-N)    , 0.0820*(1-N)    , 0, 0
0.3086*(1-N)   , 0.6094*(1-N) + N, 0.0820*(1-N)    , 0, 0
0.3086*(1-N)   , 0.6094*(1-N)    , 0.0820*(1-N) + N, 0, 0
0        , 0        , 0        , 1, 0

 

设置颜色通道(RGB均为0-2,A为0-1)
R,0,0,0,0
0,G,0,0,0
0,0,B,0,0
0,0,0,A,0

 

as代码:

 

//亮度(-100-100)

public function adjustBrightness(p_val:Number):void {

p_val = cleanValue(p_val,100);

if (p_val == 0 || isNaN(p_val)) { return; }

multiplyMatrix([

1,0,0,0,p_val,

0,1,0,0,p_val,

0,0,1,0,p_val,

0,0,0,1,0

]);

}

 

//对比度(-100-100)

public function adjustContrast(p_val:Number):void {

p_val = cleanValue(p_val,100);

if (p_val == 0 || isNaN(p_val)) { return; }

var x:Number;

if (p_val<0) {

x = 127+p_val/100*127

} else {

x = p_val%1;

if (x == 0) {

x = DELTA_INDEX[p_val];

} else {

//x = DELTA_INDEX[(p_val<<0)]; // this is how the IDE does it.

x = DELTA_INDEX[(p_val<<0)]*(1-x)+DELTA_INDEX[(p_val<<0)+1]*x; // use linear interpolation for more granularity.

}

x = x*127+127;

}

multiplyMatrix([

x/127,0,0,0,0.5*(127-x),

0,x/127,0,0,0.5*(127-x),

0,0,x/127,0,0.5*(127-x),

0,0,0,1,0

]);

}

 

//饱和度(-100-100)

public function adjustSaturation(p_val:Number):void {

p_val = cleanValue(p_val,100);

if (p_val == 0 || isNaN(p_val)) { return; }

var x:Number = 1+((p_val > 0) ? 3*p_val/100 : p_val/100);

var lumR:Number = 0.3086;

var lumG:Number = 0.6094;

var lumB:Number = 0.0820;

multiplyMatrix([

lumR*(1-x)+x,lumG*(1-x),lumB*(1-x),0,0,

lumR*(1-x),lumG*(1-x)+x,lumB*(1-x),0,0,

lumR*(1-x),lumG*(1-x),lumB*(1-x)+x,0,0,

0,0,0,1,0

]);

}

 

//色调(-180-180)

public function adjustHue(p_val:Number):void {

p_val = cleanValue(p_val,180)/180*Math.PI;

if (p_val == 0 || isNaN(p_val)) { return; }

var cosVal:Number = Math.cos(p_val);

var sinVal:Number = Math.sin(p_val);

var lumR:Number = 0.213;

var lumG:Number = 0.715;

var lumB:Number = 0.072;

multiplyMatrix([

lumR+cosVal*(1-lumR)+sinVal*(-lumR),lumG+cosVal*(-lumG)+sinVal*(-lumG),lumB+cosVal*(-lumB)+sinVal*(1-lumB),0,0,

lumR+cosVal*(-lumR)+sinVal*(0.143),lumG+cosVal*(1-lumG)+sinVal*(0.140),lumB+cosVal*(-lumB)+sinVal*(-0.283),0,0,

lumR+cosVal*(-lumR)+sinVal*(-(1-lumR)),lumG+cosVal*(-lumG)+sinVal*(lumG),lumB+cosVal*(1-lumB)+sinVal*(lumB),0,0,

0,0,0,1,0

]);

}

 

// multiplies one matrix against another:

protected function multiplyMatrix(p_matrix:Array):void {

var col:Array = [];

for (var i:uint=0;i<5;i++) {

for (var j:uint=0;j<5;j++) {

col[j] = this[j+i*5];

}

for (j=0;j<5;j++) {

var val:Number=0;

for (var k:Number=0;k<5;k++) {

val += p_matrix[j+k*5]*col[k];

}

this[j+i*5] = val;

}

}

}

// make sure values are within the specified range, hue has a limit of 180, others are 100:

protected function cleanValue(p_val:Number,p_limit:Number):Number {

return Math.min(p_limit,Math.max(-p_limit,p_val));

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值