From 078f4bc924137f808522c4d3ff86106c62b40c7a Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 26 Feb 2010 23:44:21 +0000 Subject: [PATCH] implementation of get/set for images --- android/core/src/processing/core/PImage.java | 49 +++++++++++--------- todo.txt | 6 +++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/android/core/src/processing/core/PImage.java b/android/core/src/processing/core/PImage.java index fd6e84b4a..32c411942 100644 --- a/android/core/src/processing/core/PImage.java +++ b/android/core/src/processing/core/PImage.java @@ -415,7 +415,13 @@ public class PImage implements PConstants, Cloneable { public int get(int x, int y) { if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return 0; - switch (format) { + if (pixels == null) { + return bitmap.getPixel(x, y); + + } else { + // If the pixels array exists, it's fairly safe to assume that it's + // the most up to date, and that it's faster for access. + switch (format) { case RGB: return pixels[y*width + x] | 0xff000000; @@ -424,6 +430,7 @@ public class PImage implements PConstants, Cloneable { case ALPHA: return (pixels[y*width + x] << 24) | 0xffffff; + } } return 0; } @@ -434,18 +441,6 @@ public class PImage implements PConstants, Cloneable { * As of release 0149, no longer honors imageMode() for the coordinates. */ public PImage get(int x, int y, int w, int h) { - /* - if (imageMode == CORNERS) { // if CORNER, do nothing - //x2 += x1; y2 += y1; - // w/h are x2/y2 in this case, bring em down to size - w = (w - x); - h = (h - y); - } else if (imageMode == CENTER) { - x -= w/2; - y -= h/2; - } - */ - if (x < 0) { w += x; // clip off the left edge x = 0; @@ -472,12 +467,17 @@ public class PImage implements PConstants, Cloneable { PImage newbie = new PImage(w, h, format); newbie.parent = parent; - int index = y*width + x; - int index2 = 0; - for (int row = y; row < y+h; row++) { - System.arraycopy(pixels, index, newbie.pixels, index2, w); - index += width; - index2 += w; + if (pixels == null) { + bitmap.getPixels(newbie.pixels, 0, w, x, y, w, h); + + } else { + int index = y*width + x; + int index2 = 0; + for (int row = y; row < y+h; row++) { + System.arraycopy(pixels, index, newbie.pixels, index2, w); + index += width; + index2 += w; + } } return newbie; } @@ -499,9 +499,14 @@ public class PImage implements PConstants, Cloneable { * Set a single pixel to the specified color. */ public void set(int x, int y, int c) { - if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return; - pixels[y*width + x] = c; - updatePixelsImpl(x, y, x+1, y+1); // slow? + if (pixels == null) { + bitmap.setPixel(x, y, c); + + } else { + if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return; + pixels[y*width + x] = c; + updatePixelsImpl(x, y, x+1, y+1); // slow? + } } diff --git a/todo.txt b/todo.txt index cafe8a9fc..2fd179d73 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,10 @@ 0178 pde +X write implementation for get/set methods inside PImage (w/o pixels[]) + + +_ make sure that get() and set() (for pixels and subsets) work w/ loaded images +_ make sure that get() and set() (for pixels and subsets) work w/ P2D +_ make sure that get() and set() (for pixels and subsets) work w/ P3D _ Cannot find PDF library _ http://dev.processing.org/bugs/show_bug.cgi?id=1473