3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertRGBToXY($red, $green, $blue) { // Normalize the values to 1 $normalizedToOne['red'] = $red / 255; $normalizedToOne['green'] = $green / 255; $normalizedToOne['blue'] = $blue / 255; // Make colors more vivid foreach ($normalizedToOne as $key => $normalized) { if ($normalized > 0.04045) { $color[$key] = pow(($normalized + 0.055) / (1.0 + 0.055), 2.4); } else { $color[$key] = $normalized / 12.92; } } // Convert to XYZ using the Wide RGB D65 formula $xyz['x'] = $color['red'] * 0.664511 + $color['green'] * 0.154324 + $color['blue'] * 0.162028; $xyz['y'] = $color['red'] * 0.283881 + $color['green'] * 0.668433 + $color['blue'] * 0.047685; $xyz['z'] = $color['red'] * 0.000000 + $color['green'] * 0.072310 + $color['blue'] * 0.986039; // Calculate the x/y values if (array_sum($xyz) == 0) { $x = 0; $y = 0; } else { $x = $xyz['x'] / array_sum($xyz); $y = $xyz['y'] / array_sum($xyz); } return array( 'x' => $x, 'y' => $y, 'bri' => round($xyz['y'] * 255) ); } function convertXYToRGB($x, $y, $bri = 255) { // Calculate XYZ $z = 1.0 - $x - $y; $xyz['y'] = $bri / 255; $xyz['x'] = ($xyz['y'] / $y) * $x; $xyz['z'] = ($xyz['y'] / $y) * $z; // Convert to RGB using Wide RGB D65 conversion $color['red'] = $xyz['x'] * 1.656492 - $xyz['y'] * 0.354851 - $xyz['z'] * 0.255038; $color['green'] = -$xyz['x'] * 0.707196 + $xyz['y'] * 1.655397 + $xyz['z'] * 0.036152; $color['blue'] = $xyz['x'] * 0.051713 - $xyz['y'] * 0.121364 + $xyz['z'] * 1.011530; foreach ($color as $key => $normalized) { // Apply reverse gamma correction if ($normalized <= 0.0031308) { $color[$key] = 12.92 * $normalized; } else { $color[$key] = (1.0 + 0.055) * pow($normalized, 1.0 / 2.4) - 0.055; } // Scale back from a maximum of 1 to a maximum of 255 $color[$key] = round($color[$key] * 255); } return $color; } print_r($rgb = convertRGBToXY(0, 0, 255)); print_r(convertXYToRGB($rgb['x'], $rgb['y'], 255));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Foc2T
function name:  (null)
number of ops:  20
compiled vars:  !0 = $rgb
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'convertrgbtoxy'
          2        SEND_VAL                                                 0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 255
          5        DO_FCALL                                      0  $1      
          6        ASSIGN                                           ~2      !0, $1
          7        SEND_VAL                                                 ~2
          8        DO_ICALL                                                 
   61     9        INIT_FCALL                                               'print_r'
         10        INIT_FCALL                                               'convertxytorgb'
         11        FETCH_DIM_R                                      ~4      !0, 'x'
         12        SEND_VAL                                                 ~4
         13        FETCH_DIM_R                                      ~5      !0, 'y'
         14        SEND_VAL                                                 ~5
         15        SEND_VAL                                                 255
         16        DO_FCALL                                      0  $6      
         17        SEND_VAR                                                 $6
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Function convertrgbtoxy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 30
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 69
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/Foc2T
function name:  convertRGBToXY
number of ops:  91
compiled vars:  !0 = $red, !1 = $green, !2 = $blue, !3 = $normalizedToOne, !4 = $normalized, !5 = $key, !6 = $color, !7 = $xyz, !8 = $x, !9 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    6     3        DIV                                              ~11     !0, 255
          4        ASSIGN_DIM                                               !3, 'red'
          5        OP_DATA                                                  ~11
    7     6        DIV                                              ~13     !1, 255
          7        ASSIGN_DIM                                               !3, 'green'
          8        OP_DATA                                                  ~13
    8     9        DIV                                              ~15     !2, 255
         10        ASSIGN_DIM                                               !3, 'blue'
         11        OP_DATA                                                  ~15
   10    12      > FE_RESET_R                                       $16     !3, ->30
         13    > > FE_FETCH_R                                       ~17     $16, !4, ->30
         14    >   ASSIGN                                                   !5, ~17
   11    15        IS_SMALLER                                               0.04045, !4
         16      > JMPZ                                                     ~19, ->26
   12    17    >   INIT_FCALL                                               'pow'
         18        ADD                                              ~21     !4, 0.055
         19        DIV                                              ~22     ~21, 1.055
         20        SEND_VAL                                                 ~22
         21        SEND_VAL                                                 2.4
         22        DO_ICALL                                         $23     
         23        ASSIGN_DIM                                               !6, !5
         24        OP_DATA                                                  $23
   11    25      > JMP                                                      ->29
   14    26    >   DIV                                              ~25     !4, 12.92
         27        ASSIGN_DIM                                               !6, !5
         28        OP_DATA                                                  ~25
   10    29    > > JMP                                                      ->13
         30    >   FE_FREE                                                  $16
   18    31        FETCH_DIM_R                                      ~27     !6, 'red'
         32        MUL                                              ~28     ~27, 0.664511
         33        FETCH_DIM_R                                      ~29     !6, 'green'
         34        MUL                                              ~30     ~29, 0.154324
         35        ADD                                              ~31     ~28, ~30
         36        FETCH_DIM_R                                      ~32     !6, 'blue'
         37        MUL                                              ~33     ~32, 0.162028
         38        ADD                                              ~34     ~31, ~33
         39        ASSIGN_DIM                                               !7, 'x'
         40        OP_DATA                                                  ~34
   19    41        FETCH_DIM_R                                      ~36     !6, 'red'
         42        MUL                                              ~37     ~36, 0.283881
         43        FETCH_DIM_R                                      ~38     !6, 'green'
         44        MUL                                              ~39     ~38, 0.668433
         45        ADD                                              ~40     ~37, ~39
         46        FETCH_DIM_R                                      ~41     !6, 'blue'
         47        MUL                                              ~42     ~41, 0.047685
         48        ADD                                              ~43     ~40, ~42
         49        ASSIGN_DIM                                               !7, 'y'
         50        OP_DATA                                                  ~43
   20    51        FETCH_DIM_R                                      ~45     !6, 'red'
         52        MUL                                              ~46     ~45, 0
         53        FETCH_DIM_R                                      ~47     !6, 'green'
         54        MUL                                              ~48     ~47, 0.07231
         55        ADD                                              ~49     ~46, ~48
         56        FETCH_DIM_R                                      ~50     !6, 'blue'
         57        MUL                                              ~51     ~50, 0.986039
         58        ADD                                              ~52     ~49, ~51
         59        ASSIGN_DIM                                               !7, 'z'
         60        OP_DATA                                                  ~52
   22    61        INIT_FCALL                                               'array_sum'
         62        SEND_VAR                                                 !7
         63        DO_ICALL                                         $53     
         64        IS_EQUAL                                                 $53, 0
         65      > JMPZ                                                     ~54, ->69
   23    66    >   ASSIGN                                                   !8, 0
   24    67        ASSIGN                                                   !9, 0
   22    68      > JMP                                                      ->81
   26    69    >   FETCH_DIM_R                                      ~57     !7, 'x'
         70        INIT_FCALL                                               'array_sum'
         71        SEND_VAR                                                 !7
         72        DO_ICALL                                         $58     
         73        DIV                                              ~59     ~57, $58
         74        ASSIGN                                                   !8, ~59
   27    75        FETCH_DIM_R                                      ~61     !7, 'y'
         76        INIT_FCALL                                               'array_sum'
         77        SEND_VAR                                                 !7
         78        DO_ICALL                                         $62     
         79        DIV                                              ~63     ~61, $62
         80        ASSIGN                                                   !9, ~63
   30    81    >   INIT_ARRAY                                       ~65     !8, 'x'
   31    82        ADD_ARRAY_ELEMENT                                ~65     !9, 'y'
   32    83        INIT_FCALL                                               'round'
         84        FETCH_DIM_R                                      ~66     !7, 'y'
         85        MUL                                              ~67     ~66, 255
         86        SEND_VAL                                                 ~67
         87        DO_ICALL                                         $68     
         88        ADD_ARRAY_ELEMENT                                ~65     $68, 'bri'
         89      > RETURN                                                   ~65
   34    90*     > RETURN                                                   null

End of function convertrgbtoxy

Function convertxytorgb:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 51, Position 2 = 75
Branch analysis from position: 51
2 jumps found. (Code = 78) Position 1 = 52, Position 2 = 75
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 59
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
filename:       /in/Foc2T
function name:  convertXYToRGB
number of ops:  78
compiled vars:  !0 = $x, !1 = $y, !2 = $bri, !3 = $z, !4 = $xyz, !5 = $color, !6 = $normalized, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      255
   39     3        SUB                                              ~8      1, !0
          4        SUB                                              ~9      ~8, !1
          5        ASSIGN                                                   !3, ~9
   40     6        DIV                                              ~12     !2, 255
          7        ASSIGN_DIM                                               !4, 'y'
          8        OP_DATA                                                  ~12
   41     9        FETCH_DIM_R                                      ~14     !4, 'y'
         10        DIV                                              ~15     ~14, !1
         11        MUL                                              ~16     !0, ~15
         12        ASSIGN_DIM                                               !4, 'x'
         13        OP_DATA                                                  ~16
   42    14        FETCH_DIM_R                                      ~18     !4, 'y'
         15        DIV                                              ~19     ~18, !1
         16        MUL                                              ~20     !3, ~19
         17        ASSIGN_DIM                                               !4, 'z'
         18        OP_DATA                                                  ~20
   44    19        FETCH_DIM_R                                      ~22     !4, 'x'
         20        MUL                                              ~23     ~22, 1.65649
         21        FETCH_DIM_R                                      ~24     !4, 'y'
         22        MUL                                              ~25     ~24, 0.354851
         23        SUB                                              ~26     ~23, ~25
         24        FETCH_DIM_R                                      ~27     !4, 'z'
         25        MUL                                              ~28     ~27, 0.255038
         26        SUB                                              ~29     ~26, ~28
         27        ASSIGN_DIM                                               !5, 'red'
         28        OP_DATA                                                  ~29
   45    29        FETCH_DIM_R                                      ~31     !4, 'x'
         30        MUL                                              ~32     ~31, -1
         31        MUL                                              ~33     ~32, 0.707196
         32        FETCH_DIM_R                                      ~34     !4, 'y'
         33        MUL                                              ~35     ~34, 1.6554
         34        ADD                                              ~36     ~33, ~35
         35        FETCH_DIM_R                                      ~37     !4, 'z'
         36        MUL                                              ~38     ~37, 0.036152
         37        ADD                                              ~39     ~36, ~38
         38        ASSIGN_DIM                                               !5, 'green'
         39        OP_DATA                                                  ~39
   46    40        FETCH_DIM_R                                      ~41     !4, 'x'
         41        MUL                                              ~42     ~41, 0.051713
         42        FETCH_DIM_R                                      ~43     !4, 'y'
         43        MUL                                              ~44     ~43, 0.121364
         44        SUB                                              ~45     ~42, ~44
         45        FETCH_DIM_R                                      ~46     !4, 'z'
         46        MUL                                              ~47     ~46, 1.01153
         47        ADD                                              ~48     ~45, ~47
         48        ASSIGN_DIM                                               !5, 'blue'
         49        OP_DATA                                                  ~48
   47    50      > FE_RESET_R                                       $49     !5, ->75
         51    > > FE_FETCH_R                                       ~50     $49, !6, ->75
         52    >   ASSIGN                                                   !7, ~50
   49    53        IS_SMALLER_OR_EQUAL                                      !6, 0.0031308
         54      > JMPZ                                                     ~52, ->59
   50    55    >   MUL                                              ~54     !6, 12.92
         56        ASSIGN_DIM                                               !5, !7
         57        OP_DATA                                                  ~54
   49    58      > JMP                                                      ->67
   52    59    >   INIT_FCALL                                               'pow'
         60        SEND_VAR                                                 !6
         61        SEND_VAL                                                 0.416667
         62        DO_ICALL                                         $56     
         63        MUL                                              ~57     $56, 1.055
         64        SUB                                              ~58     ~57, 0.055
         65        ASSIGN_DIM                                               !5, !7
         66        OP_DATA                                                  ~58
   55    67    >   INIT_FCALL                                               'round'
         68        FETCH_DIM_R                                      ~60     !5, !7
         69        MUL                                              ~61     ~60, 255
         70        SEND_VAL                                                 ~61
         71        DO_ICALL                                         $62     
         72        ASSIGN_DIM                                               !5, !7
         73        OP_DATA                                                  $62
   47    74      > JMP                                                      ->51
         75    >   FE_FREE                                                  $49
   57    76      > RETURN                                                   !5
   58    77*     > RETURN                                                   null

End of function convertxytorgb

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.16 ms | 1459 KiB | 19 Q