AWTRendererpublic class AWTRenderer extends BasicVideoRenderer implements BlitterRenderer for RGB images using AWT Image. |
Fields Summary |
---|
private static final String | MyNameVariables 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 int | doProcess(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 void | draw(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.Component | getComponent()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 boolean | isLightWeight()
return false;
| public int | newData(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 void | open()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 void | paint(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.Image | process(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 void | repaint()
if (!isStarted() && lastImage != null) {
Graphics g = component.getGraphics();
blitter.draw(g, component, lastImage, 0, 0, outWidth, outHeight,
0, 0, lastWidth, lastHeight);
}
| public synchronized void | reset()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 void | resized(java.awt.Component c)
super.resized(c);
if (blitter != this)
blitter.resized(c);
| public javax.media.Format | setInputFormat(javax.media.Format format)Set the data input format.
if (super.setInputFormat(format) != null) {
reset();
return format;
} else
return null;
|
|