• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/File/Image/Gd.php
  • Класс: BitrixMainFileImageGd
  • Вызов: Gd::calculatePixel
protected function calculatePixel($mask, $x, $y)
{
	$width = $this->getWidth();
	$height = $this->getHeight();

	$alpha = (imagecolorat($this->resource, $x, $y) >> 24) & 0xFF;
	$newR = $newG = $newB = 0;

	for ($j = 0; $j < 3; ++$j)
	{
		$yv = $y - 1 + $j;
		if ($yv < 0)
		{
			$yv = 0;
		}
		elseif ($yv >= $height)
		{
			$yv = $height - 1;
		}

		for ($i = 0; $i < 3; ++$i)
		{
			$xv = $x - 1 + $i;
			if ($xv < 0)
			{
				$xv = 0;
			}
			elseif ($xv >= $width)
			{
				$xv = $width - 1;
			}

			$m = $mask[$j][$i];
			$rgb = imagecolorat($this->resource, $xv, $yv);

			$newR += (($rgb >> 16) & 0xFF) * $m;
			$newG += (($rgb >> 8) & 0xFF) * $m;
			$newB += ($rgb & 0xFF) * $m;
		}
	}

	$newR = ($newR > 255 ? 255 : ($newR < 0 ? 0 : $newR));
	$newG = ($newG > 255 ? 255 : ($newG < 0 ? 0 : $newG));
	$newB = ($newB > 255 ? 255 : ($newB < 0 ? 0 : $newB));

	return imagecolorallocatealpha($this->resource, $newR, $newG, $newB, $alpha);
}