src/managers/image-generator.js
/**
   * Blend 2 pixels using their weight.
   * @private
   * @param   {Uint32Array}   pix1   the color of the first pixel as a byte array
   * @param   {Uint32Array}   pix2   the color of the second pixel as a byte array
   * @param   {Number}        weight the weight of the 2nd pixel (0.0 to 1.0)
   * @returns {Uint32Array}          the blended pixel
   */
Blend 2 pixels using their weight.
Blend 2 pixels using their weight .
blendPixels(pix1, pix2, weight) {
    if (pix1 === pix2 || weight === 0) {
      return pix1;
    }
    function toBytesInt32(num) {
      const arr = new Uint8Array([
        (num & 0xff000000) >> 24,
        (num & 0x00ff0000) >> 16,
        (num & 0x0000ff00) >> 8,
        (num & 0x000000ff)
      ]);
      return arr.buffer;
    }
    const pix1Bytes = new Uint8Array(toBytesInt32(pix1));
    const pix2Bytes = new Uint8Array(toBytesInt32(pix2));
    const resultArr = new Uint8Array(4);
    for (let i = 0; i < 4; i++) {
      resultArr[i] = Math.round(Math.sqrt(Math.pow(pix1Bytes[i], 2) * (1 - weight) +
        Math.pow(pix2Bytes[i], 2) * weight));
    }
    return new Uint32Array(resultArr.buffer)[0];
  }
blendPixels ( pix1 , pix2 , weight ) { if ( pix1 === pix2 || weight === 0 ) { return pix1 ; } function toBytesInt32 ( num ) { const arr = new Uint8Array ( [ ( num & 0xff000000 ) >> 24 , ( num & 0x00ff0000 ) >> 16 , ( num & 0x0000ff00 ) >> 8 , ( num & 0x000000ff ) ] ) ; return arr . buffer ; } const pix1Bytes = new Uint8Array ( toBytesInt32 ( pix1 ) ) ; const pix2Bytes = new Uint8Array ( toBytesInt32 ( pix2 ) ) ; const resultArr = new Uint8Array ( 4 ) ; for ( let i = 0 ; i < 4 ; i ++ ) { resultArr [ i ] = Math . round ( Math . sqrt ( Math . pow ( pix1Bytes [ i ] , 2 ) * ( 1 - weight ) + Math . pow ( pix2Bytes [ i ] , 2 ) * weight ) ) ; } return new Uint32Array ( resultArr . buffer ) [ 0 ] ; }
Blend 2 pixels using their weight.
Blend 2 pixels using their weight .