Esempio n. 1
0
  /** The main method. */
  public static void main(String[] args)
      throws IOException, InterruptedException, Correlate.CorrelateException {
    // First parse the command line and test for various
    //  settings.
    if (!commandLine(args)) System.exit(-1);

    // Set the tile cache up on JAI
    TileCache tc = JAI.createTileCache(tileCacheSize);
    JAI jai = JAI.getDefaultInstance();
    jai.setTileCache(tc);

    /*
     * Create an input stream from the specified file name
     * to be used with the file decoding operator.
     */
    FileSeekableStream stream = null;
    try {
      stream = new FileSeekableStream(inputImageFilename);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(0);
    }

    /* Create an operator to decode the image file. */
    RenderedImage inputImage = JAI.create("stream", stream);

    ParameterBlock pb = new ParameterBlock();
    pb.addSource(inputImage);
    pb.add(new Float(10.0));
    pb.add(new Float(10.0));
    // Perform the color conversion.
    RenderedImage processedImage = JAI.create("Scale", pb, null);

    JAI.create("filestore", processedImage, outputImageFilename, encoder, null);
  }
Esempio n. 2
0
  private BufferedImage cropScaleGrayscale(Rectangle visibleRect, RenderedImage image) {
    int minX = image.getMinX();
    int minY = image.getMinY();
    int width = image.getWidth();
    int height = image.getHeight();

    Rectangle bounds = new Rectangle(minX, minY, width, height);

    visibleRect = bounds.intersection(visibleRect);

    if (bounds.contains(visibleRect)) {
      ParameterBlock pb = new ParameterBlock();
      pb.addSource(image);
      pb.add((float) visibleRect.x);
      pb.add((float) visibleRect.y);
      pb.add((float) visibleRect.width);
      pb.add((float) visibleRect.height);
      image = JAI.create("Crop", pb, JAIContext.noCacheHint);
    }
    Dimension previewSize = getSize();

    if ((visibleRect.width > previewSize.width) || (visibleRect.height > previewSize.height)) {
      float scale =
          Math.min(
              previewSize.width / (float) visibleRect.width,
              previewSize.height / (float) visibleRect.height);

      image = ConvolveDescriptor.create(image, Functions.getGaussKernel(.25 / scale), null);
      ParameterBlock pb = new ParameterBlock();
      pb.addSource(image);
      pb.add(scale);
      pb.add(scale);
      image = JAI.create("Scale", pb, JAIContext.noCacheHint);
    }
    image = Functions.toColorSpace(image, JAIContext.systemColorSpace, null);

    if (image.getSampleModel().getDataType() == DataBuffer.TYPE_USHORT) {
      image = Functions.fromUShortToByte(image, null);
    }
    return Functions.toFastBufferedImage(image);
  }