예제 #1
0
  public static void randomToolActions(int numStrokes, boolean brushOnly) {
    Composition comp = ImageComponents.getActiveComp().get();
    Random random = new Random();

    if (comp != null) {
      int canvasWidth = comp.getCanvasWidth();
      int canvasHeight = comp.getCanvasHeight();

      ProgressMonitor progressMonitor = Utils.createPercentageProgressMonitor("1001 Tool Actions");

      // So far we are on the EDT
      Runnable notEDTThreadTask =
          () -> {
            assert !SwingUtilities.isEventDispatchThread();
            for (int i = 0; i < numStrokes; i++) {
              int progressPercentage = (int) ((float) i * 100 / numStrokes);
              progressMonitor.setProgress(progressPercentage);
              progressMonitor.setNote(progressPercentage + "%");

              Runnable edtRunnable =
                  () -> testToolAction(comp, random, canvasWidth, canvasHeight, brushOnly);

              try {
                SwingUtilities.invokeAndWait(edtRunnable);
              } catch (InterruptedException | InvocationTargetException e) {
                e.printStackTrace();
              }

              comp.repaint();
            }
            progressMonitor.close();
          };
      new Thread(notEDTThreadTask).start();
    }
  }
예제 #2
0
  public static void addRadialBWGradientToActiveLayer(Composition comp, boolean radial) {
    int canvasWidth = comp.getCanvasWidth();
    int canvasHeight = comp.getCanvasHeight();

    int startX = canvasWidth / 2;
    int startY = canvasHeight / 2;

    int endX = 0;
    int endY = 0;
    if (canvasWidth > canvasHeight) {
      endX = startX;
    } else {
      endY = startY;
    }

    GradientType gradientType;

    if (radial) {
      gradientType = GradientType.RADIAL;
    } else {
      gradientType = GradientType.SPIRAL_CW;
    }

    GradientTool.drawGradient(
        comp.getActiveMaskOrImageLayer(),
        gradientType,
        BLACK_TO_WHITE,
        REFLECT,
        AlphaComposite.SrcOver,
        new UserDrag(startX, startY, endX, endY),
        false);
  }
예제 #3
0
 private static void paintDiagonals(
     AbstractBrushTool eraseTool, Composition comp, int xDistanceFormEdge, int yDistanceFormEdge) {
   int canvasWidth = comp.getCanvasWidth();
   int canvasHeight = comp.getCanvasHeight();
   Point topLeft = new Point(xDistanceFormEdge, yDistanceFormEdge);
   Point topRight = new Point(canvasWidth - xDistanceFormEdge, yDistanceFormEdge);
   Point bottomRight =
       new Point(canvasWidth - xDistanceFormEdge, canvasHeight - yDistanceFormEdge);
   Point bottomLeft = new Point(xDistanceFormEdge, canvasHeight - yDistanceFormEdge);
   eraseTool.drawBrushStrokeProgrammatically(comp, topLeft, bottomRight);
   eraseTool.drawBrushStrokeProgrammatically(comp, topRight, bottomLeft);
 }
예제 #4
0
  private static void paintHeartShape(Composition comp) {
    ShapesTool shapesTool = Tools.SHAPES;
    int canvasWidth = comp.getCanvasWidth();
    int canvasHeight = comp.getCanvasHeight();

    UserDrag userDrag =
        new UserDrag(
            (int) (canvasWidth * 0.25),
            (int) (canvasHeight * 0.25),
            (int) (canvasWidth * 0.75),
            (int) (canvasHeight * 0.75));

    shapesTool.setShapeType(ShapeType.HEART);
    shapesTool.paintShapeOnIC(comp, userDrag);
  }
예제 #5
0
  public static void writeOpenRaster(Composition comp, File outFile, boolean addMergedImage)
      throws IOException {
    FileOutputStream fos = new FileOutputStream(outFile);
    ZipOutputStream zos = new ZipOutputStream(fos);

    String stackXML =
        String.format(
            "<?xml version='1.0' encoding='UTF-8'?>\n"
                + "<image w=\"%d\" h=\"%d\">\n"
                + "<stack>\n",
            comp.getCanvasWidth(), comp.getCanvasHeight());

    int nrLayers = comp.getNrLayers();

    // Reverse iteration: in stack.xml the first element in a stack is the uppermost.
    for (int i = nrLayers - 1; i >= 0; i--) {
      Layer layer = comp.getLayer(i);
      stackXML += writeLayer(zos, i, layer);
    }

    if (addMergedImage) {
      zos.putNextEntry(new ZipEntry("mergedimage.png"));
      ImageIO.write(comp.getCompositeImage(), "PNG", zos);
      zos.closeEntry();
    }

    stackXML += "</stack>\n</image>";

    // write the stack.xml file
    zos.putNextEntry(new ZipEntry("stack.xml"));
    zos.write(stackXML.getBytes("UTF-8"));
    zos.closeEntry();

    // write the mimetype
    zos.putNextEntry(new ZipEntry("mimetype"));
    zos.write("image/openraster".getBytes("UTF-8"));
    zos.closeEntry();
    zos.close();
  }