Beispiel #1
0
 public static void main(String[] args) throws Exception {
   Convolution[] filters = {
     box, new Hanning(1), new Hanning(2), new Hamming(1), new Lanczos(2), new Lanczos(3),
   };
   // BufferedImage in = Resource.loadimg("gfx/invobjs/herbs/crowberry");
   BufferedImage in = javax.imageio.ImageIO.read(new java.io.File("/tmp/e.jpg"));
   Coord tsz = new Coord(300, 300);
   for (int i = 0; i < filters.length; i++) {
     long start = System.nanoTime();
     BufferedImage out = convolvedown(in, tsz, filters[i]);
     System.err.println(System.nanoTime() - start);
     javax.imageio.ImageIO.write(out, "PNG", new java.io.File("/tmp/barda" + i + ".png"));
   }
 }
Beispiel #2
0
  public void saveFrametoPNG(String filename) {
    final int frameWidth = _canvas.getWidth();
    final int frameHeight = _canvas.getHeight();
    final ByteBuffer pixelsRGB = Direct.newByteBuffer(frameWidth * frameHeight * 3);
    _canvas.runWithContext(
        new Runnable() {
          public void run() {
            // glPushAttrib(GL_PIXEL_MODE_BIT);
            glReadBuffer(GL_BACK);
            glPixelStorei(GL_PACK_ALIGNMENT, 1);
            glReadPixels(0, 0, frameWidth, frameHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelsRGB);
            // glPopAttrib();
          }
        });
    int[] pixelInts = new int[frameWidth * frameHeight];
    int p = frameWidth * frameHeight * 3;
    int q; // Index into ByteBuffer
    int i = 0; // Index into target int[]
    int w3 = frameWidth * 3; // Number of bytes in each row
    for (int row = 0; row < frameHeight; row++) {
      p -= w3;
      q = p;
      for (int col = 0; col < frameWidth; col++) {
        int iR = pixelsRGB.get(q++);
        int iG = pixelsRGB.get(q++);
        int iB = pixelsRGB.get(q++);
        pixelInts[i++] =
            0xFF000000 | ((iR & 0x000000FF) << 16) | ((iG & 0x000000FF) << 8) | (iB & 0x000000FF);
      }
    }

    // Create a new BufferedImage from the pixeldata.
    BufferedImage bufferedImage =
        new BufferedImage(frameWidth, frameHeight, BufferedImage.TYPE_INT_ARGB);
    bufferedImage.setRGB(0, 0, frameWidth, frameHeight, pixelInts, 0, frameWidth);

    try {
      javax.imageio.ImageIO.write(bufferedImage, "PNG", new File(filename));
    } catch (IOException e) {
      System.out.println("Error: ImageIO.write.");
      e.printStackTrace();
    }

    /* End code taken from: http://www.felixgers.de/teaching/jogl/imagingProg.html */

    /*
     final BufferedImage image = new BufferedImage(
     this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
     Graphics gr = image.getGraphics();
     this.printAll(gr);
     gr.dispose();
    try {
    	ImageIO.write(image, "PNG", new File(filename));
      } catch (IOException e) {
           System.out.println( "Error: ImageIO.write." );
           e.printStackTrace();
      }
    */
  }
Beispiel #3
0
 /**
  * Make a BufferedImage from the contents of an image file.
  *
  * @param imageFileContents byte array containing the guts of a JPG, GIF, or PNG
  */
 public BufferedImage makeBufferedImage(byte[] imageFileContents) {
   BufferedImage bi = null;
   try {
     InputStream in = new ByteArrayInputStream(imageFileContents);
     bi = javax.imageio.ImageIO.read(in);
   } catch (IOException ioe) {
     GLApp.err("GLImage.makeBufferedImage(): " + ioe);
   }
   return bi;
 }
Beispiel #4
0
 /**
  * Save an array of ARGB pixels to a PNG file. If flipY is true, flip the pixels on the Y axis
  * before saving.
  */
 public static void savePixelsToPNG(
     int[] pixels, int width, int height, String imageFilename, boolean flipY) {
   if (pixels != null && imageFilename != null) {
     if (flipY) {
       // flip the pixels vertically (opengl has 0,0 at lower left, java is upper left)
       pixels = GLImage.flipPixels(pixels, width, height);
     }
     try {
       // Create a BufferedImage with the RGB pixels then save as PNG
       BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       image.setRGB(0, 0, width, height, pixels, 0, width);
       javax.imageio.ImageIO.write(image, "png", new File(imageFilename));
     } catch (Exception e) {
       GLApp.err("GLImage.savePixelsToPNG(" + imageFilename + "): exception " + e);
     }
   }
 }
 public static Image readImage(String filePath) throws IOException {
   return javax.imageio.ImageIO.read(new File(filePath));
 }