[SNIPPET] HEX to RGBA / RGBA to HEX

Code:
:hex_to_r_g_b_a 
//call @hex_to_r_g_b_a 1 color 0xC0FF01FF to R 0@ G 1@ B 2@ A 3@
0B15: 1@ = 0@ 24
0B10: 1@ = 1@ 0xFF
0B15: 2@ = 0@ 16
0B10: 2@ = 2@ 0xFF
0B15: 3@ = 0@ 8
0B10: 3@ = 3@ 0xFF
0B10: 4@ = 0@ 0xFF
0ab2: ret 4 1@ 2@ 3@ 4@

Code:
:r_g_b_a_to_hex
//call @r_g_b_a_to_hex 4 R 1@ G 2@ B 3@ A 4@ to_color 5@
0B16: 5@ = 0@ 24
0B10: 0@ = 5@ 0xFF000000
0B16: 6@ = 1@ 16
0B10: 1@ = 6@ 0x00FF0000
0B16: 7@ = 2@ 8
0B10: 2@ = 7@ 0x0000FF00
0B10: 8@ = 3@ 0x000000FF
005A: 5@ += 6@
005A: 5@ += 7@
005a: 5@ += 8@
0AB2: ret 1 5@
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,117
Solutions
5
Reaction score
882
Location
Lithuania
PHP:
:Hex_To_ARGB_Float
/*
    Convert Hex to float with max range 1.0
    0AB1: @Hex_To_ARGB_Float 1 HexColor 0@ _Returned: A 1@ R 2@ G 3@ B 4@
*/
0B15: 1@ = 0@ 24
0B10: 1@ = 1@ 0xFF
0B15: 2@ = 0@ 16
0B10: 2@ = 2@ 0xFF
0B15: 3@ = 0@ 8
0B10: 3@ = 3@ 0xFF
0B10: 4@ = 0@ 0xFF
0093: 1@ = integer 1@ to_float
1@ /= 255.0 // Normalize INT
0093: 2@ = integer 2@ to_float
2@ /= 255.0 // Normalize INT
0093: 3@ = integer 3@ to_float
3@ /= 255.0 // Normalize INT
0093: 4@ = integer 4@ to_float
4@ /= 255.0 // Normalize INT
0AB2: ret 4 1@ 2@ 3@ 4@
 
Top