001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: package com.db.layers.underlay;
034:
035: import javax.media.util.ImageToBuffer;
036: import java.awt.image.BufferedImage;
037: import java.awt.image.DataBuffer;
038: import java.awt.image.WritableRaster;
039: import java.awt.image.Raster;
040: import java.awt.Dimension;
041: import java.awt.Point;
042: import javax.media.j3d.*;
043:
044: public class TransparentCanvas3D extends Canvas3D {
045:
046: private BufferedImage sourceBufferedImage;
047: private BufferedImage destinationBufferedImage;
048: private WritableRaster raster;
049: private ImageComponent2D imageComponent2D;
050: private ImageToBuffer imageToBuffer;
051:
052: private int frameRate = 25;
053: //unused
054: private int bands = 4;
055:
056: public TransparentCanvas3D(
057: java.awt.GraphicsConfiguration graphicsConfiguration) {
058:
059: super (graphicsConfiguration);
060:
061: }
062:
063: public TransparentCanvas3D(
064: java.awt.GraphicsConfiguration graphicsConfiguration,
065: boolean offScreen) {
066:
067: super (graphicsConfiguration, offScreen);
068:
069: int rgbPixel;
070: int[] ints;
071:
072: sourceBufferedImage = this .getOffScreenBuffer().getImage();
073:
074: imageToBuffer = new ImageToBuffer();
075:
076: imageToBuffer.createBuffer(sourceBufferedImage, frameRate);
077:
078: if (!sourceBufferedImage.getColorModel().hasAlpha()) {
079:
080: raster = Raster.createBandedRaster(DataBuffer.TYPE_INT,
081: sourceBufferedImage.getWidth(), sourceBufferedImage
082: .getHeight(), 4, new Point(0, 0));
083: for (int i = 0; i < sourceBufferedImage.getHeight(); i++) {
084: for (int j = 0; j < sourceBufferedImage.getWidth(); j++) {
085: rgbPixel = sourceBufferedImage.getRGB(i, j);
086: ints = new int[4];
087: ints[0] = 1;
088: ints[1] = rgbPixel;
089: ints[2] = rgbPixel / 256;
090: ints[3] = rgbPixel / 65536;
091: raster.setPixel(i, j, ints);
092: }
093: }
094:
095: destinationBufferedImage = new BufferedImage(
096: sourceBufferedImage.getWidth(), sourceBufferedImage
097: .getHeight(), BufferedImage.TYPE_INT_ARGB);
098: destinationBufferedImage.setData(raster);
099: //destinationBufferedImage.coerceData(true);
100: } else {
101: destinationBufferedImage = sourceBufferedImage;
102: }
103:
104: //prepare next image
105: this .renderOffScreenBuffer();
106: this .waitForOffScreenRendering();
107:
108: }
109:
110: public void postSwap() {
111:
112: super.postSwap();
113:
114: }
115:
116: }
|