INNER CODE UNIT · JavaScript

contrastTextColor

increpare/flickgame · flickgame_base.js:79

function contrastTextColor(hex) {
    var dw = color_distance(hex, "#ffffff");
    var db = color_distance(hex, "#000000");
    return dw > db ? "#ffffff" : "#000000";
}

// RLE decode function.
// Run counts come straight from an untrusted game file, so targetLength (when given)
// bounds the output and pads it out: an oversized count used to build an enormous
// string and lock the tab up for minutes.
function RLE_decode(encoded, targetLength) {
    if (!encoded || typeof encoded.length !== 'number') encoded = [];
    var limit = (typeof targetLength === 'number' && targetLength >= 0) ? targetLength : Infinity;
    var output = "";
    for (var i=0;i+1<encoded.length && output.length<limit;i+=2) {
      var count = Number(encoded[i]);
      if (!isFinite(count) || count < 1) continue;
      if (count > limit - output.length) count = limit - output.length;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…