Repository: mozilla/pdf.js
File: src/core/pattern.js (JavaScript)

Code before:
      // Acrobat doesn't seem to handle these cases so we'll ignore for
      // now.
      info("Bad shading domain.");
      return;
    }

    const color = new Float32Array(cs.numComps),
      ratio = new Float32Array(1);

    let iBase = 0;
    ratio[0] = t0;
    fn(ratio, 0, color, 0);
    const rgbBuffer = new Uint8ClampedArray(3);
    cs.getRgb(color, 0, rgbBuffer);
    let rBase = rgbBuffer[0];
    let gBase = rgbBuffer[1];
    let bBase = rgbBuffer[2];
    colorStops.push([0, Util.makeHexColor(rBase, gBase, bBase)]);

    let iPrev = 1;
    ratio[0] = t0 + step;
    fn(ratio, 0, color, 0);
    cs.getRgb(color, 0, rgbBuffer);
    let rPrev = rgbBuffer[0];
    let gPrev = rgbBuffer[1];
    let bPrev = rgbBuffer[2];

    // Slopes are rise / run.
    // A max slope is from the least value the base component could have been
    // to the greatest value the current component could have been.
    // A min slope is from the greatest value the base component could have been
    // to the least value the current component could have been.
    // Each component could have been rounded up to .5 from its original value
    // so the conservative deltas are +-1 (+-.5 for base and -+.5 for current).

    // The run is iPrev - iBase = 1, so omitted.
    let maxSlopeR = rPrev - rBase + 1;
    let maxSlopeG = gPrev - gBase + 1;
    let maxSlopeB = bPrev - bBase + 1;
    let minSlopeR = rPrev - rBase - 1;
    let minSlopeG = gPrev - gBase - 1;
    let minSlopeB = bPrev - bBase - 1;

    for (let i = 2; i < NUMBER_OF_SAMPLES; i++) {
      ratio[0] = t0 + i * step;
      fn(ratio, 0, color, 0);
      cs.getRgb(color, 0, rgbBuffer);
      const r = rgbBuffer[0];
      const g = rgbBuffer[1];
      const b = rgbBuffer[2];


Review comment (suggestion):
Nit: Could we shorten this with destructuring?
```suggestion
    let [rPrev, gPrev, bPrev] = rgbBuffer;
```

Code after:
      // Acrobat doesn't seem to handle these cases so we'll ignore for
      // now.
      info("Bad shading domain.");
      return;
    }

    const color = new Float32Array(cs.numComps),
      ratio = new Float32Array(1);

    let iBase = 0;
    ratio[0] = t0;
    fn(ratio, 0, color, 0);
    const rgbBuffer = new Uint8ClampedArray(3);
    cs.getRgb(color, 0, rgbBuffer);
    let [rBase, gBase, bBase] = rgbBuffer;
    colorStops.push([0, Util.makeHexColor(rBase, gBase, bBase)]);

    let iPrev = 1;
    ratio[0] = t0 + step;
    fn(ratio, 0, color, 0);
    cs.getRgb(color, 0, rgbBuffer);
    let [rPrev, gPrev, bPrev] = rgbBuffer;

    // Slopes are rise / run.
    // A max slope is from the least value the base component could have been
    // to the greatest value the current component could have been.
    // A min slope is from the greatest value the base component could have been
    // to the least value the current component could have been.
    // Each component could have been rounded up to .5 from its original value
    // so the conservative deltas are +-1 (+-.5 for base and -+.5 for current).

    // The run is iPrev - iBase = 1, so omitted.
    let maxSlopeR = rPrev - rBase + 1;
    let maxSlopeG = gPrev - gBase + 1;
    let maxSlopeB = bPrev - bBase + 1;
    let minSlopeR = rPrev - rBase - 1;
    let minSlopeG = gPrev - gBase - 1;
    let minSlopeB = bPrev - bBase - 1;

    for (let i = 2; i < NUMBER_OF_SAMPLES; i++) {
      ratio[0] = t0 + i * step;
      fn(ratio, 0, color, 0);
      cs.getRgb(color, 0, rgbBuffer);
      const [r, g, b] = rgbBuffer;

      // Keep going if the maximum minimum slope <= the minimum maximum slope.
      // Otherwise add a rgbPrev color stop and make it the new base.

      const run = i - iBase;
      maxSlopeR = Math.min(maxSlopeR, (r - rBase + 1) / run);
      maxSlopeG = Math.min(maxSlopeG, (g - gBase + 1) / run);