code: function getBadRuns(length) {
      var badRuns = 0;
      var i;
  
      for (i = 0; i <= length; i++) {
        if (badBuffer[i] >= 5) {
          badRuns += N1 + badBuffer[i] - 5;
        }
      }
  
      // FBFFFBF as in finder.
      for (i = 3; i < length - 1; i += 2) {
        if (badBuffer[i - 2] === badBuffer[i + 2] &&
            badBuffer[i + 2] === badBuffer[i - 1] &&
            badBuffer[i - 1] === badBuffer[i + 1] &&
            badBuffer[i - 1] * 3 === badBuffer[i] &&
            // Background around the foreground pattern? Not part of the specs.
            (badBuffer[i - 3] === 0 || i + 3 > length ||
             badBuffer[i - 3] * 3 >= badBuffer[i] * 4 ||
             badBuffer[i + 3] * 3 >= badBuffer[i] * 4)) {
          badRuns += N3;
        }
      }
  
      return badRuns;
    }
docs: Using the table for the length of each run, calculate the amount of bad image. Long runs or those that look like finders are called twice; once for X and Y.