|
| 1 | +diff --git a/color.module b/color.module |
| 2 | +index 8a8aa5e..2a1c638 100644 |
| 3 | +--- a/color.module |
| 4 | ++++ b/color.module |
| 5 | +@@ -543,7 +543,7 @@ function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) { |
| 6 | + } |
| 7 | + // Not a pre-set color. Extrapolate from the base. |
| 8 | + else { |
| 9 | +- $chunk = _color_shift($palette[$base], $default[$base], $chunk, $info['blend_target']); |
| 10 | ++ $chunk = _color_shift(($palette[$base] ?? 0), ($default[$base] ?? 0), ($chunk ?? 0), ($info['blend_target'] ?? 0)) ; |
| 11 | + } |
| 12 | + } |
| 13 | + else { |
| 14 | +@@ -695,14 +695,14 @@ function _color_shift($given, $ref1, $ref2, $target) { |
| 15 | + $numerator = 0; |
| 16 | + $denominator = 0; |
| 17 | + for ($i = 0; $i < 3; ++$i) { |
| 18 | +- $numerator += ($ref2[$i] - $ref1[$i]) * ($ref2[$i] - $ref1[$i]); |
| 19 | +- $denominator += ($target[$i] - $ref1[$i]) * ($target[$i] - $ref1[$i]); |
| 20 | ++ $numerator += (($ref2[$i] ?? 0) - ($ref1[$i] ?? 0)) * (($ref2[$i] ?? 0) - ($ref1[$i] ?? 0)); |
| 21 | ++ $denominator += (($target[$i] ?? 0) - ($ref1[$i] ?? 0)) * (($target[$i] ?? 0) - ($ref1[$i] ?? 0)); |
| 22 | + } |
| 23 | + $delta = ($denominator > 0) ? (1 - sqrt($numerator / $denominator)) : 0; |
| 24 | + |
| 25 | + // Calculate the color that ref2 would be if the assumption was true. |
| 26 | + for ($i = 0; $i < 3; ++$i) { |
| 27 | +- $ref3[$i] = $target[$i] + ($ref1[$i] - $target[$i]) * $delta; |
| 28 | ++ $ref3[$i] = ($target[$i] ?? 0) + (($ref1[$i] ?? 0) - ($target[$i] ??0)) * ($delta ?? 0); |
| 29 | + } |
| 30 | + |
| 31 | + // If the assumption is not true, there is a difference between ref2 and ref3. |
| 32 | +@@ -716,7 +716,7 @@ function _color_shift($given, $ref1, $ref2, $target) { |
| 33 | + // Take the given color, and blend it towards the target. |
| 34 | + $given = _color_unpack($given, TRUE); |
| 35 | + for ($i = 0; $i < 3; ++$i) { |
| 36 | +- $result[$i] = $target[$i] + ($given[$i] - $target[$i]) * $delta; |
| 37 | ++ $result[$i] = ($target[$i] ?? 0) + (($given[$i] ?? 0) - ($target[$i] ?? 0)) * ($delta ?? 0); |
| 38 | + } |
| 39 | + |
| 40 | + // Finally, we apply the extra shift in HSL space. |
| 41 | +@@ -757,15 +757,17 @@ function _color_blend($img, $hex1, $hex2, $alpha) { |
| 42 | + * Converts a hex color into an RGB triplet. |
| 43 | + */ |
| 44 | + function _color_unpack($hex, $normalize = FALSE) { |
| 45 | +- $hex = substr($hex, 1); |
| 46 | +- if (strlen($hex) == 3) { |
| 47 | +- $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 48 | +- } |
| 49 | +- $c = hexdec($hex); |
| 50 | +- for ($i = 16; $i >= 0; $i -= 8) { |
| 51 | +- $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1); |
| 52 | ++ $out = array(); |
| 53 | ++ if (!empty($hex)) { |
| 54 | ++ $hex = substr($hex, 1); |
| 55 | ++ if (strlen($hex) == 3) { |
| 56 | ++ $hex = ($hex[0] ?? 0) . ($hex[0] ?? 0) . ($hex[1] ?? 0) . ($hex[1] ?? 0). ($hex[2] ?? 0) . ($hex[2] ?? 0); |
| 57 | ++ } |
| 58 | ++ $c = hexdec($hex); |
| 59 | ++ for ($i = 16; $i >= 0; $i -= 8) { |
| 60 | ++ $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1); |
| 61 | ++ } |
| 62 | + } |
| 63 | +- |
| 64 | + return $out; |
| 65 | + } |
| 66 | + |
0 commit comments