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

AWTRenderer

public class AWTRenderer extends BasicVideoRenderer implements Blitter
Renderer for RGB images using AWT Image.
since
JMF 2.0

Fields Summary
private static final String
MyName
Variables and Constants
private transient Vector
cacheInputData
private transient Vector
cacheInputImage
private transient Vector
cacheOutputImage
private transient Image
lastImage
private RGBFormat
supportedRGB
private RGBFormat
supportedOther
private transient int
lastWidth
private transient int
lastHeight
private Blitter
blitter
public static String
vendor
public static boolean
runningOnMac
Constructors Summary
public AWTRenderer()
Constructor


     
	try {
	    vendor = System.getProperty("java.vendor");
	    if (vendor != null) {
		vendor = vendor.toUpperCase();
		if (vendor.startsWith("APPLE")) {
		    runningOnMac = true;
		}
	    }
	} catch (Throwable e) {
	    // Non-fatal error.  No need to do anything.
	}
    
	this(MyName);
    
public AWTRenderer(String name)

	super(name);
	
	// Prepare supported input formats and preferred format
	int rMask, gMask, bMask;
	if ((Arch.getArch() & Arch.SOLARIS) != 0 && !runningOnMac) {
	    rMask = 0x000000FF;
	    gMask = 0x0000FF00;
	    bMask = 0x00FF0000;
	} else {
	    bMask = 0x000000FF;
	    gMask = 0x0000FF00;
	    rMask = 0x00FF0000;
	}

	supportedRGB = new RGBFormat(null, Format.NOT_SPECIFIED,
				     Format.intArray,
				     Format.NOT_SPECIFIED, // frame rate
				     32,
				     rMask, gMask, bMask,
				     1, Format.NOT_SPECIFIED,
				     Format.FALSE, // flipped
				     Format.NOT_SPECIFIED // endian
				     );
	supportedOther = new RGBFormat(null, Format.NOT_SPECIFIED,
				       Format.intArray,
				       Format.NOT_SPECIFIED, // frame rate
				       32,
				       bMask, gMask, rMask,
				       1, Format.NOT_SPECIFIED,
				       Format.FALSE, // flipped
				       Format.NOT_SPECIFIED // endian
				       );

	supportedFormats = new VideoFormat[2];
	supportedFormats[0] = supportedRGB;
	supportedFormats[1] = supportedOther;

	// Setting ColorModel does not really work on the Mac.
	// So there's only one format supported by the Mac.
	if (runningOnMac)
	    supportedFormats[1] = supportedRGB;

	try {
	    Class cls = Class.forName("com.sun.media.renderer.video.Java2DRenderer");
	    blitter = (Blitter) cls.newInstance();
	    //blitter.setRenderer(this);
	} catch (Throwable t) {
	    if (t instanceof ThreadDeath)
		throw (ThreadDeath) t;
	    blitter = this;
	}
    
Methods Summary
protected synchronized intdoProcess(javax.media.Buffer buffer)
Processes the data and renders it to the output device represented by this renderer.

	if (component == null)
	    return BUFFER_PROCESSED_OK;
	if (!buffer.getFormat().equals(inputFormat)) {
	    Format in = buffer.getFormat();
	    if (matches(in, supportedFormats) == null)
		return BUFFER_PROCESSED_FAILED;
	    else {
		inputFormat = (RGBFormat) in;
	    }
	}
	Object data = buffer.getData();
	if (!(data instanceof int[]))
	    return BUFFER_PROCESSED_FAILED;

	int cacheSize = cacheInputData.size();
	int i;
	boolean found = false;
	for (i = 0; i < cacheSize; ++i) {
	    Object bufKnown = cacheInputData.elementAt(i);
	    if (bufKnown == data) {
		found = true;
		break;
	    }
	}

	// Data not cached? Add to the cache and create a new Image wrapper.
	if (!found)
	    i = blitter.newData(buffer,
				cacheInputImage,
				cacheOutputImage,
				cacheInputData);

	// Couldn't create Image
	if (i < 0)
	    return BUFFER_PROCESSED_FAILED;
	RGBFormat format = (RGBFormat)buffer.getFormat();
	Dimension size = format.getSize();
	inWidth = size.width;
	inHeight = size.height;
	if (outWidth == -1)
	    outWidth = size.width;
	if (outHeight == -1)
	    outHeight = size.height;

	lastImage = blitter.process(buffer,
				    cacheInputImage.elementAt(i),
				    cacheOutputImage.elementAt(i),
				    size);

	
	lastWidth = size.width;
	lastHeight = size.height;

	if (!isLightWeight()) {
	    Graphics g = component.getGraphics();
	    if (g != null) {
		blitter.draw(g, component, lastImage, 0, 0, outWidth, outHeight,
			     0, 0, size.width, size.height);
	    }
	} else {
	    component.repaint();
	}
	return BUFFER_PROCESSED_OK;
    
