Color conversion from RGB to tpt

  • MoffD
    23rd Jul 2015 Member 0 Permalink

    Hi everyone! I'm looking for information/help for what the title says.

     

    Basically, I have a project I hope to release soon that involves filt/bray colors heavily and I was wondering if there's some direct conversion from a RGB hex string to the 30 bit color values that filt/phot/bray/etc... use.

     

    I tried a direct conversion with no luck, and looking at the values for each bit I see there's individual bits for cyan and yellow, so this really has me scratching my head.

     

    This is NOT for any image plotting (I would never post a save like that,) and please don't suggest using anything related to deco. I have no qualms with the deco layer, but it's completely unrelated to what I'm doing with the colors.

    Edited once by MoffD. Last: 23rd Jul 2015
  • MoffD
    23rd Jul 2015 Member 0 Permalink
    Thanks boxmein! I'll get cracking on a converter ;P
  • jacob1
    23rd Jul 2015 Developer 1 Permalink
    What boxmein posted does convert from the PHOT format to RGB format. But, there is no conversion the other way around. PHOT format only supports about 1500 colors (I can't remember exactly), and some things you just can't get close to.

    The format wastes a lot of space, there are 5 areas for different colors (blue, cyan, green, yellow, red?), and it counts how many bits are set and determines the color that way. Well really there are 3 areas for RGB which are 12 long and overlap. Hopefully you understand the code :).

    A lot of times you can get a close approximation to what you want, but you can only adjust hue really, and not brightness.
  • MoffD
    24th Jul 2015 Member 0 Permalink
    I figured that only hue was approximatable, but as long as it's a close color it should be alright. Thanks to both of you for helping and that snippet of code is helpful (it may take me a bit to get a conversion formula though) @jacob1 When you say there are about 1500 colors I assume there's multiple values that equal the same color? (if I did the math right it's 2^30 or 1073741824 possible combinations, right?)
    Edited once by MoffD. Last: 24th Jul 2015
  • jacob1
    24th Jul 2015 Developer 1 Permalink
    @MoffD (View Post)
    yeah, but so many of those are just duplicates. Since it just really counts the number of bits that are on in each section to get the hue. Kind of a waste but maybe that is a bit more realistic to how photons work than just an RGB, idk
  • mniip
    25th Jul 2015 Developer 0 Permalink
    @MoffD (View Post)
    I computed a table of BIZR colors a long time ago: https://gist.github.com/mniip/7146703

    The table of 5 values contains the amount of bits in R, Y, G, C, B components respectively. You can use the following snippet to convert it to a numeric ctype:
    local function nbit(n,d)
    return (2^n-1)*2^d
    end
    local function bizr(r,y,g,c,b)
    return nbit(r,21)+nbit(y,18)+nbit(g,12)+nbit(c,9)+nbit(b,0)
    end
    Edited once by mniip. Last: 25th Jul 2015