Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-12-02 13:53:34 +0300
committerCarl Schwan <carl@carlschwan.eu>2021-12-02 13:53:34 +0300
commit324e0dc36ca1781de27fe30453e30c460cc3dfb4 (patch)
tree5a6bf81e94f06922d211759207ab86206c1d47e7 /apps/theming/lib
parentf334d51b1729d9653f0094e8db5f00e30f5d8389 (diff)
Add rgb to hsl converter
This ports away from using now internal functions from scssphp. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r--apps/theming/lib/Util.php45
1 files changed, 41 insertions, 4 deletions
diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php
index 70b5a00f9ea..f18194c3266 100644
--- a/apps/theming/lib/Util.php
+++ b/apps/theming/lib/Util.php
@@ -34,7 +34,6 @@ use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
-use ScssPhp\ScssPhp\Compiler;
class Util {
@@ -97,14 +96,52 @@ class Util {
}
/**
+ * Convert RGB to HSL
+ *
+ * Copied from cssphp, copyright Leaf Corcoran, licensed under MIT
+ *
+ * @param integer $red
+ * @param integer $green
+ * @param integer $blue
+ *
+ * @return array
+ */
+ public function toHSL($red, $green, $blue)
+ {
+ $min = min($red, $green, $blue);
+ $max = max($red, $green, $blue);
+ $l = $min + $max;
+ $d = $max - $min;
+
+ if ((int) $d === 0) {
+ $h = $s = 0;
+ } else {
+ if ($l < 255) {
+ $s = $d / $l;
+ } else {
+ $s = $d / (510 - $l);
+ }
+
+ if ($red == $max) {
+ $h = 60 * ($green - $blue) / $d;
+ } elseif ($green == $max) {
+ $h = 60 * ($blue - $red) / $d + 120;
+ } elseif ($blue == $max) {
+ $h = 60 * ($red - $green) / $d + 240;
+ }
+ }
+
+ return [fmod($h, 360), $s * 100, $l / 5.1];
+ }
+
+ /**
* @param string $color rgb color value
* @return float
*/
public function calculateLuminance($color) {
[$red, $green, $blue] = $this->hexToRGB($color);
- $compiler = new Compiler();
- $hsl = $compiler->toHSL($red, $green, $blue);
- return $hsl[3] / 100;
+ $hsl = $this->toHSL($red, $green, $blue);
+ return $hsl[2] / 100;
}
/**