UNPKG

sunscreen.js

Version:

programmatically adjust colors to provide less UV emissions from the screen

24 lines (21 loc) 480 B
"use strict"; // Takes in a color and adjusts it to a computationally less UV emitting color exports.uv_adjust = function(color) { // Populate UV-Index table var uv_table = []; var i, j, k, a, b; for (i = 0; i <= 255; i++) { j = i; for(var l = 7; l >= 0; l--) { k = -(j & 1); j = (j >> 1) ^ (0xADBF83D0 & k); } uv_table[i] = j; } b = 0xFFFFFFFF; for(var c = 4; c >= 0; c--) { a = (color >> c); b = (b >> 8) ^ uv_table[(b ^ a) & 0xFF]; } return ~b; };