1
如何手动计算RGB乘法器和偏移量以调整颜色的亮度,以使-1的参数全部为黑色且1全为白色?AS3:手动计算RGB乘法器和亮度从-1到1的偏移量
如果小于1,很容易。 R,G和B只是乘以(1 +亮度)。
但是,如何计算大于0的亮度值的偏移?
如何手动计算RGB乘法器和偏移量以调整颜色的亮度,以使-1的参数全部为黑色且1全为白色?AS3:手动计算RGB乘法器和亮度从-1到1的偏移量
如果小于1,很容易。 R,G和B只是乘以(1 +亮度)。
但是,如何计算大于0的亮度值的偏移?
这是每通道插值数学的简单通道。它看起来并不简单,仅仅因为有三个通道,并且他们需要用于各种目的的de/serialization。
// Usage.
acoolor:uint = parseRGB(200, 150, 100);
trace(colorToRGB(brightNess(acoolor, 0.5)));
trace(colorToRGB(brightNess(acoolor, -0.5)));
// Implementation.
function parseRGB(ared:uint, agreen:uint, ablue:uint):uint
{
var result:uint;
result += (ared << 16) & 0xFF0000;
result += (agreen << 8) & 0xFF00;
result += (ablue) & 0xFF;
return result;
}
function colorToRGB(acolor:uint):Array
{
result = new Array;
result[0] = (acolor >> 16) & 0xFF;
result[1] = (acolor >> 8) & 0xFF;
result[2] = (acolor) & 0xFF;
return result;
}
function RGBToColor(anrgb:Array):uint
{
return parseRGB.apply(this, anrgb);
}
function brightChannel(achannel:uint, adjust:Number):uint
{
if (adjust <= -1) return 0;
if (adjust >= 1) return 255;
if (adjust < 0) return achannel * (1 + adjust);
if (adjust > 0) return achannel + (255 - achannel) * adjust;
// If adjust == 0
return achannel;
}
function brightNess(acolor:uint, adjust:Number):uint
{
var anrgb:Array = colorToRGB(acolor);
for (var i:int = 0; i < 3; i++)
anrgb[i] = brightChannel(anrgb[i], adjust);
return RGBToColor(anrgb);
}
对于HSB/HSV这是最亮的R,G,B的...对于HSL它的暗和最亮的R,G和B – PrincePolka
的平均您只是想映射平时** 0将255 **的亮度范围转换为** - 1至1 **的范围?这不会引入白化(亮度),因为您必须将亮度映射到** - 1到0 **范围(黑色水平vs原始颜色),并将亮度映射到** 0到1 **范围(原始颜色vs白色水平)。你的最后两行很混乱......我的意思是说,不能说“大于0的值”与前面提到的“如果小于1”是同一个东西,所以你可以计算出来,对吧?另外令人困惑的是_“这很容易,R,G和B只是乘以(1 +亮度)。”_这对红色= 255是如何工作的? –