Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
honghu91 committed Oct 17, 2013
1 parent 83a4eb2 commit 5e31c8d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
35 changes: 28 additions & 7 deletions alloyimage/combined/alloyimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ try{
switch(spaceName){
case "Filter":
case "Alteration":

actName == 'selectableColor' && console.log(imgData);
return this.lib[spaceName][actName].process(imgData, args);
//break;

Expand Down Expand Up @@ -3069,6 +3071,7 @@ window.AlloyImage = $AI = window.psLib;
/**
* @author: Bin Wang
* @description: 可选颜色
* @参考:http://wenku.baidu.com/view/e32d41ea856a561252d36f0b.html
*
*/
;(function(Ps){
Expand All @@ -3087,7 +3090,7 @@ window.AlloyImage = $AI = window.psLib;
var K = arg[4];

//是否相对
var isRelative = arg[5] || 1;
var isRelative = arg[5] || 0;

var maxColorMap = {
red: "R",
Expand Down Expand Up @@ -3148,16 +3151,34 @@ window.AlloyImage = $AI = window.psLib;

for(var i = 0; i < 3; i ++){
//可减少到的量
var lowLimit = colorArr[i] - ~~ (limit * (colorArr[i] / 255));
var lowLimitDelta = ~~ (limit * (colorArr[i] / 255));
var lowLimit = colorArr[i] - lowLimitDelta;

//可增加到的量
var upLimit = colorArr[i] + ~~ (limit * (1 - colorArr[i] / 255));
var upLimitDelta = ~~ (limit * (1 - colorArr[i] / 255));
var upLimit = colorArr[i] + upLimitDelta;

//相对调节
if(isRelative){
//如果分量大于128 减少量=增加量
if(colorArr[i] > 128){
lowLimitDelta = upLimitDelta;
}

//> 0表明在减少
if(alterNum[i] > 0){
var realUpLimit = colorArr[i] - alterNum[i] * lowLimitDelta;
}else{
var realUpLimit = colorArr[i] - alterNum[i] * upLimitDelta;
}
}else{

//现在量
var realUpLimit = limit * - alterNum[i] + colorArr[i];
//现在量
var realUpLimit = limit * - alterNum[i] + colorArr[i];

if(realUpLimit > upLimit) realUpLimit = upLimit;
if(realUpLimit < lowLimit) realUpLimit = lowLimit;
if(realUpLimit > upLimit) realUpLimit = upLimit;
if(realUpLimit < lowLimit) realUpLimit = lowLimit;
}

resultArr[i] = realUpLimit;
}
Expand Down
2 changes: 2 additions & 0 deletions alloyimage/src/alloyimage.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ try{
switch(spaceName){
case "Filter":
case "Alteration":

actName == 'selectableColor' && console.log(imgData);
return this.lib[spaceName][actName].process(imgData, args);
//break;

Expand Down
36 changes: 27 additions & 9 deletions alloyimage/src/module/alteration/seletableColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var K = arg[4];

//是否相对
var isRelative = arg[5] || 1;
var isRelative = arg[5] || 0;

var maxColorMap = {
red: "R",
Expand Down Expand Up @@ -81,16 +81,34 @@

for(var i = 0; i < 3; i ++){
//可减少到的量
var lowLimit = colorArr[i] - ~~ (limit * (colorArr[i] / 255));
var lowLimitDelta = ~~ (limit * (colorArr[i] / 255));
var lowLimit = colorArr[i] - lowLimitDelta;

//可增加到的量
var upLimit = colorArr[i] + ~~ (limit * (1 - colorArr[i] / 255));

//现在量
var realUpLimit = limit * - alterNum[i] + colorArr[i];

if(realUpLimit > upLimit) realUpLimit = upLimit;
if(realUpLimit < lowLimit) realUpLimit = lowLimit;
var upLimitDelta = ~~ (limit * (1 - colorArr[i] / 255));
var upLimit = colorArr[i] + upLimitDelta;

//相对调节
if(isRelative){
//如果分量大于128 减少量=增加量
if(colorArr[i] > 128){
lowLimitDelta = upLimitDelta;
}

//> 0表明在减少
if(alterNum[i] > 0){
var realUpLimit = colorArr[i] - alterNum[i] * lowLimitDelta;
}else{
var realUpLimit = colorArr[i] - alterNum[i] * upLimitDelta;
}
}else{

//现在量
var realUpLimit = limit * - alterNum[i] + colorArr[i];

if(realUpLimit > upLimit) realUpLimit = upLimit;
if(realUpLimit < lowLimit) realUpLimit = lowLimit;
}

resultArr[i] = realUpLimit;
}
Expand Down
8 changes: 6 additions & 2 deletions alloyimage/test/testSeletableColor.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
<div style="height: 100px;background: rgb(186, 130, 166);"></div>
<script type="text/javascript" src="../combined/alloyimage.js"></script>
<script type="text/javascript">
var red = $AI(100, 200, "rgb(186, 130, 166)").show();
var img = new Image();
img.src = "../res/img/10.jpg";
img.onload = function(){
var red = $AI(this);

//red.act("可选颜色", "red", 0.27, - 0.51, - 0.65).show();
red.act("可选颜色", "blue", -1, 0.91, 0.62, 0, 0).show();
};
</script>
</body>
</html>

0 comments on commit 5e31c8d

Please sign in to comment.