DC.php 602 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Util\Blurhash;
  3. final class DC {
  4. public static function encode(array $value): int {
  5. $rounded_r = Color::tosRGB($value[0]);
  6. $rounded_g = Color::tosRGB($value[1]);
  7. $rounded_b = Color::tosRGB($value[2]);
  8. return ($rounded_r << 16) + ($rounded_g << 8) + $rounded_b;
  9. }
  10. public static function decode(int $value): array {
  11. $r = $value >> 16;
  12. $g = ($value >> 8) & 255;
  13. $b = $value & 255;
  14. return [
  15. Color::toLinear($r),
  16. Color::toLinear($g),
  17. Color::toLinear($b)
  18. ];
  19. }
  20. }