鬼影特效:

package functions;import javax.media.*;
import javax.media.Effect;
import javax.media.format.*;
import javax.media.Buffer;
import javax.media.ResourceUnavailableException;public class NegativeEffect implements Effect {private static String EffectName = "NegativeEffect"; // 类名protected RGBFormat inputFormat; // 输入的RGB 色彩格式protected RGBFormat outputFormat; // 输出的RGB 色彩格式protected Format[] supportedInputFormats; // 所有支持的输入格式protected Format[] supportedOutputFormats; // 所有支持的输出格式// 构造方法,实例化所有支持的输入输出色彩为RGB 色彩格式public NegativeEffect() {supportedInputFormats = new Format[] { new RGBFormat() };supportedOutputFormats = new Format[] { new RGBFormat() };}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输入格式public Format[] getSupportedInputFormats() {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// getSupportedInputFormats() not yet implemented.");System.out.println("getSupportedInputFormats");return supportedInputFormats;}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输出格式public Format[] getSupportedOutputFormats(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// getSupportedOutputFormats() not yet implemented.");System.out.println("getSupportedOutputFormats [in = " + parm1 + "]");// 如果传入的Format 对象parm1 不是GRBFormat 实例,则返回默认的RGBFormat 格式对象if (parm1 == null)return supportedOutputFormats;if (!(parm1 instanceof RGBFormat))return new Format[0];// 如果是,根据该格式返回一个对象引用RGBFormat irf = (RGBFormat) parm1;RGBFormat orf = (RGBFormat) parm1.clone();return new Format[] { orf };}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setInputFormat(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// setInputFormat() not yet implemented.");System.out.println("setInputFormat [input = " + parm1 + "]");inputFormat = (RGBFormat) parm1;return (Format) inputFormat;}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setOutputFormat(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// setOutputFormat() not yet implemented.");System.out.println("setOutputFormat [ output = " + parm1 + "]");outputFormat = (RGBFormat) parm1;return (Format) outputFormat;}// 不一定要实现的两个方法,仅仅满足getXXX,setXXX 的对称性public Format getInputFormat() {System.out.println("getInputFormat");return inputFormat;}public Format getOutputFormat() {System.out.println("getOutputFormat");return outputFormat;}// 实现Effect 接口继承自Codec 的方法,处理输入的媒体数据parm1,得到经处理的输出的媒体数据parm2// 该方法完成本类的效用,处理媒体数据,达到使色彩反色输出的处理效果// 是本类的核心方法public int process(Buffer parm1, Buffer parm2) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method process()// not yet implemented.");Object o1 = parm1.getData(); // 获得输入的数据对象的引用int inLength = parm1.getLength(); // 输入的数据的长度int inOffset = parm1.getOffset(); // 偏移量// 如果输入输出的媒体数据非合法的short[] int[]形式,返回出错信息if (!(o1 instanceof short[]) && !(o1 instanceof int[])&& !(o1 instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;Object o2 = parm2.getData();if (o2 != null) {if (!(o2 instanceof short[]) && !(o2 instanceof int[])&& !(o1 instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;} else {// 根据输入的数据长度,设置输出的数据长度if (o1 instanceof short[])parm2.setData(new short[inLength]);else if (o1 instanceof int[])parm2.setData(new int[inLength]);elseparm2.setData(new byte[inLength]);o2 = parm2.getData();}// 根据输入的数据偏移量,设置输出的数据偏移量int outOffset = parm2.getOffset();if (o1 instanceof short[]) {short[] inData = (short[]) o1;short[] outData = (short[]) o2;// 处理输入的媒体数据,似的色彩反色,并将数据放入输出的媒体数据对象中for (int i = 0; i < inLength; i++)outData[outOffset++] = (short) ~inData[inOffset++];} else if (o1 instanceof int[]){int[] inData = (int[]) o1;int[] outData = (int[]) o2;for (int i = 0; i < inLength; i++)outData[outOffset++] = ~inData[inOffset++];}else {byte[] inData = (byte[]) o1;byte[] outData = (byte[]) o2;for (int i = 0; i < inLength; i++)outData[outOffset++] = (byte)~inData[inOffset++];}// 设置输出媒体数据的格式parm2.setFormat(outputFormat);// 设置输出媒体数据的长度和偏移parm2.setLength(inLength);parm2.setOffset(0);// 返回数据处理成功完成信息return this.BUFFER_PROCESSED_OK;}// 返回类名public String getName() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method getName()// not yet implemented.");System.out.println("getName");return EffectName;}// 以下的方法不一定要求实现,这些方法是Effect 接口的父类的上层类// 如javax.media.Controls、javax.media.PlugIn 的方法public void open() throws javax.media.ResourceUnavailableException {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method open() not// yet implemented.");System.out.println("open");}public void close() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method close() not// yet implemented.");System.out.println("close");}public void reset() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method reset() not// yet implemented.");System.out.println("reset");}public Object[] getControls() {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControls() not yet implemented.");System.out.println("getControls");return new Controls[0];}public Object getControl(String parm1) {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControl() not yet implemented.");System.out.println("getControl [controlType = " + parm1 + "]");try {Class cls = Class.forName(parm1);Object[] cs = this.getControls();for (int i = 0; i < cs.length; i++) {if (cls.isInstance(cs[i])) {return cs[i];}}return null;} catch (Exception err) {return null;}}
}

