Exemplo n.º 1
0
  @Override
  public DirtyRegionContainer getDirtyRegions(Effect defaultInput, DirtyRegionPool regionPool) {
    Effect di = getDefaultedInput(0, defaultInput);
    DirtyRegionContainer drc = di.getDirtyRegions(defaultInput, regionPool);

    drc.grow(state.getHPad(), state.getVPad());

    return drc;
  }
  @Test
  public void dropShadowTest() {
    setupTest();

    effect = new DropShadow();

    drc.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    g1bn.setEffect(effect);
    g1bn.applyEffect(g1bn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(40, 40, 70, 70)});
    compareResult(drcExpected, drc);

    drc.addDirtyRegion(new RectBounds(70, 70, 80, 80));
    gbn.setEffect(effect);
    gbn.applyEffect(gbn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(30, 30, 90, 90)});
    compareResult(drcExpected, drc);
  }
  @Test
  public void colorAdjustTest() {
    setupTest();

    effect = new ColorAdjust();

    drc.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    g1bn.setEffect(effect);
    g1bn.applyEffect(g1bn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    compareResult(drcExpected, drc);

    drc.addDirtyRegion(new RectBounds(70, 70, 80, 80));
    gbn.setEffect(effect);
    gbn.applyEffect(gbn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(
        new RectBounds[] {new RectBounds(50, 50, 60, 60), new RectBounds(70, 70, 80, 80)});
    compareResult(drcExpected, drc);
  }
  @Test
  public void boxBlurTest() {
    setupTest();

    effect = new BoxBlur(10, 5, 3);

    drc.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    g1bn.setEffect(effect);
    g1bn.applyEffect(g1bn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(36, 44, 74, 66)});
    compareResult(drcExpected, drc);

    drc.addDirtyRegion(new RectBounds(70, 70, 80, 80));
    gbn.setEffect(effect);
    gbn.applyEffect(gbn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(
        new RectBounds[] {new RectBounds(22, 38, 88, 72), new RectBounds(56, 64, 94, 86)});
    compareResult(drcExpected, drc);
  }
  @Test
  public void motionBlurTest() {
    setupTest();

    effect = new MotionBlur();

    drc.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    g1bn.setEffect(effect);
    g1bn.applyEffect(g1bn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(40, 50, 70, 60)});
    compareResult(drcExpected, drc);

    ((MotionBlur) effect).setAngle((float) Math.toRadians(90));
    drc.addDirtyRegion(new RectBounds(70, 70, 80, 80));
    gbn.setEffect(effect);
    gbn.applyEffect(gbn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(
        new RectBounds[] {new RectBounds(39, 40, 71, 70), new RectBounds(69, 60, 81, 90)});
    compareResult(drcExpected, drc);
  }
  @Test
  public void gausianBlurTest() {
    setupTest();

    effect = new GaussianBlur(5);

    drc.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    g1bn.setEffect(effect);
    g1bn.applyEffect(g1bn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(45, 45, 65, 65)});
    compareResult(drcExpected, drc);

    ((GaussianBlur) effect).setRadius(2);
    drc.addDirtyRegion(new RectBounds(70, 70, 80, 80));
    gbn.setEffect(effect);
    gbn.applyEffect(gbn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(
        new RectBounds[] {new RectBounds(43, 43, 67, 67), new RectBounds(68, 68, 82, 82)});
    compareResult(drcExpected, drc);
  }
  @Test
  public void boxShadowTest() {
    setupTest();

    effect = new BoxShadow();
    ((BoxShadow) effect).setHorizontalSize(10);

    drc.deriveWithNewRegions(new RectBounds[] {new RectBounds(50, 50, 60, 60)});
    g1bn.setEffect(effect);
    g1bn.applyEffect(g1bn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(new RectBounds[] {new RectBounds(45, 50, 65, 60)});
    compareResult(drcExpected, drc);

    ((BoxShadow) effect).setHorizontalSize(0);
    ((BoxShadow) effect).setVerticalSize(10);
    drc.addDirtyRegion(new RectBounds(70, 70, 80, 80));
    gbn.setEffect(effect);
    gbn.applyEffect(gbn.getEffectFilter(), drc, drp);
    drcExpected.deriveWithNewRegions(
        new RectBounds[] {new RectBounds(45, 45, 65, 65), new RectBounds(70, 65, 80, 85)});
    compareResult(drcExpected, drc);
  }
 private void compareResult(DirtyRegionContainer expected, DirtyRegionContainer computed) {
   for (int i = 0; i < computed.size(); i++) {
     Assert.assertEquals(expected.getDirtyRegion(i), computed.getDirtyRegion(i));
   }
 }