Conditions | 5 |
Paths | 7 |
Total Lines | 28 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
42 | public function encode(): string |
||
43 | { |
||
44 | foreach ((new \ImagickPixelIterator($this->image)) as $y => $row) { |
||
45 | $bit = $byte = 0; |
||
46 | |||
47 | /** @var \ImagickPixel[] $row */ |
||
48 | foreach ($row as $x => $pixel) { |
||
49 | $color = $pixel->getColor(); |
||
50 | |||
51 | $value = (int) (($color['r'] + $color['g'] + $color['b']) / 3) >> 7; |
||
52 | |||
53 | $bit = $x % 8; |
||
54 | |||
55 | $byte = ($y * $this->bytesPerRow) + \intdiv($x, 8); |
||
56 | |||
57 | if ($value === 0) { |
||
58 | $this->buffer[$byte] &= ~(1 << (7 - $bit)); |
||
59 | } else { |
||
60 | $this->buffer[$byte] |= (1 << (7 - $bit)); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | if ($bit !== 7) { |
||
65 | $this->buffer[$byte] ^= (1 << (7 - $bit)) - 1; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | return \pack('C*', ...$this->buffer); |
||
70 | } |
||
72 |