|
|
On 11/23/2016 1:59 AM, Mike Horvath wrote:
> I have the following three functions:
>
> #declare correctRGB_R = function(R,G,B) {min(max(R,0),1)}
> #declare correctRGB_G = function(R,G,B) {min(max(G,0),1)}
> #declare correctRGB_B = function(R,G,B) {min(max(B,0),1)}
>
> They each process input and output one component of an R,G,B color vector.
>
> However, instead of the above, I want the entire vector discarded if
> *any* of R, G or B is less than zero or greater than one.
>
> I'm not sure how to form the select statement. What is the best way to
> do this?
>
> Mike
Here is the code I came up with:
// utility
#declare selectRGBa = function(C,D) {select(C,0,D)}
#declare selectRGBb = function(C,D) {select(C-1,D,D,0)}
// input R: between 0 and 1
// input G: between 0 and 1
// input B: between 0 and 1
// output R: between 0 and 1
// output G: between 0 and 1
// output B: between 0 and 1
#declare correctRGBa1 = function(R,G,B)
{selectRGBa(R,selectRGBa(G,selectRGBa(B,R)))}
#declare correctRGBa2 = function(R,G,B)
{selectRGBa(R,selectRGBa(G,selectRGBa(B,G)))}
#declare correctRGBa3 = function(R,G,B)
{selectRGBa(R,selectRGBa(G,selectRGBa(B,B)))}
#declare correctRGBb1 = function(R,G,B)
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa1(R,G,B))))}
#declare correctRGBb2 = function(R,G,B)
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa2(R,G,B))))}
#declare correctRGBb3 = function(R,G,B)
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa3(R,G,B))))}
The selectRGBa and selectRGBb functions are new helper functions.
Mike
Post a reply to this message
|
|