Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
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);
  }
    private void makeNoDataTransparent(
        BufferedImage image, short missingDataSignal, short missingDataReplacement) {
      WritableRaster raster = null;

      if (null != image
          && (image.getType() == BufferedImage.TYPE_4BYTE_ABGR
              || image.getType() == BufferedImage.TYPE_INT_ARGB)
          && null != (raster = image.getRaster())) {
        int nodata_r = missingDataSignal & 0xff;
        int nodata_g = missingDataSignal & 0xff;
        int nodata_b = missingDataSignal & 0xff;

        int[] pixel = new int[4];
        int[] transparentPixel =
            new int[] {
              0xFF & missingDataReplacement /* red */,
              0xFF & missingDataReplacement /* green */,
              0xFF & missingDataReplacement,
              0x00 /* alpha */
            };

        int width = image.getWidth();
        int height = image.getHeight();
        for (int j = 0; j < height; j++) {
          for (int i = 0; i < width; i++) {
            // We know, by the nature of this source, that we are dealing with RGBA rasters...
            raster.getPixel(i, j, pixel);
            if (pixel[0] == nodata_r && pixel[1] == nodata_g && pixel[2] == nodata_b) {
              //                            pixel[0] = pixel[1] = pixel[2] = 0xFF &
              // missingDataReplacement;
              //                            pixel[3] = 0;   // transparent
              raster.setPixel(i, j, transparentPixel);
            } else {
              pixel[3] = 0xff; // non-transparent
              raster.setPixel(i, j, pixel);
            }
          }
        }
      }
    }
Ejemplo n.º 5
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);
  }