mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 09:39:19 +01:00
tweaks for image
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user