trimEdges(stage) {
    if (!stage.srcCtx) {
      return;
    }

    const srcData = stage.srcCtx.getImageData(0, 0, stage.srcSize.w, stage.srcSize.h);

    // Always trim by top-left pixel color
    const trimPixel = getPixel_(stage, srcData, 0, 0);

    let insetRect = {l:0, t:0, r:0, b:0};
    let x, y;

    // Trim top
    trimTop:
    for (y = 0; y < stage.srcSize.h; y++) {
      for (x = 0; x < stage.srcSize.w; x++) {
        if (getPixel_(stage, srcData, x, y) != trimPixel) {
          break trimTop;
        }
      }
    }
    insetRect.t = y;
    // Trim left
    trimLeft:
    for (x = 0; x < stage.srcSize.w; x++) {
      for (y = 0; y < stage.srcSize.h; y++) {
        if (getPixel_(stage, srcData, x, y) != trimPixel) {
          break trimLeft;
        }
      }
    }
    insetRect.l = x;
    // Trim bottom
    trimBottom:
    for (y = stage.srcSize.h - 1; y >= 0; y--) {
      for (x = 0; x < stage.srcSize.w; x++) {
        if (getPixel_(stage, srcData, x, y) != trimPixel) {
          break trimBottom;
        }
      }
    }
    insetRect.b = stage.srcSize.h - y - 1;
    // Trim right
    trimRight:
    for (x = stage.srcSize.w - 1; x >= 0; x--) {
      for (y = 0; y < stage.srcSize.h; y++) {
        if (getPixel_(stage, srcData, x, y) != trimPixel) {
          break trimRight;
        }
      }
    }
    insetRect.r = stage.srcSize.w - x - 1;

    if (insetRect.l <= 0 && insetRect.t <= 0 && insetRect.r <= 0 && insetRect.b <= 0) {
      // No-op
      return;
    }

    // Build a new stage with inset values
    const size = {
      w: stage.srcSize.w - insetRect.l - insetRect.r,
      h: stage.srcSize.h - insetRect.t - insetRect.b
    };

    const rects = {
      contentRect: constrain_(size, {
        x: stage.contentRect.x - insetRect.l,
        y: stage.contentRect.y - insetRect.t,
        w: stage.contentRect.w,
        h: stage.contentRect.h
      }),
      stretchRect: constrain_(size, {
        x: stage.stretchRect.x - insetRect.l,
        y: stage.stretchRect.y - insetRect.t,
        w: stage.stretchRect.w,
        h: stage.stretchRect.h
      }),
      opticalBoundsRect: constrain_(size, {
        x: stage.opticalBoundsRect.x - insetRect.l,
        y: stage.opticalBoundsRect.y - insetRect.t,
        w: stage.opticalBoundsRect.w,
        h: stage.opticalBoundsRect.h
      })
    };

    stage.name = `${stage.name}-EDGES_TRIMMED`;
    let newCtx = studio.Drawing.context(size);
    newCtx.drawImage(stage.srcCtx.canvas,
        insetRect.l, insetRect.t, size.w, size.h,
        0, 0, size.w, size.h);
    stage.loadSourceImage(newCtx, rects);
  }
Trims excess edges of the nine patch... any pixels that are the same
as the top-left most pixel color. Same as Photoshop's Trim feature.