From cf8e03ff702a922e3b762827ae09621ac0132342 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 16 Jan 2014 18:04:15 -0500 Subject: [PATCH] fix #2202 --- core/src/processing/opengl/Texture.java | 2 +- .../video/src/processing/video/Capture.java | 24 +++++++++++++++++ .../video/src/processing/video/Movie.java | 26 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index a8ea6662c..555ae5986 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -881,7 +881,7 @@ public class Texture implements PConstants { public void getBufferPixels(int[] pixels) { BufferData data = null; if (usedBuffers != null && 0 < usedBuffers.size()) { - // the last used buffer is the one currently stored in the opengl the + // the last used buffer is the one currently stored in the opengl // texture data = usedBuffers.getLast(); } else if (bufferCache != null && 0 < bufferCache.size()) { diff --git a/java/libraries/video/src/processing/video/Capture.java b/java/libraries/video/src/processing/video/Capture.java index 7cad36876..8ff7de94e 100644 --- a/java/libraries/video/src/processing/video/Capture.java +++ b/java/libraries/video/src/processing/video/Capture.java @@ -107,6 +107,7 @@ public class Capture extends PImage implements PConstants { protected int reqHeight; protected boolean useBufferSink = false; + protected boolean outdatedPixels = true; protected Object bufferSink; protected Method sinkCopyMethod; protected Method sinkSetMethod; @@ -375,6 +376,7 @@ public class Capture extends PImage implements PConstants { } if (useBufferSink) { // The native buffer from gstreamer is copied to the buffer sink. + outdatedPixels = true; if (natBuffer == null) { return; } @@ -442,10 +444,32 @@ public class Capture extends PImage implements PConstants { e.printStackTrace(); } } + + // super.loadPixels() sets loaded to true, but in the useBufferSink mode, + // the contents of the pixels array is overriden by the buffers coming + // from gstreamer, so we don't want PGraphicsOpenGL replacing the OpenGL + // texture with the pixels. + setLoaded(false); + outdatedPixels = false; } } + public int get(int x, int y) { + if (outdatedPixels) loadPixels(); + return super.get(x, y); + } + + + protected void getImpl(int sourceX, int sourceY, + int sourceWidth, int sourceHeight, + PImage target, int targetX, int targetY) { + if (outdatedPixels) loadPixels(); + super.getImpl(sourceX, sourceY, sourceWidth, sourceHeight, + target, targetX, targetY); + } + + //////////////////////////////////////////////////////////// // List methods. diff --git a/java/libraries/video/src/processing/video/Movie.java b/java/libraries/video/src/processing/video/Movie.java index fcb0056e6..694f92f27 100644 --- a/java/libraries/video/src/processing/video/Movie.java +++ b/java/libraries/video/src/processing/video/Movie.java @@ -79,6 +79,7 @@ public class Movie extends PImage implements PConstants { protected boolean seeking = false; protected boolean useBufferSink = false; + protected boolean outdatedPixels = true; protected Object bufferSink; protected Method sinkCopyMethod; protected Method sinkSetMethod; @@ -487,6 +488,7 @@ public class Movie extends PImage implements PConstants { } if (useBufferSink) { // The native buffer from gstreamer is copied to the buffer sink. + outdatedPixels = true; if (natBuffer == null) { return; } @@ -565,11 +567,33 @@ public class Movie extends PImage implements PConstants { } catch (Exception e) { e.printStackTrace(); } - } + } + + // super.loadPixels() sets loaded to true, but in the useBufferSink mode, + // the contents of the pixels array is overriden by the buffers coming + // from gstreamer, so we don't want PGraphicsOpenGL replacing the OpenGL + // texture with the pixels. + setLoaded(false); + outdatedPixels = false; } } + public int get(int x, int y) { + if (outdatedPixels) loadPixels(); + return super.get(x, y); + } + + + protected void getImpl(int sourceX, int sourceY, + int sourceWidth, int sourceHeight, + PImage target, int targetX, int targetY) { + if (outdatedPixels) loadPixels(); + super.getImpl(sourceX, sourceY, sourceWidth, sourceHeight, + target, targetX, targetY); + } + + //////////////////////////////////////////////////////////// // Initialization methods.