<commit_before>(function (win) {
  // Options
  var blendColors = true;
  var use3xOriginalImplementation = false;

  const REDMASK = 0x000000FF; // &MASK	>>0
  const GREENMASK = 0x0000FF00; // &MASK	>>8
  const BLUEMASK = 0x00FF0000; // &MASK	>>16
  const ALPHAMASK = 0xFF000000; // &MASK	>>24
  const THRESHHOLD_Y = 48;
  const THRESHHOLD_U = 7;
  const THRESHHOLD_V = 6;

  // Convert an ARGB byte to YUV
  function _getYuv(p) {
    var r = (p & REDMASK);
    var g = (p & GREENMASK) >> 8;
    var b = (p & BLUEMASK) >> 16;
    var y = r * .299000 + g * .587000 + b * .114000;
    var u = r *  - .168736 + g *  - .331264 + b * .500000;
    var v = r * .500000 + g *  - .418688 + b *  - .081312;
    var output = [y, u, v];
	
    return output;
  }

  function _YuvDifference(A, B) {
    var alphaA = (A & ALPHAMASK) >> 24;
    var alphaB = (B & ALPHAMASK) >> 24;
    var yuvA = _getYuv(A);
    var yuvB = _getYuv(B);

    /*Add HQx filters threshold & return*/
    return Math.abs(alphaA - alphaB)
         + Math.abs(yuvA[0] - yuvB[0])
         + Math.abs(yuvA[1] - yuvB[1])
         + Math.abs(yuvA[2] - yuvB[2]);
  }

  function _IsEqual(A, B) {
    return _YuvDifference(A, B) < 155;
  }

  function pixelInterpolate(A, B, q1, q2) {
    /*Extract each value from 32bit Uint & blend colors together*/
    var r = (q2 * (B & REDMASK) + q1 * (A & REDMASK)) / (q1 + q2);
    var g = (q2 * ((B & GREENMASK) >> 8) + q1 * ((A & GREENMASK) >> 8)) / (q1 + q2);
    var b = (q2 * ((B & BLUEMASK) >> 16) + q1 * ((A & BLUEMASK) >> 16)) / (q1 + q2);
    var a = (q2 * ((B & ALPHAMASK) >> 24) + q1 * ((A & ALPHAMASK) >> 24)) / (q1 + q2);
    /*The bit hack '~~' is used to floor the values like Math.floor, but faster*/
    // TODO: remove to allow alpha channel
    return ((~~r) | ((~~g) << 8) | ((~~b) << 16) | ((~~a) << 24));
  }

  /// <summary>
  /// This is the XBR2x by Hyllian (see http://board.byuu.org/viewtopic.php?f=10&t=2248)
  /// </summary>
  function computeXbr(oriPixelView, oriX, oriY, oriW, oriH, dstPixelView, dstX, dstY, dstW, factor, allowAlphaBlending) {
    var xm2 = oriX - 2;
    if (xm2 < 0) {
      xm2 = 0;
    }
    var xm1 = oriX - 1;
    if (xm1 < 0) {
      xm1 = 0;
    }
    var xp0 = oriX;
    var xp1 = oriX + 1;
    if (xp1 >= oriW) {
      xp1 = oriW - 1;
    }
    var xp2 = oriX + 2;
    if (xp2 >= oriW) {
      xp2 = oriW - 1;
    }

    var ym2 = oriY - 2;
    if (ym2 < 0) {
      ym2 = 0;<commit_msg>New and improved algorithm to deal with alpha channel<commit_after>(function (win) {
  // Options
  var blendColors = true;
  var use3xOriginalImplementation = false;

  const REDMASK = 0x000000FF; // &MASK	>>0
  const GREENMASK = 0x0000FF00; // &MASK	>>8
  const BLUEMASK = 0x00FF0000; // &MASK	>>16
  const ALPHAMASK = 0xFF000000; // &MASK	>>24
  const THRESHHOLD_Y = 48;
  const THRESHHOLD_U = 7;
  const THRESHHOLD_V = 6;

  // Convert an ARGB byte to YUV
  function _getYuv(p) {
    var r = (p & REDMASK);
    var g = (p & GREENMASK) >> 8;
    var b = (p & BLUEMASK) >> 16;
    var y = r * .299000 + g * .587000 + b * .114000;
    var u = r *  - .168736 + g *  - .331264 + b * .500000;
    var v = r * .500000 + g *  - .418688 + b *  - .081312;
    var output = [y, u, v];
	
    return output;
  }

  function _YuvDifference(A, B) {
    var alphaA = (A & ALPHAMASK) >> 24;
    var alphaB = (B & ALPHAMASK) >> 24;

    if (alphaA === 0 && alphaB === 0) {
      return 0;
    }

    if (alphaA === 0 || alphaB === 0) {
      // Very large value not attainable by the thresholds
      return 1000000;
    }

    var yuvA = _getYuv(A);
    var yuvB = _getYuv(B);

    /*Add HQx filters threshold & return*/
    return Math.abs(yuvA[0] - yuvB[0]) * THRESHHOLD_Y
         + Math.abs(yuvA[1] - yuvB[1]) * THRESHHOLD_U
         + Math.abs(yuvA[2] - yuvB[2]) * THRESHHOLD_V;
  }

  function _IsEqual(A, B) {
    var alphaA = (A & ALPHAMASK) >> 24;
    var alphaB = (B & ALPHAMASK) >> 24;

    if (alphaA === 0 && alphaB === 0) {
      return true;
    }

    if (alphaA === 0 || alphaB === 0) {
      return false;
    }

    var yuvA = _getYuv(A);
    var yuvB = _getYuv(B);

    if (Math.abs(yuvA[0] - yuvB[0]) > THRESHHOLD_Y) {
      return false;
    }
    if (Math.abs(yuvA[1] - yuvB[1]) > THRESHHOLD_U) {
      return false;
    }
    if (Math.abs(yuvA[2] - yuvB[2]) > THRESHHOLD_V) {
      return false;
    }

    return true;
  }

  function pixelInterpolate(A, B, q1, q2) {
    var alphaA = (A & ALPHAMASK) >> 24;
    var alphaB = (B & ALPHAMASK) >> 24;

    /*Extract each value from 32bit Uint & blend colors together*/
    var r, g, b ,a;

    if (alphaA === 0) {
      r = B & REDMASK;
      g = (B & GREENMASK) >> 8;
      b = (B & BLUEMASK) >> 16;
    } else if (alphaB === 0) {
      r = A & REDMASK;
      g = (A & GREENMASK) >> 8;
      b = (A & BLUEMASK) >> 16;
    } else {
      r = (q2 * (B & REDMASK) + q1 * (A & REDMASK)) / (q1 + q2);
      g = (q2 * ((B & GREENMASK) >> 8) + q1 * ((A & GREENMASK) >> 8)) / (q1 + q2);
      b = (q2 * ((B & BLUEMASK) >> 16) + q1 * ((A & BLUEMASK) >> 16)) / (q1 + q2);
    }
    a = (q2 * ((B & ALPHAMASK) >> 24) + q1 * ((A & ALPHAMASK) >> 24)) / (q1 + q2);
    /*The bit hack '~~' is used to floor the values like Math.floor, but faster*/
    // TODO: remove to allow alpha channel
    return ((~~r) | ((~~g) << 8) | ((~~b) << 16) | ((~~a) << 24));
  }

  /// <summary>
  /// This is the XBR2x by Hyllian (see http://board.byuu.org/viewtopic.php?f=10&t=2248)
  /// </summary>
  function computeXbr(oriPixelView, oriX, oriY, oriW, oriH, dstPixelView, dstX, dstY, dstW, factor, allowAlphaBlending) {
    var xm2 = oriX - 2;
    if (xm2 < 0) {
      xm2 = 0;
    }
    var xm1 = oriX - 1;
    if (xm1 < 0) {
      xm1 = 0;
    }
    var xp0 = oriX;
    var xp1 = oriX + 1;
    if (xp1 >= oriW) {
      xp1 = oriW - 1;
    }
    var xp2 = oriX + 2;
    if (xp2 >= oriW) {
      xp2 = oriW - 1;
    }

    var ym2 = oriY - 2;
    if (ym2 < 0) {
      ym2 = 0;
{'fraction_non_alphanumeric': 0.175857431069267, 'fraction_numerical': 0.066408876933423, 'mean_word_length': 2.0554699537750385, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7668809', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2520, 'n_words': 697}