From 7c76c07a67fe297e1d1485ef65a4c9bd02490b7d Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 21 Dec 2004 06:00:02 +0000 Subject: [PATCH] tweaks for image --- processing/core/PImage.java | 86 ++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/processing/core/PImage.java b/processing/core/PImage.java index 4c8c73865..44013e800 100644 --- a/processing/core/PImage.java +++ b/processing/core/PImage.java @@ -157,18 +157,10 @@ public class PImage implements PConstants, Cloneable { public void modified() { tindex = -1; + // bit shifting this might be more efficient int width2 = (int) Math.pow(2, Math.ceil(Math.log(width) / Math.log(2))); int height2 = (int) Math.pow(2, Math.ceil(Math.log(height) / Math.log(2))); - /* - if ((width2 == width) && (height2 == height)) { - // image can be used by itself as the texture image - tpixels = pixels; - twidth = width; - theight = height; - - } else { - */ if ((width2 > twidth) || (height2 > theight)) { // either twidth/theight are zero, or size has changed tpixels = null; @@ -178,43 +170,79 @@ public class PImage implements PConstants, Cloneable { theight = height2; tpixels = new int[twidth * theight]; } + // copy image data into the texture int p = 0; int t = 0; - for (int y = 0; y < height; y++) { + + if (System.getProperty("sun.cpu.endian").equals("big")) { switch (format) { case ALPHA: - for (int x = 0; x < width; x++) { - tpixels[t++] = 0xFFFFFF00 | pixels[p++]; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + tpixels[t++] = 0xFFFFFF00 | pixels[p++]; + } + t += twidth - width; } - t += twidth - width; break; case RGB: - for (int x = 0; x < width; x++) { - int pixel = pixels[p++]; - tpixels[t++] = (pixel << 8) | 0xff; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int pixel = pixels[p++]; + tpixels[t++] = (pixel << 8) | 0xff; + } + t += twidth - width; } - t += twidth - width; - /* - System.arraycopy(pixels, p, tpixels, t, width); - p += width; - t += twidth; - */ break; case ARGB: - for (int x = 0; x < width; x++) { - int pixel = pixels[p++]; - //tpixels[t++] = 0x80808080; - tpixels[t++] = (pixel << 8) | ((pixel >> 24) & 0xff); - //tpixels[t++] = 0xFFFFFF00 | pixels[p++]; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int pixel = pixels[p++]; + tpixels[t++] = (pixel << 8) | ((pixel >> 24) & 0xff); + } + t += twidth - width; + } + break; + } + + } else { + switch (format) { + case ALPHA: + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + tpixels[t++] = (pixels[p++] << 24) | 0x00FFFFFF; + } + t += twidth - width; + } + break; + + case RGB: + for (int y = 0; y < height; y++) { + System.arraycopy(pixels, p, tpixels, t, width); + p += width; + t += twidth; + } + break; + + case ARGB: + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int pixel = pixels[p++]; + // needs to be ABGR + // stored in memory ARGB + // so R and B must be swapped + tpixels[t++] = + ((pixel & 0xFF) << 16) | + ((pixel & 0xFF0000) >> 16) | + (pixel & 0xFF00FF00); + } + t += twidth - width; } - t += twidth - width; break; } } - //} }