| Total Complexity | 4 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Color |
||
| 9 | { |
||
| 10 | const COMPONENTS = [ |
||
| 11 | Imagick::COLOR_RED, |
||
| 12 | Imagick::COLOR_GREEN, |
||
| 13 | Imagick::COLOR_BLUE, |
||
| 14 | Imagick::COLOR_ALPHA |
||
| 15 | ]; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * TODO: this black bit magic is probably optimizable |
||
| 19 | * |
||
| 20 | * @param ImagickPixel $pixel |
||
| 21 | * @return int |
||
| 22 | */ |
||
| 23 | public static function get(ImagickPixel $pixel) |
||
| 24 | { |
||
| 25 | $color = 0; |
||
| 26 | for ($i = 0; $i < 4; $i++) { |
||
| 27 | $component = $pixel->getColorValue(self::COMPONENTS[$i]); |
||
| 28 | $component = ((int) ($component * 0xFF)) & 0xFF; |
||
| 29 | $color |= $component << ((3 - $i) * 8); |
||
| 30 | } |
||
| 31 | return $color; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param ImagickPixel $pixel |
||
| 36 | * @param int $color |
||
| 37 | */ |
||
| 38 | public static function set(ImagickPixel $pixel, $color) |
||
| 43 | } |
||
| 44 | } |
||
| 46 |