中心内凹特效:

package functions;import java.awt.Dimension;import javax.media.*;
import javax.media.format.*;
/*** * @author hp* 只支持RGB,每个分量用一个8位字节* 视频流是byte数组*/
public class HahajingEffect implements Effect {private static String EffectName = "HahajingEffect"; // 类名protected RGBFormat inputFormat; // 输入的色彩格式protected RGBFormat outputFormat; // 输出的色彩格式protected Format[] supportedInputFormats; // 所有支持的输入格式protected Format[] supportedOutputFormats; // 所有支持的输出格式// 构造方法,实例化所有支持的输入输出色彩为RGB 色彩格式public HahajingEffect() {supportedInputFormats = new Format[] { new RGBFormat()};supportedOutputFormats = new Format[] { new RGBFormat() };}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输入格式public Format[] getSupportedInputFormats() {return supportedInputFormats;}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输出格式public Format[] getSupportedOutputFormats(Format parm1) {if (parm1 == null)return supportedOutputFormats;if (!(parm1 instanceof RGBFormat))return new Format[0];// 如果是,根据该格式返回一个对象引用RGBFormat orf = (RGBFormat) parm1.clone();return new Format[] { orf };}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setInputFormat(Format parm1) {System.out.println("setInputFormat [input = " + parm1 + "]");inputFormat = (RGBFormat) parm1;return (Format) inputFormat;}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setOutputFormat(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// setOutputFormat() not yet implemented.");System.out.println("setOutputFormat [ output = " + parm1 + "]");outputFormat = (RGBFormat) parm1;return (Format) outputFormat;}// 不一定要实现的两个方法,仅仅满足getXXX,setXXX 的对称性public Format getInputFormat() {System.out.println("getInputFormat");return inputFormat;}public Format getOutputFormat() {System.out.println("getOutputFormat");return outputFormat;}// 实现Effect 接口继承自Codec 的方法,处理输入的媒体数据parm1,得到经处理的输出的媒体数据parm2// 该方法完成本类的效用,处理媒体数据,// 是本类的核心方法public int process(Buffer parm1, Buffer parm2) {// this.setInputFormat(parm1.getFormat()); // 设置输入格式// this.setOutputFormat(parm1.getFormat());// 获取输入格式的视频分辨率Dimension size = ((VideoFormat) parm1.getFormat()).getSize();int inWidth = size.width;int inHeight = size.height;Object srcData = parm1.getData(); // 获得输入的数据对象的引用// System.out.println(srcData.getClass().toString());// 如果输入输出的媒体数据非合法的short[] int[]形式,返回出错信息if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;Object outputData = null; // parm2.getData();if (outputData != null) {if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;}outputData = this.hahajingMirror((byte[]) srcData, 0.0, inWidth, inHeight, inWidth / 2, inHeight / 2);parm2.setData(outputData);int inLength = parm1.getLength(); // 输入的数据的长度int inOffset = parm1.getOffset(); // 偏移量// 设置输出媒体数据的格式parm2.setFormat(parm1.getFormat());// 设置输出媒体数据的长度和偏移parm2.setLength(inLength);parm2.setOffset(inOffset);// 返回数据处理成功完成信息return this.BUFFER_PROCESSED_OK;}// 返回类名public String getName() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method getName()// not yet implemented.");System.out.println("getName");return EffectName;}// 以下的方法不一定要求实现,这些方法是Effect 接口的父类的上层类// 如javax.media.Controls、javax.media.PlugIn 的方法public void open() throws javax.media.ResourceUnavailableException {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method open() not// yet implemented.");System.out.println("open");}public void close() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method close() not// yet implemented.");System.out.println("close");}public void reset() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method reset() not// yet implemented.");System.out.println("reset");}public Object[] getControls() {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControls() not yet implemented.");System.out.println("getControls");return new Controls[0];}public Object getControl(String parm1) {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControl() not yet implemented.");System.out.println("getControl [controlType = " + parm1 + "]");try {Class cls = Class.forName(parm1);Object[] cs = this.getControls();for (int i = 0; i < cs.length; i++) {if (cls.isInstance(cs[i])) {return cs[i];}}return null;} catch (Exception err) {return null;}}private byte[] hahajingMirror(byte[] srcData, double factor, int w, int h, int x, int y) {int cenX = x;int cenY = y;int newX = 0;//新坐标int newY = 0;int offsetX = 0;int offsetY = 0;int radius = 0;double theta = 0;byte[] tempData = (byte[]) srcData.clone();int length = srcData.length;for (int j = 0; j < h; j++) {for (int i = 0; i < w; i++) {int tX = i - cenX;int tY = j - cenY;theta = Math.atan2((double) tY, (double) tX);radius = (int) Math.sqrt((double) (tX * tX + tY * tY));int newR = (int) (Math.sqrt((double) radius) * 12);newX = cenX + (int) (newR * Math.cos(theta));newY = cenY + (int) (newR * Math.sin(theta));if (newX > 0 && newX < w) {offsetX = newX;} else {newX = 0;}if (newY > 0 && newY < h) {offsetY = newY;} else {newY = 0;}int tempLocation1 = i * 3 + j * w * 3;int tempLocation2 = i * 3 + 1 + j * w * 3;int tempLocation3 = i * 3 + 2 + j * w * 3;int srcLocation1 = newX * 3 + newY * w * 3;int srcLocation2 = newX * 3 + 1 + newY * w * 3;int srcLocation3 = newX * 3 + 2 + newY * w * 3;if ((tempLocation1 <= length)&& (tempLocation2 <= length) && (tempLocation3 <= length)&& (srcLocation1 <= length) && (srcLocation2 <= length) && (srcLocation3 <= length)) {                tempData[tempLocation1] = srcData[srcLocation1];tempData[tempLocation2] = srcData[srcLocation2];tempData[tempLocation3] = srcData[srcLocation3];}}}return tempData;}}

纵向拉长特效:

package functions;
import java.awt.Dimension;import javax.media.*;
import javax.media.format.*;
/*** * @author hp* 只支持RGB,每个分量用一个8位字节* 视频流是byte数组*/
public class HahajingEffect2 implements Effect  {private static String EffectName = "HahajingEffect"; // 类名protected RGBFormat inputFormat; // 输入的色彩格式protected RGBFormat outputFormat; // 输出的色彩格式protected Format[] supportedInputFormats; // 所有支持的输入格式protected Format[] supportedOutputFormats; // 所有支持的输出格式// 构造方法,实例化所有支持的输入输出色彩为RGB 色彩格式public HahajingEffect2() {supportedInputFormats = new Format[] { new RGBFormat()};supportedOutputFormats = new Format[] { new RGBFormat() };}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输入格式public Format[] getSupportedInputFormats() {return supportedInputFormats;}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输出格式public Format[] getSupportedOutputFormats(Format parm1) {if (parm1 == null)return supportedOutputFormats;if (!(parm1 instanceof RGBFormat))return new Format[0];// 如果是,根据该格式返回一个对象引用RGBFormat orf = (RGBFormat) parm1.clone();return new Format[] { orf };}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setInputFormat(Format parm1) {System.out.println("setInputFormat [input = " + parm1 + "]");inputFormat = (RGBFormat) parm1;return (Format) inputFormat;}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setOutputFormat(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// setOutputFormat() not yet implemented.");System.out.println("setOutputFormat [ output = " + parm1 + "]");outputFormat = (RGBFormat) parm1;return (Format) outputFormat;}// 不一定要实现的两个方法,仅仅满足getXXX,setXXX 的对称性public Format getInputFormat() {System.out.println("getInputFormat");return inputFormat;}public Format getOutputFormat() {System.out.println("getOutputFormat");return outputFormat;}// 实现Effect 接口继承自Codec 的方法,处理输入的媒体数据parm1,得到经处理的输出的媒体数据parm2// 该方法完成本类的效用,处理媒体数据,// 是本类的核心方法public int process(Buffer parm1, Buffer parm2) {// this.setInputFormat(parm1.getFormat()); // 设置输入格式// this.setOutputFormat(parm1.getFormat());// 获取输入格式的视频分辨率Dimension size = ((VideoFormat) parm1.getFormat()).getSize();int inWidth = size.width;int inHeight = size.height;Object srcData = parm1.getData(); // 获得输入的数据对象的引用// System.out.println(srcData.getClass().toString());// 如果输入输出的媒体数据非合法的short[] int[]形式,返回出错信息if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;Object outputData = null; // parm2.getData();if (outputData != null) {if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;}outputData = this.hahajingMirror((byte[]) srcData, inWidth, inHeight);parm2.setData(outputData);int inLength = parm1.getLength(); // 输入的数据的长度int inOffset = parm1.getOffset(); // 偏移量// 设置输出媒体数据的格式parm2.setFormat(parm1.getFormat());// 设置输出媒体数据的长度和偏移parm2.setLength(inLength);parm2.setOffset(inOffset);// 返回数据处理成功完成信息return this.BUFFER_PROCESSED_OK;}// 返回类名public String getName() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method getName()// not yet implemented.");System.out.println("getName");return EffectName;}// 以下的方法不一定要求实现,这些方法是Effect 接口的父类的上层类// 如javax.media.Controls、javax.media.PlugIn 的方法public void open() throws javax.media.ResourceUnavailableException {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method open() not// yet implemented.");System.out.println("open");}public void close() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method close() not// yet implemented.");System.out.println("close");}public void reset() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method reset() not// yet implemented.");System.out.println("reset");}public Object[] getControls() {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControls() not yet implemented.");System.out.println("getControls");return new Controls[0];}public Object getControl(String parm1) {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControl() not yet implemented.");System.out.println("getControl [controlType = " + parm1 + "]");try {Class cls = Class.forName(parm1);Object[] cs = this.getControls();for (int i = 0; i < cs.length; i++) {if (cls.isInstance(cs[i])) {return cs[i];}}return null;} catch (Exception err) {return null;}}private byte[] hahajingMirror(byte[] srcData, int w, int h) {int oldX = 0;int oldY = 0;byte[] tempData = (byte[]) srcData.clone();int length = srcData.length;for (int j = 0; j < h; j++) {for (int i = 0; i < w; i++) {oldX = i;//x坐标不变oldY = j/6;//旧的坐标是新y坐标的1/6int tempLocation1 = i * 3 + j * w * 3;int tempLocation2 = i * 3 + 1 + j * w * 3;int tempLocation3 = i * 3 + 2 + j * w * 3;int srcLocation1 = oldX * 3 + oldY * w * 3;int srcLocation2 = oldX * 3 + 1 + oldY * w * 3;int srcLocation3 = oldX * 3 + 2 + oldY * w * 3;if ((tempLocation1 <= length)&& (tempLocation2 <= length) && (tempLocation3 <= length)&& (srcLocation1 <= length) && (srcLocation2 <= length) && (srcLocation3 <= length)) {              tempData[tempLocation1] = srcData[srcLocation1];tempData[tempLocation2] = srcData[srcLocation2];tempData[tempLocation3] = srcData[srcLocation3];}}}return tempData;}
}

中轴外凸特效:

package functions;import java.awt.Dimension;import javax.media.*;
import javax.media.format.*;
/*** * @author hp* 只支持RGB,每个分量用一个8位字节* 视频流是byte数组*/
public class HahajingEffect3 implements Effect {private static String EffectName = "HahajingEffect"; // 类名protected RGBFormat inputFormat; // 输入的色彩格式protected RGBFormat outputFormat; // 输出的色彩格式protected Format[] supportedInputFormats; // 所有支持的输入格式protected Format[] supportedOutputFormats; // 所有支持的输出格式// 构造方法,实例化所有支持的输入输出色彩为RGB 色彩格式public HahajingEffect3() {supportedInputFormats = new Format[] { new RGBFormat()};supportedOutputFormats = new Format[] { new RGBFormat() };}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输入格式public Format[] getSupportedInputFormats() {return supportedInputFormats;}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输出格式public Format[] getSupportedOutputFormats(Format parm1) {if (parm1 == null)return supportedOutputFormats;if (!(parm1 instanceof RGBFormat))return new Format[0];// 如果是,根据该格式返回一个对象引用RGBFormat orf = (RGBFormat) parm1.clone();return new Format[] { orf };}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setInputFormat(Format parm1) {System.out.println("setInputFormat [input = " + parm1 + "]");inputFormat = (RGBFormat) parm1;return (Format) inputFormat;}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setOutputFormat(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// setOutputFormat() not yet implemented.");System.out.println("setOutputFormat [ output = " + parm1 + "]");outputFormat = (RGBFormat) parm1;return (Format) outputFormat;}// 不一定要实现的两个方法,仅仅满足getXXX,setXXX 的对称性public Format getInputFormat() {System.out.println("getInputFormat");return inputFormat;}public Format getOutputFormat() {System.out.println("getOutputFormat");return outputFormat;}// 实现Effect 接口继承自Codec 的方法,处理输入的媒体数据parm1,得到经处理的输出的媒体数据parm2// 该方法完成本类的效用,处理媒体数据,// 是本类的核心方法public int process(Buffer parm1, Buffer parm2) {// this.setInputFormat(parm1.getFormat()); // 设置输入格式// this.setOutputFormat(parm1.getFormat());// 获取输入格式的视频分辨率Dimension size = ((VideoFormat) parm1.getFormat()).getSize();int inWidth = size.width;int inHeight = size.height;Object srcData = parm1.getData(); // 获得输入的数据对象的引用// System.out.println(srcData.getClass().toString());// 如果输入输出的媒体数据非合法的short[] int[]形式,返回出错信息if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;Object outputData = null; // parm2.getData();if (outputData != null) {if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;}outputData = this.hahajingMirror((byte[]) srcData, 0.0, inWidth, inHeight, inWidth / 2, inHeight / 2);parm2.setData(outputData);int inLength = parm1.getLength(); // 输入的数据的长度int inOffset = parm1.getOffset(); // 偏移量// 设置输出媒体数据的格式parm2.setFormat(parm1.getFormat());// 设置输出媒体数据的长度和偏移parm2.setLength(inLength);parm2.setOffset(inOffset);// 返回数据处理成功完成信息return this.BUFFER_PROCESSED_OK;}// 返回类名public String getName() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method getName()// not yet implemented.");System.out.println("getName");return EffectName;}// 以下的方法不一定要求实现,这些方法是Effect 接口的父类的上层类// 如javax.media.Controls、javax.media.PlugIn 的方法public void open() throws javax.media.ResourceUnavailableException {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method open() not// yet implemented.");System.out.println("open");}public void close() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method close() not// yet implemented.");System.out.println("close");}public void reset() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method reset() not// yet implemented.");System.out.println("reset");}public Object[] getControls() {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControls() not yet implemented.");System.out.println("getControls");return new Controls[0];}public Object getControl(String parm1) {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControl() not yet implemented.");System.out.println("getControl [controlType = " + parm1 + "]");try {Class cls = Class.forName(parm1);Object[] cs = this.getControls();for (int i = 0; i < cs.length; i++) {if (cls.isInstance(cs[i])) {return cs[i];}}return null;} catch (Exception err) {return null;}}private byte[] hahajingMirror(byte[] srcData, double factor, int w, int h, int x, int y) {int cenX = x;int cenY = y;int newX = 0;int newY = 0;int R=(int) (Math.sqrt(h*h+w*w)/2);int radius = 0;byte[] tempData = (byte[]) srcData.clone();int length = srcData.length;for (int j = 0; j < h; j++) {for (int i = 0; i < w; i++) {int tX = i - cenX;int tY = j - cenY;radius = (int) Math.sqrt((double) (tX * tX +tY*tY ));if(radius<R) {newX=cenX+tX*radius/R;newY=cenY+tY*radius/R;}int tempLocation1 = i * 3 + j * w * 3;int tempLocation2 = i * 3 + 1 + j * w * 3;int tempLocation3 = i * 3 + 2 + j * w * 3;int srcLocation1 = newX * 3 + newY * w * 3;int srcLocation2 = newX * 3 + 1 + newY * w * 3;int srcLocation3 = newX * 3 + 2 + newY * w * 3;if ((tempLocation1 <= length)&& (tempLocation2 <= length) && (tempLocation3 <= length)&& (srcLocation1 <= length) && (srcLocation2 <= length) && (srcLocation3 <= length)) {              tempData[tempLocation1] = srcData[srcLocation1];tempData[tempLocation2] = srcData[srcLocation2];tempData[tempLocation3] = srcData[srcLocation3];}}}return tempData;}}

复合特效:

package functions;import java.awt.Dimension;import javax.media.*;
import javax.media.format.*;
/*** * @author hp* 只支持RGB,每个分量用一个8位字节* 视频流是byte数组*/
public class HahajingEffect4 implements Effect {private static String EffectName = "HahajingEffect"; // 类名protected RGBFormat inputFormat; // 输入的色彩格式protected RGBFormat outputFormat; // 输出的色彩格式protected Format[] supportedInputFormats; // 所有支持的输入格式protected Format[] supportedOutputFormats; // 所有支持的输出格式// 构造方法,实例化所有支持的输入输出色彩为RGB 色彩格式public HahajingEffect4() {supportedInputFormats = new Format[] { new RGBFormat()};supportedOutputFormats = new Format[] { new RGBFormat() };}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输入格式public Format[] getSupportedInputFormats() {return supportedInputFormats;}// 实现Effect 接口继承自Codec 的方法,返回所有支持的输出格式public Format[] getSupportedOutputFormats(Format parm1) {if (parm1 == null)return supportedOutputFormats;if (!(parm1 instanceof RGBFormat))return new Format[0];// 如果是,根据该格式返回一个对象引用RGBFormat orf = (RGBFormat) parm1.clone();return new Format[] { orf };}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setInputFormat(Format parm1) {System.out.println("setInputFormat [input = " + parm1 + "]");inputFormat = (RGBFormat) parm1;return (Format) inputFormat;}// 实现Effect 接口继承自Codec 的方法,返回传入的数据格式public Format setOutputFormat(Format parm1) {/** @todo Implement this javax.media.Codec method */// throw new java.lang.UnsupportedOperationException("Method// setOutputFormat() not yet implemented.");System.out.println("setOutputFormat [ output = " + parm1 + "]");outputFormat = (RGBFormat) parm1;return (Format) outputFormat;}// 不一定要实现的两个方法,仅仅满足getXXX,setXXX 的对称性public Format getInputFormat() {System.out.println("getInputFormat");return inputFormat;}public Format getOutputFormat() {System.out.println("getOutputFormat");return outputFormat;}// 实现Effect 接口继承自Codec 的方法,处理输入的媒体数据parm1,得到经处理的输出的媒体数据parm2// 该方法完成本类的效用,处理媒体数据,// 是本类的核心方法public int process(Buffer parm1, Buffer parm2) {// this.setInputFormat(parm1.getFormat()); // 设置输入格式// this.setOutputFormat(parm1.getFormat());// 获取输入格式的视频分辨率Dimension size = ((VideoFormat) parm1.getFormat()).getSize();int inWidth = size.width;int inHeight = size.height;Object srcData = parm1.getData(); // 获得输入的数据对象的引用// System.out.println(srcData.getClass().toString());// 如果输入输出的媒体数据非合法的short[] int[]形式,返回出错信息if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;Object outputData = null; // parm2.getData();if (outputData != null) {if (!(srcData instanceof byte[]))return this.BUFFER_PROCESSED_FAILED;}outputData = this.hahajingMirror((byte[]) srcData, 0.0, inWidth, inHeight, inWidth / 2, inHeight / 2);parm2.setData(outputData);int inLength = parm1.getLength(); // 输入的数据的长度int inOffset = parm1.getOffset(); // 偏移量// 设置输出媒体数据的格式parm2.setFormat(parm1.getFormat());// 设置输出媒体数据的长度和偏移parm2.setLength(inLength);parm2.setOffset(inOffset);// 返回数据处理成功完成信息return this.BUFFER_PROCESSED_OK;}// 返回类名public String getName() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method getName()// not yet implemented.");System.out.println("getName");return EffectName;}// 以下的方法不一定要求实现,这些方法是Effect 接口的父类的上层类// 如javax.media.Controls、javax.media.PlugIn 的方法public void open() throws javax.media.ResourceUnavailableException {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method open() not// yet implemented.");System.out.println("open");}public void close() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method close() not// yet implemented.");System.out.println("close");}public void reset() {/** @todo Implement this javax.media.PlugIn method */// throw new java.lang.UnsupportedOperationException("Method reset() not// yet implemented.");System.out.println("reset");}public Object[] getControls() {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControls() not yet implemented.");System.out.println("getControls");return new Controls[0];}public Object getControl(String parm1) {/** @todo Implement this javax.media.Controls method */// throw new java.lang.UnsupportedOperationException("Method// getControl() not yet implemented.");System.out.println("getControl [controlType = " + parm1 + "]");try {Class cls = Class.forName(parm1);Object[] cs = this.getControls();for (int i = 0; i < cs.length; i++) {if (cls.isInstance(cs[i])) {return cs[i];}}return null;} catch (Exception err) {return null;}}private byte[] hahajingMirror(byte[] srcData, double factor, int w, int h, int x, int y) {int cenX = x;int cenY = y;int newX = 0;int newY = 0;int R=(int) (Math.sqrt(h*h+w*w)/2);int offsetX = 0;int offsetY = 0;int radius = 0;double theta = 0;byte[] tempData = (byte[]) srcData.clone();int length = srcData.length;for (int j = 0; j < h; j++) {for (int i = 0; i < w/2; i++) {int tX = i - cenX;int tY = j - cenY;theta = Math.atan2((double) tY, (double) tX);radius = (int) Math.sqrt((double) (tX * tX + tY * tY));int newR = (int) (Math.sqrt((double) radius) * 12);newX = cenX + (int) (newR * Math.cos(theta));newY = cenY + (int) (newR * Math.sin(theta));if (newX > 0 && newX < w) {offsetX = newX;} else {newX = 0;}if (newY > 0 && newY < h) {offsetY = newY;} else {newY = 0;}int tempLocation1 = i * 3 + j * w * 3;int tempLocation2 = i * 3 + 1 + j * w * 3;int tempLocation3 = i * 3 + 2 + j * w * 3;int srcLocation1 = newX * 3 + newY * w * 3;int srcLocation2 = newX * 3 + 1 + newY * w * 3;int srcLocation3 = newX * 3 + 2 + newY * w * 3;if ((tempLocation1 <= length)&& (tempLocation2 <= length) && (tempLocation3 <= length)&& (srcLocation1 <= length) && (srcLocation2 <= length) && (srcLocation3 <= length)) {                tempData[tempLocation1] = srcData[srcLocation1];tempData[tempLocation2] = srcData[srcLocation2];tempData[tempLocation3] = srcData[srcLocation3];}}}for (int j = 0; j < h; j++) {for (int i = w/2; i < w; i++) {int tX = i - cenX;int tY = j - cenY;radius = (int) Math.sqrt((double) (tX * tX +tY*tY ));if(radius<R) {newX=cenX+tX*radius/R;newY=cenY+tY*radius/R;}int tempLocation1 = i * 3 + j * w * 3;int tempLocation2 = i * 3 + 1 + j * w * 3;int tempLocation3 = i * 3 + 2 + j * w * 3;int srcLocation1 = newX * 3 + newY * w * 3;int srcLocation2 = newX * 3 + 1 + newY * w * 3;int srcLocation3 = newX * 3 + 2 + newY * w * 3;if ((tempLocation1 <= length)&& (tempLocation2 <= length) && (tempLocation3 <= length)&& (srcLocation1 <= length) && (srcLocation2 <= length) && (srcLocation3 <= length)) {                tempData[tempLocation1] = srcData[srcLocation1];tempData[tempLocation2] = srcData[srcLocation2];tempData[tempLocation3] = srcData[srcLocation3];}}}return tempData;}
//  private byte[] hahajingMirror(byte[] srcData, double factor, int w, int h, int x, int y) {
//      int cenX = x;
//      int cenY = y;
//      int newX = 0;
//      int newY = 0;
//        int R=(int) (Math.sqrt(h*h+w*w)/2);
//      int radius = 0;
//      byte[] tempData = (byte[]) srcData.clone();
//      int length = srcData.length;
//      for (int j = 0; j < h; j++) {
//          for (int i = 0; i < w; i++) {
//              int tX = i - cenX;
//              int tY = j - cenY;
//              radius = (int) Math.sqrt((double) (tX * tX +tY*tY ));
//              if(radius<R) {
//                  newX=cenX+tX*radius/R;
//                   newY=cenY+tY*radius/R;
//              }
//
//              int tempLocation1 = i * 3 + j * w * 3;
//              int tempLocation2 = i * 3 + 1 + j * w * 3;
//              int tempLocation3 = i * 3 + 2 + j * w * 3;
//              int srcLocation1 = newX * 3 + newY * w * 3;
//              int srcLocation2 = newX * 3 + 1 + newY * w * 3;
//              int srcLocation3 = newX * 3 + 2 + newY * w * 3;
//              if ((tempLocation1 <= length)&& (tempLocation2 <= length) && (tempLocation3 <= length)
//                      && (srcLocation1 <= length) && (srcLocation2 <= length) && (srcLocation3 <= length)) {
//                  tempData[tempLocation1] = srcData[srcLocation1];
//                  tempData[tempLocation2] = srcData[srcLocation2];
//                  tempData[tempLocation3] = srcData[srcLocation3];
//              }
//          }
//      }
//
//      return tempData;
//
//  }
//
}

由于时间紧,复合特效就简单的把两种特效一边一半显示,感兴趣可以自己修改。

(趣味哈哈镜)图像处理算法的实现相关推荐

