我有一个可以选择颜色(HSB)的javascript。但在我的闪光元素中,色调计算错误。
我有这个输入例如: HUE: 360... SAT: 100..BRIGHTNESS: 97 但闪光灯元素的颜色错误。该怎么办?我正在使用 PixelBlender 更改每个像素的颜色。
这是我的 HUE.PBJ:
<languageVersion : 1.0;>
kernel HSLFilter
<
namespace : "Boostworthy::Filters";
vendor : "Ryan Taylor";
version : 1;
description : "";
>
{
parameter float hue
<
minValue : 0.0;
maxValue : 360.0;
defaultValue : 360.0;
>;
parameter float saturation
<
minValue : 0.0;
maxValue : 100.0;
defaultValue : 0.0;
>;
parameter float lightness
<
minValue : 0.0;
maxValue : 100.0;
defaultValue : 0.0;
>;
input image4 source;
output pixel4 result;
void evaluatePixel()
{
// Convert sampled pixel from RGB space to HSL space.
pixel4 samp;
float sampMin;
float sampMax;
float sampDiff;
float sampSum;
float sampH;
float sampS;
float sampL;
samp = sampleNearest(source, outCoord());
sampMin = min(samp.r, samp.g);
sampMin = min(sampMin, samp.b);
sampMax = max(samp.r, samp.g);
sampMax = max(sampMax, samp.b);
sampDiff = sampMax - sampMin;
sampSum = sampMax + sampMin;
sampL = sampSum * 0.5;
if(sampMin == sampMax)
sampH = 0.0;
else if(sampMax == samp.r)
sampH = mod(60.0 * ((samp.g - samp.b) / sampDiff), 360.0);
else if(sampMax == samp.g)
sampH = 60.0 * ((samp.b - samp.r) / sampDiff) + 120.0;
else if(sampMax == samp.b)
sampH = 60.0 * ((samp.r - samp.g) / sampDiff) + 240.0;
else
sampH = 0.0;
if(sampMin == sampMax)
sampS = 0.0;
else if(sampL > 0.5)
sampS = sampDiff / (2.0 - sampSum);
else
sampS = sampDiff / sampSum;
// Transform the sampled HSL values by the amounts specified
// by the hue, saturation, and lightness parameters.
float outH;
float outS;
float outL;
outH = sampH - hue;
outS = sampS * (saturation / 100.0 + 1.0);
outL = sampL - (1.0 - (lightness / 100.0 + 1.0));
// Convert the transformed HSL values back to RGB space.
float q;
float p;
float h;
if(outL < 0.5)
q = outL * (1.0 + outS);
else
q = outL + outS - outL * outS;
p = 2.0 * outL - q;
h = outH / 360.0;
float oneOverThree = 1.0 / 3.0;
float twoOverThree = 2.0 / 3.0;
float oneOverSix = 1.0 / 6.0;
float3 t = float3(h + oneOverThree, h, h - oneOverThree);
if(t.r < 0.0)
t.r += 1.0;
else if(t.r > 1.0)
t.r -= 1.0;
if(t.g < 0.0)
t.g += 1.0;
else if(t.g > 1.0)
t.g -= 1.0;
if(t.b < 0.0)
t.b += 1.0;
else if(t.b > 1.0)
t.b -= 1.0;
pixel4 c = pixel4(0.0, 0.0, 0.0, samp.a);
if(t.r < oneOverSix)
c.r = p + (q - p) * 6.0 * t.r;
else if(t.r >= oneOverSix && t.r < 0.5)
c.r = q;
else if(t.r >= 0.5 && t.r < twoOverThree)
c.r = p + (q - p) * 6.0 * (twoOverThree - t.r);
else
c.r = p;
if(t.g < oneOverSix)
c.g = p + (q - p) * 6.0 * t.g;
else if(t.g >= oneOverSix && t.g < 0.5)
c.g = q;
else if(t.g >= 0.5 && t.g < twoOverThree)
c.g = p + (q - p) * 6.0 * (twoOverThree - t.g);
else
c.g = p;
if(t.b < oneOverSix)
c.b = p + (q - p) * 6.0 * t.b;
else if(t.b >= oneOverSix && t.b < 0.5)
c.b = q;
else if(t.b >= 0.5 && t.b < twoOverThree)
c.b = p + (q - p) * 6.0 * (twoOverThree - t.b);
else
c.b = p;
// Apply the final ARGB color to the pixel.
result = c;
}
}