Alessio Caiazza avatar Alessio Caiazza committed 4675e4d

CaptureMJPEG: wrapper around passing ByteArrayInputStream into
processing.core.PImage.<init>
Now really works on Processing > 1.0 ! fixes #4

I'll hope in a better solution in future.
Fixed copyright statements

Comments (0)

Files changed (7)

 <?xml version="1.0"?>
 <!-- build file for CaptureMJPEG library -->
-<!-- Created by: Alessio Caiazza &lt;ac@abisso.org&gt;	-->
+<!-- Created by: Alessio Caiazza &lt;nolith@abisso.org&gt;	-->
 
 <project name="CaptureMJPEG" default="build" basedir=".">
 	<import file="user_pref.xml"/>
 	  		<exclude name="it/lilik/capturemjpeg/*Test.java"/>  
 	  	</fileset>
 	    <doctitle><![CDATA[<h1>CaptureMJPEG</h1>]]></doctitle>
-	    <bottom><![CDATA[<i>Copyright &#169; 2008 Alessio Caiazza, Cosimo Cecchi All Rights Reserved.</i>]]></bottom>
+	    <bottom><![CDATA[<i>Copyright &#169; 2008-09 Alessio Caiazza, Cosimo Cecchi All Rights Reserved.</i>]]></bottom>
 	    <link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
 	  	<link href="http://hc.apache.org/httpclient-3.x/apidocs/"/>
 		<link href="http://dev.processing.org/reference/core/javadoc/"/>

src/it/lilik/capturemjpeg/AxisURL.java

     You should have received a copy of the GNU Lesser Public License
     along with CaptureMJPEG.  If not, see <http://www.gnu.org/licenses/>.
     
-    Copyright (c) 2008 - Alessio Caiazza, Cosimo Cecchi
+    Copyright (c) 2008-09 - Alessio Caiazza, Cosimo Cecchi
  */
 package it.lilik.capturemjpeg;
 

src/it/lilik/capturemjpeg/CaptureMJPEG.java

     You should have received a copy of the GNU Lesser Public License
     along with CaptureMJPEG.  If not, see <http://www.gnu.org/licenses/>.
     
-    Copyright (c) 2008 - Alessio Caiazza, Cosimo Cecchi
+    Copyright (c) 2008-09 - Alessio Caiazza, Cosimo Cecchi
  */
 package it.lilik.capturemjpeg;
 
 import java.awt.image.BufferedImage;
+import java.awt.image.PixelGrabber;
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 				synchronized (lastImage) {
 					if (captureEventMethod != null) {
 				            try {
-				            	PImage tmp = null;
-				            	tmp = new PImage((BufferedImage)ImageIO.read(
-						            			new ByteArrayInputStream(img)));
+											PImage tmp = getPImage(new ByteArrayInputStream(img));
 				            	captureEventMethod.invoke(parent, new Object[] { 
 				            		  this.assign(tmp) });
 				            } catch (Exception e) {
 
 	}
 
+	/*
+	 * Bypass Default PImage costructur forcing
+	 * a load like in Processing < 1.0
+	 *
+	 */
+	private PImage getPImage(ByteArrayInputStream bais) throws IOException {
+		PImage tmp = null;
+		BufferedImage bi = (BufferedImage)ImageIO.read(bais);
+
+		int width = bi.getWidth(null);
+		int height = bi.getHeight(null);
+		int[] pixels = new int[width * height];
+		PixelGrabber pg =
+				new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width);
+		try {
+				pg.grabPixels();
+		} catch (InterruptedException e) { }
+
+		tmp = new PImage(width,height);
+		tmp.loadPixels();
+		for (int i = 0; i < width * height; i++) {
+				tmp.pixels[i] = pixels[i];
+		}
+		tmp.updatePixels();
+
+		return tmp;	
+	}
+
 	private void setErrorImage(ErrorImage error) {
 		if (captureEventMethod != null) {
 			try {
 			if (!isImageAvailable())
 				return lastImage;
 			try {
-				PImage tmp = new PImage(ImageIO.read(buffer.pop()));
+				PImage tmp = getPImage(buffer.pop());
 				return assign(tmp);
 			} catch (IOException e1) {
 				e1.printStackTrace();

src/it/lilik/capturemjpeg/CircularBuffer.java

     You should have received a copy of the GNU Lesser Public License
     along with CaptureMJPEG.  If not, see <http://www.gnu.org/licenses/>.
     
-    Copyright (c) 2008 - Alessio Caiazza, Cosimo Cecchi
+    Copyright (c) 2008-09 - Alessio Caiazza, Cosimo Cecchi
  */
 package it.lilik.capturemjpeg;
 

src/it/lilik/capturemjpeg/ErrorImage.java

     You should have received a copy of the GNU Lesser Public License
     along with CaptureMJPEG.  If not, see <http://www.gnu.org/licenses/>.
     
-    Copyright (c) 2008 - Alessio Caiazza, Cosimo Cecchi
+    Copyright (c) 2008-09 - Alessio Caiazza, Cosimo Cecchi
  */
 package it.lilik.capturemjpeg;
 

src/it/lilik/capturemjpeg/MJPEGInputStream.java

     You should have received a copy of the GNU Lesser Public License
     along with CaptureMJPEG.  If not, see <http://www.gnu.org/licenses/>.
     
-    Copyright (c) 2008 - Alessio Caiazza, Cosimo Cecchi
+    Copyright (c) 2008-09 - Alessio Caiazza, Cosimo Cecchi
  */
 package it.lilik.capturemjpeg;
 

src/it/lilik/capturemjpeg/SonyURL.java

     You should have received a copy of the GNU Lesser Public License
     along with CaptureMJPEG.  If not, see <http://www.gnu.org/licenses/>.
     
-    Copyright (c) 2008 - Alessio Caiazza, Cosimo Cecchi
+    Copyright (c) 2008-09 - Alessio Caiazza, Cosimo Cecchi
  */
 package it.lilik.capturemjpeg;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.