INNER CODE UNIT · JavaScript

RLE_decode

increpare/flickgame · flickgame_base.js:89

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;
      var value = parseInt(encoded[i+1], 16);
      var ch = (value >= 0 && value < 16) ? value.toString(16) : "0";
      for (var j=0;j<count;j++){
        output+=ch;
      }
    }
    while (output.length < limit) output += "0";
    return output;
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…