FileDocCategorySizeDatePackage
Java2DRenderer.javaAPI DocJMF 2.1.1e3606Mon May 12 12:20:48 BST 2003com.sun.media.renderer.video

Java2DRenderer

public class Java2DRenderer extends Object implements Blitter
Renderer for RGB images using BufferedImage

Fields Summary
private transient AffineTransformOp
savedATO
Variables and Constants
private transient DirectColorModel
dcm
private transient Image
destImage
Constructors Summary
public Java2DRenderer()
Constructor


          

      
	try {
	    Class.forName("java.awt.Graphics2D");
	} catch (ClassNotFoundException e) {
	    throw new RuntimeException("No Java2D");
	}
    
Methods Summary
public synchronized voiddraw(java.awt.Graphics g, java.awt.Component component, java.awt.Image lastImage, int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh)

	if (lastImage == null || dw < 1 || dh < 1)
	    return;
	if (savedATO == null) {
	    AffineTransform at = new AffineTransform((float)dw / sw, 0,
						     0, (float)dh / sh,
						     0, 0);
	    AffineTransformOp ato = new AffineTransformOp(at, null);

	    savedATO = ato;
	    destImage = ato.createCompatibleDestImage((BufferedImage)lastImage,
						      (ColorModel)dcm);
	}
	((AffineTransformOp)savedATO).filter((BufferedImage)lastImage, (BufferedImage)destImage);
	if (g != null && lastImage != null && g instanceof Graphics2D) {
	    ((Graphics2D)g).drawImage(destImage, 0, 0, component);
	}
    
public intnewData(javax.media.Buffer buffer, java.util.Vector cacheInputImage, java.util.Vector cacheOutputImage, java.util.Vector cacheInputData)

	Object data = buffer.getData();
	if (!(data instanceof int[]))
	    return -1;
	RGBFormat format = (RGBFormat) buffer.getFormat();
	int rMask, gMask, bMask;
	/*
	rMask = 0x000000FF;
	gMask = 0x0000FF00;
	bMask = 0x00FF0000;
	*/
	
	rMask = format.getRedMask();
	gMask = format.getGreenMask();
	bMask = format.getBlueMask();
	int [] masks = new int[3];
	masks[0] = rMask;
	masks[1] = gMask;
	masks[2] = bMask;
	
	DataBuffer db = new DataBufferInt((int[])data,
					  format.getLineStride() *
					    format.getSize().height);
		
	SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
							  format.getLineStride(),
							  format.getSize().height,
							  masks);
	WritableRaster wr = Raster.createWritableRaster(sm, db, new Point(0, 0));

	dcm = new DirectColorModel(24, rMask, gMask, bMask);
	BufferedImage sourceImage = new BufferedImage((ColorModel)dcm, wr, true, null);

	cacheInputData.addElement(data);
	cacheInputImage.addElement(sourceImage);
	cacheOutputImage.addElement(sourceImage);  // dummy
	synchronized (this) {
	    savedATO = null;
	}
	return cacheInputImage.size() - 1;
    
public java.awt.Imageprocess(javax.media.Buffer buffer, java.lang.Object cacheInputImage, java.lang.Object cacheOutputImage, java.awt.Dimension size)
Processes the data and creates an image to be rendered

	return (Image) cacheInputImage;
    
public voidresized(java.awt.Component c)

	savedATO = null;