I had a very very old function I wrote when I first tried to understand
what the heck was that format.
It's packed in that tool:

set cut_paste_input [stack 0]
version 7.0 v8
push $cut_paste_input
NoOp {
 name NoOp1
 selected true
 xpos 23685
 ypos -5343
 addUserKnob {20 User}
 addUserKnob {19 set l "Set color"}
 set {0.03599999845 0.01999999955 0.0120000001 0}
 addUserKnob {22 set_button l Set! -STARTLINE T "rgba =
nuke.thisNode().knob('set').getValue()\nhex=''\nfor value in rgba:\n    hex
+= '%02x' % (value*255)\nweird = int(hex,
16)\n\nnuke.thisNode().knob('tile_color').setValue(weird)\nnuke.thisNode().knob('setval').setValue('Hex:'
+ hex + ' Nuke:' + str(weird))"}
 addUserKnob {26 setval l Result: T "Hex:09050300 Nuke:151323392"}
 addUserKnob {19 get l "Get Color"}
 get {0 0 0 0}
 addUserKnob {22 get_button l Get! -STARTLINE T "weird =
nuke.thisNode().knob('tile_color').getValue()\nhex=  '%08x' % weird\nrgba =
\[float(int(hex\[0:2], 16))/255.0,float(int(hex\[2:4],
16))/255.0,float(int(hex\[4:6], 16))/255.0,float(int(hex\[6:8],
16))/255.0]\n\n\nnuke.thisNode().knob('get').setValue(rgba)\nnuke.thisNode().knob('getval').setValue('Hex:'
+ hex + ' Nuke:' + str(weird))"}
 addUserKnob {26 getval l Result: T "Hex:00000000 Nuke:0.0"}
}

It's not fancy, but the math is quite easy to understand, and it does
return the right color. (See the little part of code in the "Get" button.)

*Erwan* LEROY
www.erwanleroy.com

On Mon, Dec 28, 2015 at 3:44 PM, Ivan Busquets <[email protected]>
wrote:

> Glad to hear!
>
> And... come on!      (0xFF & V >> 24) is pretty self explanatory, isn't
> it? :p
>
> I can't even claim to fully understand it now, though it made sense at the
> time.
> The overall idea is that you're "unpacking" that 32 bit int, 8 bits at a
> time.
>
> So, for RED, you're shifting those 32 bits 24 bits to the right
> (essentially leaving you with the first 8 bits only) , and then multiplying
> (bitwise AND) with an 8-bit white mask (0xFF). I think for the red channel
> you probably wouldn't even need this, as you are already left with only 8
> bits, so probably don't need to mask anything (can't verify right now,
> though)
>
> For GREEN, you're shifting 16 bits, meaning you have discarded the last 16
> (blue and alpha), and you are left with green (first 8 bits) and red. Then
> you multiply this with an 8 bit mask (0xFF), which leaves you with just
> the 8 bits of the green channel (256 possible values), and divide by 255 to
> get it in a 0-1 range.
>
> (same for blue, shifting only 8 bits to the right)
>
> I *think* that's the gist of it, but it's been a while...
>
> Cheers,
> Ivan
>
> On Sun, Dec 27, 2015 at 11:27 PM, Frank Rueter|OHUfx <[email protected]>
> wrote:
>
>> Sweet, thanks Ivan!
>> I won't even try to understand this but it works.
>>
>> frank
>>
>>
>>
>> On 28/12/15 8:25 pm, Ivan Busquets wrote:
>>
>> Hey Frank,
>>
>> Found this buried inside some old backdrop-utilities module. I think it
>> should work for what you're after.
>>
>> def TILEtoRGB(V):
>>
>>     '''
>>
>>     TILEtoRGB(V) -> tuple
>>
>>     Returns a tuple representing Red, Green, and Blue values
>>
>>     in a 0-1 range, from a 32 bit int as returned by the "tile_color"
>> knob.
>>
>>     Keyword arguments:
>>
>>     V -- a 32 bit int as returned by the "tile_color" knob
>>
>>     '''
>>
>>
>>     R = (0xFF & V >> 24) / 255.0
>>
>>     G = (0xFF & V >> 16) / 255.0
>>
>>     B = (0xFF & V >> 8) / 255.0
>>
>>     return R,G,B
>>
>>
>>
>> Hope it helps!
>>
>>
>>
>> On Sun, Dec 27, 2015 at 11:11 PM, Frank Rueter|OHUfx <[email protected]>
>> wrote:
>>
>>> Hi guys,
>>>
>>> after years of begrudgingly having to convert rgb to tile colour
>>> friendly values, I now need to do the opposite, i.e. take a tile color
>>> value and get rgb values from it.
>>>
>>> How do I do that?
>>>
>>> Cheers,
>>> frank
>>>
>>>
>>> --
>>> [image: ohufxLogo 50x50] <http://www.ohufx.com> *vfx compositing
>>> <http://ohufx.com/index.php/vfx-compositing> | workflow customisation and
>>> consulting <http://ohufx.com/index.php/vfx-customising> *
>>>
>>> _______________________________________________
>>> Nuke-python mailing list
>>> [email protected], http://forums.thefoundry.co.uk/
>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>
>>>
>>
>>
>> _______________________________________________
>> Nuke-python mailing [email protected], 
>> http://forums.thefoundry.co.uk/http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>
>>
>> --
>> [image: ohufxLogo 50x50] <http://www.ohufx.com> *vfx compositing
>> <http://ohufx.com/index.php/vfx-compositing> | workflow customisation and
>> consulting <http://ohufx.com/index.php/vfx-customising> *
>>
>> _______________________________________________
>> Nuke-python mailing list
>> [email protected], http://forums.thefoundry.co.uk/
>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>
>>
>
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to