diff --git a/examples/movie/.classpath b/examples/movie/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..bea7a29386f9b3493de0f8c6cfce1fb335681e31 --- /dev/null +++ b/examples/movie/.classpath @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="lib" path="jjmpeg/jjmpeg-0.0/dist/jjmpeg.jar"/> + <classpathentry combineaccessrules="false" kind="src" path="/com.amd.aparapi"/> + <classpathentry kind="output" path="classes"/> +</classpath> diff --git a/examples/movie/.project b/examples/movie/.project new file mode 100644 index 0000000000000000000000000000000000000000..6be55d8ca562f663e59edf2456ac64465cf94d67 --- /dev/null +++ b/examples/movie/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>movie</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/examples/movie/build.xml b/examples/movie/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..b873dcc013ee946a805c391c0e0e518310b17daf --- /dev/null +++ b/examples/movie/build.xml @@ -0,0 +1,127 @@ +<?xml version="1.0"?> + +<project name="movie" default="build" basedir="."> + + <target name="getjjmpeg-windows-i586" if="use.win32.jjmpeg"> + <delete dir="jjmpeg"/> + <mkdir dir="jjmpeg"/> + <get dest="jjmpeg"> + <url url="http://jjmpeg.googlecode.com/files/jjmpeg-0.0-bin.tar.bz2"/> + </get> + <untar src="jjmpeg/jjmpeg-0.0-bin.tar.bz2" compression="bzip2" dest="jjmpeg"/> + </target> + + <target name="getffmpeg-windows-i586" if="use.win32.ffmpeg"> + <delete dir="ffmpeg"/> + <mkdir dir="ffmpeg"/> + <get dest="ffmpeg"> + <url url="http://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-git-9c2651a-win32-shared.7z"/> + </get> + <exec dir="ffmpeg" executable="C:\Program Files\7-Zip\7z.exe"> + <arg value="x"/> + <arg value="ffmpeg-git-9c2651a-win32-shared.7z"/> + </exec> + </target> + <target name="getjjmpeg-windows-amd64" if="use.win64.jjmpeg"> + <delete dir="jjmpeg"/> + <mkdir dir="jjmpeg"/> + <get dest="jjmpeg"> + <url url="http://jjmpeg.googlecode.com/files/jjmpeg-0.0-bin.tar.bz2"/> + </get> + <untar src="jjmpeg/jjmpeg-0.0-bin.tar.bz2" compression="bzip2" dest="jjmpeg"/> + </target> + <target name="getffmpeg-windows-amd64" if="use.win64.ffmpeg"> + <delete dir="ffmpeg"/> + <mkdir dir="ffmpeg"/> + <get dest="ffmpeg"> + <url url="http://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-git-9c2651a-win64-shared.7z"/> + </get> + <exec dir="ffmpeg" executable="C:\Program Files\7-Zip\7z.exe"> + <arg value="x"/> + <arg value="ffmpeg-git-9c2651a-win64-shared.7z"/> + </exec> + </target> + + <target name="checkos"> + <condition property="use.win32.jjmpeg"> + <and> + <os family="windows" /> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + <not><available file="jjmpeg/jjmpeg-0.0/native/mswin-i386/jjmpeg.dll"/> </not> + <not><available file="jjmpeg/jjmpeg-0.0/dist/jjmpeg.jar"/> </not> + </and> + </condition> + <condition property="use.win32.ffmpeg"> + <and> + <os family="windows" /> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\avcodec-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\avdevice-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\avfilter-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\avformat-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\avutil-51.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\postproc-51.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin\swscale-2.dll"/> </not> + </and> + </condition> + <condition property="use.win64.jjmpeg"> + <and> + <os family="windows" /> + <not> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + </not> + <not><available file="jjmpeg/jjmpeg-0.0/native/mswin-amd64/jjmpeg.dll"/> </not> + <not><available file="jjmpeg/jjmpeg-0.0/dist/jjmpeg.jar"/> </not> + </and> + </condition> + + <condition property="use.win64.ffmpeg"> + <and> + <os family="windows" /> + <not> + <or> + <os arch="x86" /> + <os arch="i386" /> + </or> + </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\avcodec-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\avdevice-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\avfilter-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\avformat-53.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\avutil-51.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\postproc-51.dll"/> </not> + <not><available file="ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin\swscale-2.dll"/> </not> + </and> + </condition> + </target> + + <target name="getstuff" depends="checkos, getjjmpeg-windows-i586, getffmpeg-windows-i586, getjjmpeg-windows-amd64, getffmpeg-windows-amd64"/> + + <target name="build" depends="getstuff,clean"> + <mkdir dir="classes"/> + <javac srcdir="src" destdir="classes" debug="on" includeantruntime="false" > + <classpath> + <pathelement path="..\..\com.amd.aparapi\dist\aparapi.jar"/> + <pathelement path="jjmpeg\jjmpeg-0.0\dist\jjmpeg.jar/"/> + <pathelement path="..\jviolajones\jviolajones.jar/"/> + </classpath> + </javac> + <jar jarfile="${ant.project.name}.jar" basedir="classes"/> + </target> + + <target name="clean"> + <delete dir="classes"/> + <delete file="${ant.project.name}.jar"/> + </target> + + +</project> diff --git a/examples/movie/movie.bat b/examples/movie/movie.bat new file mode 100644 index 0000000000000000000000000000000000000000..9a9f9011ee5e50b8d9ba3b5390c421ac3e8c71f6 --- /dev/null +++ b/examples/movie/movie.bat @@ -0,0 +1,15 @@ +SETLOCAL +if /I %PROCESSOR_ARCHITECTURE%==x86 goto win32 +echo "win64!" +set PATH=%PATH%;ffmpeg\ffmpeg-git-9c2651a-win64-shared\bin +set PATH=%PATH%;jjmpeg\jjmpeg-0.0\native\mswin-amd64 +goto win64 +:win32 +echo "win32!" +set PATH=%PATH%;ffmpeg\ffmpeg-git-9c2651a-win32-shared\bin +set PATH=%PATH%;jjmpeg\jjmpeg-0.0\native\mswin-i386 +:win64 +set PATH=%PATH%;..\..\com.amd.aparapi.jni\dist +java -classpath jjmpeg\jjmpeg-0.0\dist\jjmpeg.jar;..\..\com.amd.aparapi\dist\aparapi.jar;movie.jar; com.amd.aparapi.examples.movie.Main + +ENDLOCAL diff --git a/examples/movie/src/com/amd/aparapi/examples/movie/ConvMatrix3x3Editor.java b/examples/movie/src/com/amd/aparapi/examples/movie/ConvMatrix3x3Editor.java new file mode 100644 index 0000000000000000000000000000000000000000..6e537259dc4e679c7a00a98111a0fc5f247d0a01 --- /dev/null +++ b/examples/movie/src/com/amd/aparapi/examples/movie/ConvMatrix3x3Editor.java @@ -0,0 +1,151 @@ +/* +Copyright (c) 2010-2011, Advanced Micro Devices, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following +disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export +laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through +774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, +you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of +Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration +Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, +E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups +D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject +to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 +of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations +under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. + +*/ + +package com.amd.aparapi.examples.movie; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; + +import javax.swing.BoxLayout; +import javax.swing.JComboBox; +import javax.swing.JPanel; +import javax.swing.JSpinner; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +public class ConvMatrix3x3Editor{ + Component component; + + float[] default3x3; + + float[] none3x3 = new float[] { + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0 + }; + + float[] blur3x3 = new float[] { + .1f, + .1f, + .1f, + .1f, + .1f, + .1f, + .1f, + .1f, + .1f + }; + + JSpinner[] spinners = new JSpinner[9]; + + protected void updated(float[] _convMatrix3x3) { + + }; + + void set(float[] _to, float[] _from) { + for (int i = 0; i < 9; i++) { + _to[i] = _from[i]; + spinners[i].setValue((Double) (double) _to[i]); + + } + updated(_to); + } + + ConvMatrix3x3Editor(final float[] _convMatrix3x3) { + default3x3 = Arrays.copyOf(_convMatrix3x3, _convMatrix3x3.length); + JPanel leftPanel = new JPanel(); + JPanel controlPanel = new JPanel(); + BoxLayout layout = new BoxLayout(controlPanel, BoxLayout.Y_AXIS); + controlPanel.setLayout(layout); + component = leftPanel; + JPanel grid3x3Panel = new JPanel(); + controlPanel.add(grid3x3Panel); + grid3x3Panel.setLayout(new GridLayout(3, 3)); + for (int i = 0; i < 9; i++) { + final int index = i; + SpinnerModel model = new SpinnerNumberModel(_convMatrix3x3[index], -50f, 50f, 1f); + JSpinner spinner = new JSpinner(model); + spinners[i] = spinner; + spinner.addChangeListener(new ChangeListener(){ + public void stateChanged(ChangeEvent ce) { + JSpinner source = (JSpinner) ce.getSource(); + double value = ((Double) source.getValue()); + _convMatrix3x3[index] = (float) value; + updated(_convMatrix3x3); + } + }); + grid3x3Panel.add(spinner); + } + String[] options = new String[] { + "DEFAULT", + "NONE", + "BLUR" + }; + JComboBox combo = new JComboBox(options); + combo.addActionListener(new ActionListener(){ + + @Override public void actionPerformed(ActionEvent e) { + JComboBox cb = (JComboBox) e.getSource(); + String value = (String) cb.getSelectedItem(); + if (value.equals("DEFAULT")) { + set(_convMatrix3x3, default3x3); + } else if (value.equals("NONE")) { + set(_convMatrix3x3, none3x3); + } else if (value.equals("BLUR")) { + set(_convMatrix3x3, blur3x3); + } + } + + }); + controlPanel.add(combo); + + leftPanel.add(controlPanel, BorderLayout.NORTH); + } +} diff --git a/examples/movie/src/com/amd/aparapi/examples/movie/JJMPEGPlayer.java b/examples/movie/src/com/amd/aparapi/examples/movie/JJMPEGPlayer.java new file mode 100644 index 0000000000000000000000000000000000000000..0957eef076463c8fca1cbad652e418435e68e155 --- /dev/null +++ b/examples/movie/src/com/amd/aparapi/examples/movie/JJMPEGPlayer.java @@ -0,0 +1,147 @@ +/* +Copyright (c) 2010-2011, Advanced Micro Devices, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following +disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export +laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through +774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, +you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of +Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration +Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, +E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups +D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject +to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 +of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations +under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. + +*/ +package com.amd.aparapi.examples.movie; + +import java.awt.BorderLayout; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; + +import au.notzed.jjmpeg.io.JJMediaReader; +import au.notzed.jjmpeg.io.JJMediaReader.JJReaderVideo; + +/** + * Code based on Demo of JJVideoScanner class from jjmpeg + * + * See http://code.google.com/p/jjmpeg/ + * + * @author notzed + * @author gfrost + */ +public abstract class JJMPEGPlayer{ + + public JJMPEGPlayer(final String _title, final String _fileName, final float[] _convMatrix3x3) { + SwingUtilities.invokeLater(new Runnable(){ + final Object doorBell = new Object(); + + public void run() { + + JFrame frame = new JFrame(_title); + frame.getContentPane().setLayout(new BorderLayout()); + final JLabel label = new JLabel(){ + @Override public void paint(Graphics GC) { + super.paint(GC); + synchronized (doorBell) { + doorBell.notify(); + } + } + }; + frame.getContentPane().add(label, BorderLayout.CENTER); + + ConvMatrix3x3Editor editor = new ConvMatrix3x3Editor(_convMatrix3x3){ + @Override protected void updated(float[] _convMatrix3x3) { + + } + }; + frame.getContentPane().add(editor.component, BorderLayout.WEST); + + try { + final JJMediaReader reader = new JJMediaReader(_fileName); + final JJReaderVideo vs = reader.openFirstVideoStream(); + final BufferedImage in = vs.createImage(); + final BufferedImage out = vs.createImage(); + + label.setIcon(new ImageIcon(out)); + + new Thread(new Runnable(){ + public void run() { + int frames = 0; + long start = System.currentTimeMillis() - 1; + try { + while (true) { + JJMediaReader.JJReaderStream rs = reader.readFrame(); + if (rs != null) { + vs.getOutputFrame(in); + Graphics2D gc = in.createGraphics(); + frames++; + long fps = (frames * 1000) / (System.currentTimeMillis() - start); + gc.drawString("" + fps, 20, 20); + + processFrame(gc, _convMatrix3x3, in, out); + + label.repaint(); + synchronized (doorBell) { + try { + doorBell.wait(); + } catch (InterruptedException ie) { + ie.getStackTrace(); + } + } + } else { + reader.dispose(); + System.exit(1); + } + Thread.sleep(1); + } + } catch (Exception ex) { + ex.printStackTrace(); + Logger.getLogger(JJMPEGPlayer.class.getName()).log(Level.SEVERE, null, ex); + } + } + }).start(); + frame.pack(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } catch (Exception ex) { + Logger.getLogger(JJMPEGPlayer.class.getName()).log(Level.SEVERE, null, ex); + } + + } + }); + } + + protected abstract void processFrame(Graphics2D gc, float[] _convMatrix, BufferedImage in, BufferedImage _out); + +} diff --git a/examples/movie/src/com/amd/aparapi/examples/movie/Main.java b/examples/movie/src/com/amd/aparapi/examples/movie/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..7489ce9a3dd2f502b1758fa1b41c87cd57e36a3c --- /dev/null +++ b/examples/movie/src/com/amd/aparapi/examples/movie/Main.java @@ -0,0 +1,131 @@ +/* +Copyright (c) 2010-2011, Advanced Micro Devices, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following +disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products +derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export +laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through +774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, +you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of +Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration +Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, +E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups +D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject +to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 +of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations +under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. + +*/ +package com.amd.aparapi.examples.movie; + +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferByte; + + +import com.amd.aparapi.Kernel; +import com.amd.aparapi.Range; + +public class Main{ + + public static class Convolution extends Kernel{ + + private byte[] inputData; + + private byte[] outputData; + + private int width; + + private int height; + + private Range range; + + float[] convMatrix3x3; + + public Convolution(BufferedImage _imageIn, BufferedImage _imageOut) { + inputData = ((DataBufferByte) _imageIn.getRaster().getDataBuffer()).getData(); + outputData = ((DataBufferByte) _imageOut.getRaster().getDataBuffer()).getData(); + width = _imageIn.getWidth(); + height = _imageIn.getHeight(); + range = Range.create2D(width * 3, height); + setExplicit(true); + + } + + public void processPixel(int x, int y, int w, int h) { + float accum = 0; + int count = 0; + for (int dx = -3; dx < 6; dx += 3) { + for (int dy = -1; dy < 2; dy += 1) { + int rgb = 0xff & inputData[((y + dy) * w) + (x + dx)]; + accum += rgb * convMatrix3x3[count++]; + } + } + outputData[y * w + x] = (byte) Math.max(0, Math.min((int) accum, 255)); + } + + public void run() { + int x = getGlobalId(0); + int y = getGlobalId(1); + int w = getGlobalSize(0); + int h = getGlobalSize(1); + if (x > 3 && x < (w - 3) && y > 1 && y < (h - 1)) { + processPixel(x, y, w, h); + } else { + outputData[y * w + x] = inputData[(y * w) + x]; + } + } + + public void apply(float[] _convMatrix3x3) { + convMatrix3x3 = _convMatrix3x3; + put(convMatrix3x3).put(inputData).execute(range).get(outputData); + } + + } + + public static void main(final String[] _args) { + String fileName = _args.length == 1 ? _args[0] : "Leo720p.wmv"; + + float[] convMatrix3x3 = new float[] { + 0f, + -10f, + 0f, + -10f, + 41f, + -10f, + 0f, + -10f, + 0f + }; + new JJMPEGPlayer("lab-6-solution", fileName, convMatrix3x3){ + Convolution kernel = null; + + @Override protected void processFrame(Graphics2D gc, float[] _convMatrix3x3, BufferedImage in, BufferedImage out) { + if (kernel == null) { + kernel = new Convolution(in, out); + } + kernel.apply(_convMatrix3x3); + } + }; + + } +}