POV-Ray : Newsgroups : povray.general : converting rgb to spectra : Re: converting rgb to spectra Server Time
9 Aug 2024 03:22:28 EDT (-0400)
  Re: converting rgb to spectra  
From: Chris Huff
Date: 21 Aug 2000 23:05:08
Message: <chrishuff-87615D.22063021082000@news.povray.org>
In article <39a1d84c@news.povray.org>, "Halbert" <hha### [at] capitalnet> 
wrote:

> Psuedocode plagerized from Computer Graphics and Principals 2nd Edition:
...snip...
> This should be easily converted into a macro (assumming I haven't 
> made too many typing errors.)

Whee, Pascal...the last time I read Pascal I was trying to convert a 
demo program written in it to C. It was surprisingly easy, actually...
Here is an untested attempt at a straight conversion to POV:

#macro RGB2HSV(RGB)
    #local Max = max(RGB.r, max(RGB.g, RGB.b));
    #local Min = min(RGB.r, min(RGB.g, RGB.b));

    #local V = Max;

    #if(Max != 0)
        #local S = (Max - Min)/Max;
    #else
        #local S = 0;
    #end

    #if(S = 0)
        #local H = 0;
    #else
        #local Delta = Max - Min;
        #if(RGB.r = Max)
            #local H = (RGB.g - RGB.b)/Delta;
        #else
            #if(RGB.g = Max)
                #local H = 2 + (RGB.b - RGB.r)/Delta;
            #else
                #if(RGB.b = Max)
                    #local H = 4 + (RGB.r - RGB.g)/Delta;
                #end
            #end
        #end

        #local H = H*60;
        #if(H < 0)
            #local H = H + 360;
        #end
    #end
    (< H, S, V>)
#end

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.