001: package org.apollo.effect.old;
002:
003: import java.awt.image.BufferedImage;
004: import java.awt.image.ConvolveOp;
005: import java.awt.image.DataBuffer;
006: import java.awt.image.DataBufferInt;
007: import java.awt.image.Kernel;
008: import java.io.IOException;
009: import java.util.ArrayList;
010: import java.util.Collections;
011: import java.util.List;
012:
013: import javax.media.Buffer;
014: import javax.media.Effect;
015: import javax.media.PlugInManager;
016:
017: import org.apollo.ApolloMediaCore;
018: import org.apollo.effect.IVideoEffect;
019:
020: /**
021: * Effect apply a simple convolve operation
022: *
023: * @author Giovane.Kuhn on 06/04/2005
024: */
025: public final class SimpleEdgeEffect extends ApolloMediaCore implements
026: Effect, IVideoEffect {
027:
028: /** Effect name */
029: private static final String NAME = "Simple edge effect";
030:
031: private static final List<String> PROPERTY_NAMES;
032:
033: /** Operation to detect edge */
034: private static final ConvolveOp EDGE_OP = new ConvolveOp(
035: new Kernel(3, 3, new float[] { 0, -1, 0, -1, 4, -1, 0, -1,
036: 0 }));
037:
038: static {
039: // properties
040: List<String> list = new ArrayList<String>();
041: PROPERTY_NAMES = Collections.unmodifiableList(list);
042:
043: // register
044: PlugInManager.addPlugIn( //
045: SimpleEdgeEffect.class.getName(), //
046: SUPPORTED_FORMATS, //
047: SUPPORTED_FORMATS, //
048: PlugInManager.EFFECT //
049: );
050: try {
051: PlugInManager.commit();
052: } catch (IOException e) {
053: throw new RuntimeException(e);
054: }
055: }
056:
057: public SimpleEdgeEffect() {
058: // nop
059: }
060:
061: /* instance methods */
062: public List<String> getProperties() {
063: return PROPERTY_NAMES;
064: }
065:
066: public String getName() {
067: return NAME;
068: }
069:
070: public int process(Buffer inputBuffer, Buffer outputBuffer) {
071: long start = System.currentTimeMillis();
072: assert inputFormat.matches(inputBuffer.getFormat());
073: assert outputFormat != null;
074:
075: // input data
076: int[] in = (int[]) inputBuffer.getData();
077: int inLength = inputBuffer.getLength();
078: int inOffset = inputBuffer.getOffset();
079:
080: // update output buffer properties
081: outputBuffer.setFormat(outputFormat);
082: outputBuffer.setLength(inLength);
083: outputBuffer.setOffset(inOffset);
084: if (inLength == 0) {
085: outputBuffer.setData(in);
086: return BUFFER_PROCESSED_OK;
087: }
088:
089: // create buffer image
090: DataBufferInt db = new DataBufferInt(in, inLength, 0);
091: BufferedImage bi = createBufferedImage(db);
092:
093: // convolve operation
094: bi = EDGE_OP.filter(bi, null);
095:
096: // set output buffer data
097: assert bi.getData().getDataBuffer().getDataType() == DataBuffer.TYPE_INT;
098: db = (DataBufferInt) bi.getData().getDataBuffer();
099: outputBuffer.setData(db.getData());
100:
101: System.out.println("[" + this .getClass().getSimpleName()
102: + "] #" + inputBuffer.getSequenceNumber() + " in "
103: + (System.currentTimeMillis() - start) + "ms.");
104: return BUFFER_PROCESSED_OK;
105: }
106: }
|