View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, Joćo E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d; 21 22 /* 23 This class is adapted from the one that came with java 3D. Follows 24 Sun's copyright notice. 25 */ 26 27 /*** @(#)OffScreenCanvas3D.java 1.6 01/01/11 28 07:36:38 29 * 30 * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved. 31 * 32 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, 33 * modify and redistribute this software in source and binary code form, 34 * provided that i) this copyright notice and license appear on all copies of 35 * the software; and ii) Licensee does not utilize the software in a manner 36 * which is disparaging to Sun. 37 * 38 * This software is provided "AS IS," without a warranty of any kind. ALL 39 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY 40 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR 41 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE 42 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING 43 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS 44 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, 45 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER 46 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF 47 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 48 * POSSIBILITY OF SUCH DAMAGES. 49 * 50 * This software is not designed or intended for use in on-line control of 51 * aircraft, air traffic, aircraft navigation or aircraft communications; or in 52 * the design, construction, operation or maintenance of any nuclear 53 * facility. Licensee represents and warrants that it will not use or 54 * redistribute the Software for such purposes. 55 */ 56 57 import java.awt.*; 58 import java.awt.image.BufferedImage; 59 import java.awt.event.*; 60 import javax.media.j3d.*; 61 import javax.vecmath.*; 62 import com.sun.j3d.utils.applet.MainFrame; 63 import com.sun.j3d.utils.image.*; 64 import java.awt.print.*; 65 import java.awt.print.PrinterJob; 66 import java.awt.print.PrinterGraphics; 67 import java.awt.Image; 68 import java.awt.image.ImageObserver; 69 import java.io.*; 70 import java.net.*; 71 import javax.media.j3d.*; 72 import javax.vecmath.*; 73 import java.awt.geom.AffineTransform; 74 import java.awt.image.BufferedImage; 75 import com.sun.image.codec.jpeg.*; 76 import java.awt.Color; 77 78 79 /*** 80 * Adapted from an OffScreenCanvas3D class that used to come as a demo 81 * with Java3D. 82 */ 83 class OffScreenCanvas3D extends Canvas3D { 84 85 //Raster drawRaster; 86 private boolean printing = false; 87 private String filename; 88 private BufferedImage bImage; 89 90 91 public OffScreenCanvas3D(GraphicsConfiguration gconfig, boolean offscreenflag/*, 92 Raster drawRaster*/) { 93 super(gconfig, offscreenflag); 94 } 95 96 public void print(boolean toWait, String filename, int width, int height) { 97 98 this.filename = filename; 99 if (!toWait) 100 printing = true; 101 102 bImage = new BufferedImage(width, height , BufferedImage.TYPE_INT_RGB); 103 104 ImageComponent2D buffer = new ImageComponent2D( 105 ImageComponent.FORMAT_RGB, bImage); 106 buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); 107 108 this.setOffScreenBuffer(buffer); 109 110 this.renderOffScreenBuffer(); 111 112 if (toWait) { 113 this.waitForOffScreenRendering(); 114 drawOffScreenBuffer(); 115 saveJPEG(bImage); 116 this.getView().removeCanvas3D(this); 117 } 118 } 119 120 public void postSwap() { 121 122 if (printing) { 123 super.postSwap(); 124 drawOffScreenBuffer(); 125 printing = false; 126 } 127 } 128 129 void drawOffScreenBuffer() { 130 131 /*BufferedImage */bImage = this.getOffScreenBuffer().getImage(); 132 //drawRaster.setImage(newImageComponent); 133 } 134 135 /*** 136 * Creates a jpeg file which contains the most recent frame. The name of the 137 * file was set in a previous step (when the print method was called). 138 * @param img image of the last frame. 139 */ 140 private void saveJPEG(BufferedImage img){ 141 try { 142 FileOutputStream out = new FileOutputStream(filename); 143 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); 144 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img); 145 param.setQuality(1.0f,false); // 100% quality JPEG 146 encoder.setJPEGEncodeParam(param); 147 encoder.encode(img); 148 out.close(); 149 // printRGBValues(img); 150 } catch ( IOException e ) { 151 System.out.println("I/O exception!"); 152 } 153 154 } 155 156 } 157

This page was automatically generated by Maven