1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Util/Blurhash/Color.php

19 lines
559 B
PHP
Raw Normal View History

2020-12-05 07:16:27 +00:00
<?php
namespace App\Util\Blurhash;
final class Color {
public static function toLinear(int $value): float {
$value = $value / 255;
return ($value <= 0.04045)
? $value / 12.92
: pow(($value + 0.055) / 1.055, 2.4);
}
public static function tosRGB(float $value): int {
$normalized = max(0, min(1, $value));
return ($normalized <= 0.0031308)
? (int) round($normalized * 12.92 * 255 + 0.5)
: (int) round((1.055 * pow($normalized, 1 / 2.4) - 0.055) * 255 + 0.5);
}
}