Esempio n. 1
0
  public static ArthurImage multiply(ArthurImage one, ArthurImage two) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    BufferedImage image2 = JavaImageMath.clone(two.bf);

    WritableRaster r1 = image.getRaster();
    WritableRaster r2 = image2.getRaster();
    int newWidth = Math.max(r1.getWidth(), r2.getWidth());
    int newHeight = Math.max(r1.getHeight(), r2.getHeight());

    BufferedImage collage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = collage.getRaster();

    int[] p1 = new int[3];
    int[] p2 = new int[3];
    int[] pixelArray = new int[3];
    for (int y = 0; y < newHeight; y++) {
      for (int x = 0; x < newWidth; x++) {
        p1 = null;
        p2 = null;

        if (x < r1.getWidth() && y < r1.getHeight()) {
          p1 = r1.getPixel(x, y, p1);
        }

        if (x < r2.getWidth() && y < r2.getHeight()) {
          p2 = r2.getPixel(x, y, p2);
        }

        for (int i = 0; i < 3; i++) {
          if (p1 == null && p2 == null) {
            pixelArray[i] = 0;
          } else if (p1 == null && p2 != null) {
            pixelArray[i] = p2[i];
          } else if (p1 != null && p2 == null) {
            pixelArray[i] = p1[i];
          } else {
            pixelArray[i] = (int) ((p1[i] + p2[i]) / 2);
          }
        }
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "X"
            + // filename can't contain the / or *characters; decide later
            two.filename.substring(0, two.filename.indexOf(".jpg"))
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }
Esempio n. 2
0
  public static ArthurImage add(ArthurImage one, ArthurColor two) {
    BufferedImage image = JavaImageMath.clone(one.bf);

    double r = two.r.val;
    double g = two.g.val;
    double b = two.g.val;

    WritableRaster raster = image.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < raster.getHeight(); y++) {
      for (int x = 0; x < raster.getWidth(); x++) {
        pixelArray = raster.getPixel(x, y, pixelArray);
        pixelArray[0] = (int) (3 * pixelArray[0] + r) / 4;
        pixelArray[1] = (int) (3 * pixelArray[1] + g) / 4;
        pixelArray[2] = (int) (3 * pixelArray[2] + b) / 4;
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "+"
            + // filename can't contain the / or *characters; decide later
            r
            + g
            + b
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(image, outputFn);
  }
Esempio n. 3
0
  public static ArthurImage add(ArthurImage one, ArthurNumber two) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    int num = two.val.intValue();

    WritableRaster raster = image.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < raster.getHeight(); y++) {
      for (int x = 0; x < raster.getWidth(); x++) {
        pixelArray = raster.getPixel(x, y, pixelArray);
        pixelArray[0] = pixelArray[0] + num;
        pixelArray[1] = pixelArray[1] + num;
        pixelArray[2] = pixelArray[2] + num;
        for (int i = 0; i < 3; i++) {
          if (pixelArray[i] > 255) {
            pixelArray[i] = 255;
          }
        }
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "+"
            + // filename can't contain the / or *characters; decide later
            num
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(image, outputFn);
  }
Esempio n. 4
0
  public static ArthurImage divide(ArthurImage one, ArthurImage two) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    BufferedImage image2 = JavaImageMath.clone(two.bf);

    WritableRaster r1 = image.getRaster();
    int width = r1.getWidth();
    int height = r1.getHeight();

    BufferedImage r2resize = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = r2resize.createGraphics();
    g2d.drawImage(image2, 0, 0, width, height, null);
    g2d.dispose();
    WritableRaster r2 = r2resize.getRaster();

    BufferedImage collage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = collage.getRaster();

    int[] p1 = new int[3];
    int[] p2 = new int[3];
    int[] pixelArray = new int[3];
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        p1 = r1.getPixel(x, y, p1);
        p2 = r2.getPixel(x, y, p2);

        for (int i = 0; i < 3; i++) {
          pixelArray[i] = (int) ((p1[i] + p2[i]) / 2);
        }
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "D"
            + // filename can't contain the / or *characters; decide later
            two.filename.substring(0, two.filename.indexOf(".jpg"))
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }