色を選択できるJavaScript(HSB)があります。しかし、私のフラッシュ要素では、HUE の計算が間違っています。
例: 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;
}
}