Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from developmentseed/new-hsl-2-rgb

New hsl 2 rgb conversion
  • Loading branch information...
commit 5abbc035ea9d279c05f586bc287a23b8a008ffed 2 parents f22972b + bc24407
@miccolis miccolis authored
View
36 lib/tint.js
@@ -15,24 +15,24 @@ if (!Buffer) {
function hsl2rgb(h, s, l) {
if (!s) return [l * 255, l * 255, l * 255];
- var v = l <= 0.5 ? l*(1+s) : l+s-l*s;
- if (!v) return [0, 0, 0];
-
- var min = 2*l-v;
- var sv = (v-min)/l
- h = (h % 360) / 60;
- var sextant = h | 0;
- var fract = h-sextant;
- v *= 255;
- min *= 255;
- switch (sextant) {
- case 0: return [Math.round(v), Math.round(min+v*sv*fract), Math.round(min)];
- case 1: return [Math.round(v-v*sv*fract), Math.round(v), Math.round(min)];
- case 2: return [Math.round(min), Math.round(v), Math.round(min+v*sv*fract)];
- case 3: return [Math.round(min), Math.round(v-v*sv*fract), Math.round(v)];
- case 4: return [Math.round(min+v*sv*fract), Math.round(min), Math.round(v)];
- case 5: return [Math.round(v), Math.round(min), Math.round(v-v*sv*fract)];
- }
+ var m1, m2, r, g, b;
+ h = h / 360;
+
+ var hueToRGB = function (m1, m2, h) {
+ h = (h + 1) % 1;
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
+ if (h * 2 < 1) return m2;
+ if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
+ return m1;
+ };
+
+ m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
+ m1 = l * 2 - m2;
+ return [
+ hueToRGB(m1, m2, h + 0.33333) * 255,
+ hueToRGB(m1, m2, h) * 255,
+ hueToRGB(m1, m2, h - 0.33333) * 255
+ ];
}
var tables = {};
View
BIN  test/tinted/marketst_60_100.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/marketst_60_100_1.0_0.0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/marketst_60_60_0.8_0.2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_20_100.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_20_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_20_50_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_20_50_0_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_270_50_0.5_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_270_50_1_0.5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  test/tinted/sydney_90_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.