public 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 (g != null)
	    g.drawImage(lastImage, dx, dy, dw, dh,
			sx, sy, sw, sh, component);
    
public java.awt.ComponentgetComponent()
Returns an AWT component that it will render to. Returns null if it is not rendering to an AWT component.

	if (component == null) {
	    if (isLightWeight()) {
		component = new LightComponent();
		component.setBackground(getPreferredBackground());
		if (compListener == null)
		    compListener = new CompListener();
		component.addComponentListener(compListener);
	    } else
		component = super.getComponent();
	}
	return component;
    
public booleanisLightWeight()

	return false;
    
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();

	DirectColorModel dcm = new DirectColorModel(format.getBitsPerPixel(),
						    format.getRedMask(),
						    format.getGreenMask(),
						    format.getBlueMask());

	MemoryImageSource sourceImage = new MemoryImageSource(format.getLineStride(),
							      format.getSize().height,
							      dcm,
							      (int[])data, 0,
							      format.getLineStride());
	sourceImage.setAnimated(true);
	sourceImage.setFullBufferUpdates(true);
	Image destImage = null;
	if (component != null) {
	    destImage = component.createImage(sourceImage);
	    component.prepareImage(destImage, component);
	}
	cacheOutputImage.addElement(destImage);
	cacheInputData.addElement(data);
	cacheInputImage.addElement(sourceImage);
	return cacheInputImage.size() - 1;
    
public voidopen()
Opens the plug-in software or hardware component and acquires necessary resources. If all the needed resources could not be acquired, it throws a ResourceUnavailableException. Data should not be passed into the plug-in without first calling this method.

	cacheInputData = new Vector();
	cacheInputImage = new Vector();
	cacheOutputImage = new Vector();
    
public voidpaint(java.awt.Graphics g)

	if (g != null && lastImage != null) 
	    blitter.draw(g, component, lastImage, 0, 0, outWidth, outHeight,
			 0, 0, lastWidth, lastHeight);
    
public java.awt.Imageprocess(javax.media.Buffer buffer, java.lang.Object cacheInputImage, java.lang.Object cacheOutputImage, java.awt.Dimension size)
Blitter methods


	MemoryImageSource sourceImage = (MemoryImageSource)cacheInputImage;    
	Image lastImage = (Image) cacheOutputImage;
	sourceImage.newPixels(0, 0, size.width, size.height);
	return lastImage;
    
protected voidrepaint()

	if (!isStarted() && lastImage != null) {
	    Graphics g = component.getGraphics();
	    blitter.draw(g, component, lastImage, 0, 0, outWidth, outHeight,
			 0, 0, lastWidth, lastHeight);
	}
    
public synchronized voidreset()
Resets the state of the plug-in. Typically at end of media or when media is repositioned.

	cacheInputData = new Vector();
	cacheInputImage = new Vector();
	cacheOutputImage = new Vector();	
    
public synchronized voidresized(java.awt.Component c)

	super.resized(c);
	if (blitter != this)
	    blitter.resized(c);
    
public javax.media.FormatsetInputFormat(javax.media.Format format)
Set the data input format.

return
false if the format is not supported.

	if (super.setInputFormat(format) != null) {
	    reset();
	    return format;
	} else
	    return null;