protected static function GdGaussianBlur::ucharClamp in Image Effects 8
Same name and namespace in other branches
- 8.3 src/Component/GdGaussianBlur.php \Drupal\image_effects\Component\GdGaussianBlur::ucharClamp()
- 8.2 src/Component/GdGaussianBlur.php \Drupal\image_effects\Component\GdGaussianBlur::ucharClamp()
Convert a double to an unsigned char.
Round to the nearest integer and clamp the result between 0 and max. The absolute value of $clr must be less than the maximum value of an unsigned short. Casting a negative float to an unsigned short is undefined. However, casting a float to a signed truncates toward zero and casting a negative signed value to an unsigned of the same size results in a bit-identical value (assuming twos-complement arithmetic). This is what we want: all legal negative values for $clr will be greater than 255.
Parameters
float $clr: The float to be converted.
int $max: The maximum value.
Return value
int The converted value.
1 call to GdGaussianBlur::ucharClamp()
- GdGaussianBlur::applyCoeffsLine in src/
Component/ GdGaussianBlur.php - Applies the Gaussian coefficients to a line of the destination image.
File
- src/
Component/ GdGaussianBlur.php, line 178
Class
- GdGaussianBlur
- Gaussian Blur helper methods for GD.
Namespace
Drupal\image_effects\ComponentCode
protected static function ucharClamp($clr, $max) {
// Convert and clamp.
$result = (int) ($clr + 0.5);
if ($result > $max) {
$result = $clr < 0 ? 0 : $max;
}
return $result;
}