  1. FPGA图像处理_OTSU算法的实现(含源码)

      由于图像阈值的直观性和易于实现的性质,使它在图像分割应用中处于中心地位.阈值分割方法实际上是输入图像fff到输出图像ggg的变换,如式所示. g(i,j)={1,f(i,j)>=T0,f(i ...

  2. python边缘检测代码_python Canny边缘检测算法的实现

    图像边缘信息主要集中在高频段,通常说图像锐化或检测边缘,实质就是高频滤波.我们知道微分运算是求信号的变化率,具有加强高频分量的作用.在空域运算中来说,对图像的锐化就是计算微分.对于数字图像的离散信号, ...

  3. 计算机图形学直线线型实验报告,计算机图形学实验报告-直线中点bresenham算法的实现资料.doc...

    计算机图形学实验报告-直线中点bresenham算法的实现资料.doc (10页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 29.90 积分 计算机图形 ...

  4. 基于MATLAB的图像压缩感知 算法的实现

    摘要 获取项目源文件,联系Q:1415736481,可指导毕设,课设 数据压缩技术是提高无线数据传输速度的有效措施之一.传统的数据压缩技术是基于奈奎斯特采样定律进行采样,并根据数据本身的特性降低其冗余 ...

  5. 模糊C均值聚类算法的实现

     模糊C均值聚类算法的实现 研究背景 聚类分析是多元统计分析的一种,也是无监督模式识别的一个重要分支,在模式分类 图像处理和模糊规则处理等众多领域中获得最广泛的应用.它把一个没有类别标记的样本按照 ...

  6. 基于slam的三维重建_实时三维重建算法的实现 基于Kinect与单目视觉SLAM的三维重建.docx...

    实时三维重建算法的实现 基于Kinect与单目视觉SLAM的三维重建 实时三维重建算法的实现--基于Kinect与单目视觉SLAM的三维重建夏文玲1,顾照鹏2,杨唐胜2XIAWenling1,GUZh ...

  7. matlab差分算子的灰度图像边缘检测,图像边缘检测算法的实现及比较研究论文

    内容介绍 原文档由会员 rbntrygd 发布 图像边缘检测算法的实现及比较研究论文 ①页数26 ②字数 11620字 此论文被评选为优秀毕业论文,能保证绝对原创. ③摘要: 边缘检测在图像处理中有着 ...

  8. python canny检测_python Canny边缘检测算法的实现

    图像边缘信息主要集中在高频段,通常说图像锐化或检测边缘,实质就是高频滤波.我们知道微分运算是求信号的变化率,具有加强高频分量的作用.在空域运算中来说,对图像的锐化就是计算微分.对于数字图像的离散信号, ...

  9. 计算机图形学 区域填充,计算机图形学 区域填充算法的实现

    . '. 实验四区域填充算法的实现班级 08信计学号 58 姓名陈瑞雪分数 一.实验目的和要求: 1.掌握区域填充算法基本知识 2.理解区域的表示和类型,能正确区分四连通和八连通的区域 3.了解区域填 ...

最新文章

  1. jenkins部署web项目
  2. ​2012年至今,细数深度学习领域这些年取得的经典成果
  3. linux除了eeprom其他的保存方法,linux的EEPROM的读写控制.doc
  4. Android-HttpURLConnection自己主动管理cookie
  5. 使用dbcp连接池创建进行表的增删改查
  6. seaborn绘图后得到分布参数
  7. oracle sql execute elapsed time,SQL ordered by Elapsed Time 脚本
  8. 单击浏览器右上角的X弹出提示窗口
  9. 一、操作系统——处理机(作业)调度算法:先来先服务算法FCFS、最短作业优先算法SJF(非抢占式)、 最短剩余时间优先算法SRTN(抢占式)、最高响应比优先算法HRRN
  10. 使用ajax提交图片,提交已经注入文件的表单给后台上传图片 使用ajaxsubmit
  11. swiper监听滚动条_swiper Scrollbar滚动条组件详解
  12. ORACLE中Like与Instr模糊查询性能大比拼
  13. shell脚本:批量添加用户,并设置随机字符为密码
  14. Juce-强大的开源类库
  15. r语言和python培训_Python 和R语言
  16. python里的pip list是什么意思_python - 运行pip list,抛出异常,这是什么情况
  17. 一个完美的JS加密和解密程序
  18. Spring 官宣:换掉 JVM!
  19. python:实现Triplets with zero sum零和三元组(附完整源码)
  20. 《卡耐基三部曲》(Yanlz+VR云游戏+Unity+SteamVR+云技术+5G+AI+人性的弱点+人性的优点+语言的突破+术业有专攻+世界观+人生观+价值观+志同道合+不卑不亢+立钻哥哥++==)

热门文章

  1. JAVA反序列化漏洞简单理解
  2. python编译py文件为pyc文件
  3. 全屏游戏中自动切出到桌面的问题解决
  4. 【库存控制技术】方法
  5. 局域网内多台windows设备共用一套键鼠【微软官方】Mouse without Borders 2.2.1.0327
  6. Java正则表达式校验日期
  7. git强制拉取远程项目覆盖本地项目
  8. Java入门第66课——银行卡系统(实现银联接口)
  9. Sql Server2008如何让外网访问自己的数据库
  10. 页面引入百度API报警示问题 A Parser-blocking, cross site (i.e. different eTLD+1) script,