2012-10-13 25 views
1

我有一個JavaScript可以選擇顏色(HSB)。但在我的閃光元素中,HUE計算錯誤。PixelBlender錯誤的色調。閃光/動作

我有這樣的輸入: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; 
} 
} 

回答

0

IIRC原始着色器版本中使用-180到180的色調參數,你最有可能低於-1您的結核病某些色調,這是下落不明,在此着色器。將其更改爲-180至180,默認值爲0,並觀看樂趣。