Skip to content

Commit

Permalink
Add kornrunner/blurhash
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Oct 19, 2023
1 parent e6c45c6 commit 4427fef
Show file tree
Hide file tree
Showing 29 changed files with 629 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"guzzlehttp/guzzle": "^7.5.0",
"icewind/searchdav": "^3.0",
"icewind/streams": "^0.7.7",
"kornrunner/blurhash": "^1.2",
"laravel/serializable-closure": "^1.2.2",
"mexitek/phpcolors": "^1.0",
"microsoft/azure-storage-blob": "^1.5.4",
Expand Down
50 changes: 49 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions composer/InstalledVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static function getRawData()
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
Expand Down Expand Up @@ -341,7 +341,7 @@ private static function getInstalled()
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
Expand Down
2 changes: 0 additions & 2 deletions composer/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Copyright (c) Nils Adermann, Jordi Boggiano

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -18,4 +17,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

5 changes: 5 additions & 0 deletions composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3439,6 +3439,11 @@
'cweagans\\Composer\\PatchEvent' => $vendorDir . '/cweagans/composer-patches/src/PatchEvent.php',
'cweagans\\Composer\\PatchEvents' => $vendorDir . '/cweagans/composer-patches/src/PatchEvents.php',
'cweagans\\Composer\\Patches' => $vendorDir . '/cweagans/composer-patches/src/Patches.php',
'kornrunner\\Blurhash\\AC' => $vendorDir . '/kornrunner/blurhash/src/AC.php',
'kornrunner\\Blurhash\\Base83' => $vendorDir . '/kornrunner/blurhash/src/Base83.php',
'kornrunner\\Blurhash\\Blurhash' => $vendorDir . '/kornrunner/blurhash/src/Blurhash.php',
'kornrunner\\Blurhash\\Color' => $vendorDir . '/kornrunner/blurhash/src/Color.php',
'kornrunner\\Blurhash\\DC' => $vendorDir . '/kornrunner/blurhash/src/DC.php',
'libphonenumber\\CountryCodeSource' => $vendorDir . '/giggsey/libphonenumber-for-php-lite/src/CountryCodeSource.php',
'libphonenumber\\CountryCodeToRegionCodeMap' => $vendorDir . '/giggsey/libphonenumber-for-php-lite/src/CountryCodeToRegionCodeMap.php',
'libphonenumber\\CountryCodeToRegionCodeMapForTesting' => $vendorDir . '/giggsey/libphonenumber-for-php-lite/src/CountryCodeToRegionCodeMapForTesting.php',
Expand Down
1 change: 1 addition & 0 deletions composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
'ownCloud\\TarStreamer\\' => array($vendorDir . '/deepdiver1975/tarstreamer/src'),
'libphonenumber\\' => array($vendorDir . '/giggsey/libphonenumber-for-php-lite/src'),
'kornrunner\\Blurhash\\' => array($vendorDir . '/kornrunner/blurhash/src'),
'cweagans\\Composer\\' => array($vendorDir . '/cweagans/composer-patches/src'),
'bantu\\IniGetWrapper\\' => array($vendorDir . '/bantu/ini-get-wrapper/src'),
'ZipStreamer\\' => array($vendorDir . '/deepdiver/zipstreamer/src'),
Expand Down
13 changes: 13 additions & 0 deletions composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652
array (
'libphonenumber\\' => 15,
),
'k' =>
array (
'kornrunner\\Blurhash\\' => 20,
),
'c' =>
array (
'cweagans\\Composer\\' => 18,
Expand Down Expand Up @@ -304,6 +308,10 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652
array (
0 => __DIR__ . '/..' . '/giggsey/libphonenumber-for-php-lite/src',
),
'kornrunner\\Blurhash\\' =>
array (
0 => __DIR__ . '/..' . '/kornrunner/blurhash/src',
),
'cweagans\\Composer\\' =>
array (
0 => __DIR__ . '/..' . '/cweagans/composer-patches/src',
Expand Down Expand Up @@ -4103,6 +4111,11 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652
'cweagans\\Composer\\PatchEvent' => __DIR__ . '/..' . '/cweagans/composer-patches/src/PatchEvent.php',
'cweagans\\Composer\\PatchEvents' => __DIR__ . '/..' . '/cweagans/composer-patches/src/PatchEvents.php',
'cweagans\\Composer\\Patches' => __DIR__ . '/..' . '/cweagans/composer-patches/src/Patches.php',
'kornrunner\\Blurhash\\AC' => __DIR__ . '/..' . '/kornrunner/blurhash/src/AC.php',
'kornrunner\\Blurhash\\Base83' => __DIR__ . '/..' . '/kornrunner/blurhash/src/Base83.php',
'kornrunner\\Blurhash\\Blurhash' => __DIR__ . '/..' . '/kornrunner/blurhash/src/Blurhash.php',
'kornrunner\\Blurhash\\Color' => __DIR__ . '/..' . '/kornrunner/blurhash/src/Color.php',
'kornrunner\\Blurhash\\DC' => __DIR__ . '/..' . '/kornrunner/blurhash/src/DC.php',
'libphonenumber\\CountryCodeSource' => __DIR__ . '/..' . '/giggsey/libphonenumber-for-php-lite/src/CountryCodeSource.php',
'libphonenumber\\CountryCodeToRegionCodeMap' => __DIR__ . '/..' . '/giggsey/libphonenumber-for-php-lite/src/CountryCodeToRegionCodeMap.php',
'libphonenumber\\CountryCodeToRegionCodeMapForTesting' => __DIR__ . '/..' . '/giggsey/libphonenumber-for-php-lite/src/CountryCodeToRegionCodeMapForTesting.php',
Expand Down
51 changes: 51 additions & 0 deletions composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,57 @@
},
"install-path": "../justinrainbow/json-schema"
},
{
"name": "kornrunner/blurhash",
"version": "v1.2.2",
"version_normalized": "1.2.2.0",
"source": {
"type": "git",
"url": "https://github.com/kornrunner/php-blurhash.git",
"reference": "bc8a4596cb0a49874f0158696a382ab3933fefe4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kornrunner/php-blurhash/zipball/bc8a4596cb0a49874f0158696a382ab3933fefe4",
"reference": "bc8a4596cb0a49874f0158696a382ab3933fefe4",
"shasum": ""
},
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"ext-gd": "*",
"ocramius/package-versions": "^1.4|^2.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9",
"vimeo/psalm": "^4.3"
},
"time": "2022-07-13T19:38:39+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"kornrunner\\Blurhash\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Boris Momčilović",
"email": "boris.momcilovic@gmail.com"
}
],
"description": "Pure PHP implementation of Blurhash",
"homepage": "https://github.com/kornrunner/php-blurhash",
"support": {
"issues": "https://github.com/kornrunner/php-blurhash/issues",
"source": "https://github.com/kornrunner/php-blurhash.git"
},
"install-path": "../kornrunner/blurhash"
},
{
"name": "laravel/serializable-closure",
"version": "v1.2.2",
Expand Down
13 changes: 11 additions & 2 deletions composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'nextcloud/3rdparty',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '6e16075d122c7582527e2be7e365775f0b8e5f0c',
'reference' => 'e6c45c6c0d4f92ffec621446fcc3b34584772b13',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand Down Expand Up @@ -235,6 +235,15 @@
'aliases' => array(),
'dev_requirement' => false,
),
'kornrunner/blurhash' => array(
'pretty_version' => 'v1.2.2',
'version' => '1.2.2.0',
'reference' => 'bc8a4596cb0a49874f0158696a382ab3933fefe4',
'type' => 'library',
'install_path' => __DIR__ . '/../kornrunner/blurhash',
'aliases' => array(),
'dev_requirement' => false,
),
'laravel/serializable-closure' => array(
'pretty_version' => 'v1.2.2',
'version' => '1.2.2.0',
Expand Down Expand Up @@ -310,7 +319,7 @@
'nextcloud/3rdparty' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '6e16075d122c7582527e2be7e365775f0b8e5f0c',
'reference' => 'e6c45c6c0d4f92ffec621446fcc3b34584772b13',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand Down
3 changes: 3 additions & 0 deletions kornrunner/blurhash/.coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: build/logs/clover.xml
json_path: coveralls-upload.json
21 changes: 21 additions & 0 deletions kornrunner/blurhash/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Boris Momčilović

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions kornrunner/blurhash/infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection.log"
},
"mutators": {
"@default": true
}
}
34 changes: 34 additions & 0 deletions kornrunner/blurhash/src/AC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace kornrunner\Blurhash;

