protected function unfilter(ByteArray $ba, $width, $height, $bpp) { $i = 0; for ($y = 0; $y < $height; $y++) { switch ($ba[$i++]) { case 0: $i += $width * $bpp; break; case 1: foreach (range(0, $width * $bpp - 1) as $x) { if ($x - $bpp >= 0) { $ba->offsetSet($i, $ba->offsetGet($i) + $ba->offsetGet($i - $bpp) & 0xff); } $i++; } break; case 2: for ($x = 0; $x < $width * $bpp; $x++) { if ($y > 0) { $ba->offsetSet($i, $ba->offsetGet($i) + $ba->offsetGet($i - $width * $bpp - 1) & 0xff); } $i++; } break; case 3: for ($x = 0; $x < $width * $bpp; $x++) { $left = $x - $bpp >= 0 ? $ba->offsetGet($i - $bpp) : 0; $above = $y - 1 >= 0 ? $ba->offsetGet($i - $width * $bpp - 1) : 0; $ba->offsetSet($i, $ba->offsetGet($i) + floor(($left + $above) / 2) & 0xff); $i++; } break; case 4: for ($x = 0; $x < $width * $bpp; $x++) { $left = $x - $bpp >= 0 ? $ba->offsetGet($i - $bpp) : 0; $above = $y > 0 ? $ba->offsetGet($i - $width * $bpp - 1) : 0; $upper_left = $x - $bpp >= 0 && $y > 0 ? $ba->offsetGet($i - $width * $bpp - 1 - $bpp) : 0; $ba->offsetSet($i, $ba->offsetGet($i) + $this->paethPredictor($left, $above, $upper_left) & 0xff); $i++; } break; default: throw new PNGDecodeException('未知のフィルタです。'); } } }