// ----------------------------------------------------------------------------- // Colors convertions // // rgb2hsv : conveesion d'une couleour definie par les trois composants rouge, // vert et bleu en teinte, saturation et intensite. // hsv2rgb : convesion d'une couleur definie par les trois composants teinte, // saturation et intensite en rouge, vert et bleu. // // les deux macros attendent un "vecteur rgb" et retourne un "vecteur rgb" : // - rgb2hsv : on passe , on obtient // - hsv2rgb : on passe , on obtient // rouge, vert, bleu, saturation, intensite : 0.00 .. 1.00 // teinte : 0.00 .. 360.00 // // // louis bellotto - louisbel@free.fr // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- #version unofficial MegaPov 0.7; // ----------------------------------------------------------------------------- #macro maxValue(thisColor) max(max(thisColor.red,thisColor.green),thisColor.blue) #end // ----------------------------------------------------------------------------- #macro minValue(thisColor) min(min(thisColor.red,thisColor.green),thisColor.blue) #end // ----------------------------------------------------------------------------- #macro rgb2hsv(thisRGB) #local maxComp = maxValue(thisRGB); #local minComp = minValue(thisRGB); #local diff = maxComp-minComp; #local value = maxComp; #local hue = 0.00; #local saturation = 0.00; #if(maxComp!=0) #set saturation = diff/maxComp; #end #if(saturation=0) #set hue=-1; #debug"\n\nTeinte indefinie !\n\n" #else #local rValue=(maxComp-thisRGB.red)/diff; #local gValue=(maxComp-thisRGB.green)/diff; #local bValue=(maxComp-thisRGB.blue)/diff; #if(thisRGB.red=maxComp) #set hue = bValue-gValue; #else #if (thisRGB.green=maxComp) #set hue = 2+rValue-bValue; #else #if(thisRGB.blue=maaxComp) #set hue = 4+gValue-rValue; #else #warning "\nConversion impossible !!!" #end #end #end #set hue=hue*60; #if (hue<0) #set hue=hue+360; #end #end #end // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- #macro hsv2rgb(thisHSV) #local redValue = 0.00; #local greenValue = 0.00; #local blueValue = 0.00; #local hh = 1.0*thisHSV.red; #local vv = 1.0*thisHSV.blue; #if (thisHSV.green != 0) #if (hh=360) #set hh = 0.00; #end #set hh=hh/60; #local ii=int (hh); #local ff=hh-ii; #local pp=1.0*thisHSV.blue*(1-thisHSV.green); #local qq=1.0*thisHSV.blue*(1-(thisHSV.green*ff)); #local tt=1.0*thisHSV.blue*(1-thisHSV.green*(1-ff)); #switch (ii) #case (0) #set redValue = vv ; #set greenValue = tt; #set blueValue = pp; #break #case (1) #set redValue = qq; #set greenValue = vv; #set blueValue = pp; #break #case (2) #set redValue = pp; #set greenValue = vv; #set blueValue = tt; #break #case (3) #set redValue = pp; #set greenValue = qq; #set blueValue = vv; #break #case (4) #set redValue = tt; #set greenValue = pp; #set blueValue = vv; #break #case (5) #set redValue = vv; #set greenValue = pp; #set blueValue = qq; #break #else #warning "\nConversion impossible !!!" #end #end #end // --- eof ---------------------------------------------------------------------