final class AC {

public static function encode(array $value, float $max_value): float {
$quant_r = static::quantise($value[0] / $max_value);
$quant_g = static::quantise($value[1] / $max_value);
$quant_b = static::quantise($value[2] / $max_value);
return $quant_r * 19 * 19 + $quant_g * 19 + $quant_b;
}

public static function decode(int $value, float $max_value): array {
$quant_r = intdiv($value, 19 * 19);
$quant_g = intdiv($value, 19) % 19;
$quant_b = $value % 19;

return [
static::signPow(($quant_r - 9) / 9, 2) * $max_value,
static::signPow(($quant_g - 9) / 9, 2) * $max_value,
static::signPow(($quant_b - 9) / 9, 2) * $max_value
];
}

private static function quantise(float $value): float {
return floor(max(0, min(18, floor(static::signPow($value, 0.5) * 9 + 9.5))));
}

private static function signPow(float $base, float $exp): float {
$sign = $base <=> 0;
return $sign * pow(abs($base), $exp);
}
}
39 changes: 39 additions & 0 deletions kornrunner/blurhash/src/Base83.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace kornrunner\Blurhash;

use InvalidArgumentException;

class Base83 {
private const ALPHABET = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '#', '$', '%', '*', '+', ',', '-', '.',
':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~'
];

private const BASE = 83;

public static function encode(int $value, int $length): string {
if (intdiv($value, self::BASE ** $length) != 0) {
throw new InvalidArgumentException('Specified length is too short to encode given value.');
}

$result = '';
for ($i = 1; $i <= $length; $i++) {
$digit = intdiv($value, self::BASE ** ($length - $i)) % self::BASE;
$result .= self::ALPHABET[$digit];
}
return $result;
}

public static function decode(string $hash): int {
$result = 0;
foreach (str_split($hash) as $char) {
$result = $result * self::BASE + (int) array_search($char, self::ALPHABET, true);
}
return $result;
}
}
Loading

0 comments on commit 4427fef

Please sign in to comment.