Class DesignerSnapshotCompare

java.lang.Object
com.iizigo.panel.DesignerSnapshotCompare

public final class DesignerSnapshotCompare extends Object
Pure pixel functions over ImageData used by the Panel Designer refresh: detection of a failed capture (an image of one color) and the before/after comparison of two captures. No SWT resources are created, so the functions can be unit tested directly.
Author:
Christopher Mindus
  • Method Details

    • isUniform

      public static boolean isUniform(ImageData d)
      Checks if an image is empty or of one color, which is what a failed capture of a GPU-composited browser produces. A grid of at most 64 by 64 sample points is inspected.
      Parameters:
      d - The image data, may be null.
      Returns:
      true when the image is null, empty or all sampled pixels are equal.
    • compare

      public static DesignerSnapshotCompare.Result compare(ImageData a, ImageData b, boolean createMask)
      Compares two captures pixel by pixel. The captures must have the same size; when their pixel formats differ the comparison is made on the RGB values, otherwise on the raw pixel values. Alpha is ignored.
      Parameters:
      a - The "before" image data, may be null.
      b - The "after" image data, may be null.
      createMask - Flag to build the difference mask image.
      Returns:
      The result; isComparable is false with a reason when a capture is missing or the sizes differ.
    • compare

      public static DesignerSnapshotCompare.Result compare(ImageData a, ImageData b, boolean createMask, Rectangle[] ignore)
      Compares two captures pixel by pixel as compare(ImageData,ImageData,boolean) does, leaving out the pixels inside the given rectangles: a pixel that differs there is counted in DesignerSnapshotCompare.Result.ignored, not in DesignerSnapshotCompare.Result.differing, and is neither in the box nor in the mask.
      Parameters:
      a - The "before" image data, may be null.
      b - The "after" image data, may be null.
      createMask - Flag to build the difference mask image.
      ignore - The rectangles to leave out, in image pixels, null or empty for none.
      Returns:
      The result; isComparable is false with a reason when a capture is missing or the sizes differ.
    • compareRefresh

      public static DesignerSnapshotCompare.Result compareRefresh(ImageData before, Object volatileBefore, ImageData after, Object volatileAfter, int monitorZoom, boolean createMask)
      Compares the BEFORE and the AFTER capture of a refresh of the Panel Designer, leaving out what the page paints for the pointer or for a moment and not for the panel: the pointer's cross hair and its marks in the rulers, the hover of the component or the mark under the pointer, a flash. The page names those rectangles at each capture (izDesigner.getVolatileRects() of iz/designer/paint.js). A rectangle named at ONE capture and not, the same, at the other is left out - of either capture: the pointer is somewhere else in each. A rectangle named the same at both is painted the same in both and is compared like everything else, so a pointer that rests in a container does not hide that container from the check. Without this the cross hair alone - two lines across the page in each capture - was several thousand differing pixels of a refresh that changed nothing.
      Parameters:
      before - The BEFORE image data, may be null.
      volatileBefore - What the page answered at the BEFORE capture: an array of numbers, four for each rectangle (x, y, width, height in page pixels), or null.
      after - The AFTER image data, may be null.
      volatileAfter - What the page answered at the AFTER capture, or null.
      monitorZoom - The monitor zoom in percent: an image pixel is 100/zoom page pixels.
      createMask - Flag to build the difference mask image.
      Returns:
      The result of the comparison.