Passed
Push — dev ( e9cf15...64faf7 )
by Fike
03:26
created

Color   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A blend() 0 15 2
1
<?php
2
3
namespace AmaTeam\Image\Projection\Image\Utility;
4
5
class Color
6
{
7
    /**
8
     * @param int $target
9
     * @param int $source
10
     * @return int
11
     */
12
    public static function blend($target, $source)
13
    {
14
        $targetAlpha = $target & 0xFF;
15
        $sourceAlpha = $source & 0xFF;
16
        $influence = $sourceAlpha / $targetAlpha;
17
        $result = ((int) ($targetAlpha + (255 - $targetAlpha) * ($sourceAlpha / 255))) & 0xFF;
18
        for ($i = 3; $i >= 1; $i--) {
19
            $shift = $i * 8;
20
            $targetColor = ($target >> $shift) & 0xFF;
21
            $sourceColor = ($source >> $shift) & 0xFF;
22
            $difference = $sourceColor - $targetColor;
23
            $color = $targetColor + $difference * $influence;
24
            $result |= (((int) $color) & 0xFF) << $shift;
25
        }
26
        return $result;
27
    }
28
}
29