this should speed things up a great deal:
Code:
private int[] getRow(int index, int y) {
int[] outgoing = new int[width];
int offset = y*width;
switch (index) {
case 0:
for (int x = 0; x < width; x++) {
outgoing[offset + x] = (p5.pixels[offset + x] >> 16) & 0xff;
}
break;
case 1:
for (int x = 0; x < width; x++) {
outgoing[offset + x] = (p5.pixels[offset + x] >> 8) & 0xff;
}
break;
case 2:
for (int x = 0; x < width; x++) {
outgoing[offset + x] = p5.pixels[offset + x] & 0xff;
}
break;
}
return outgoing;
}
not sure if this function is still needed, but this is what the optimized version would look like:
Code:
private int getColor(int index, int c) {
switch (index) {
case 0: return (c >> 16) & 0xff; // red
case 1: return (c >> 8) & 0xff; // green
case 2: return c & 0xff; // blue
default: return 0;
}
red(), green() etc are all really slow (see notes in teh docs). also, you're not guaranteed to have the functions inline properly (PApplet.red() might sometimes get inlined) so called getColor() repeatedly will be slow because the switch() is inside of that.
other things that would speed things up.. if outgoing[] can re-use its int array, that'll save a lot of time, becuase the overhead for creating (and unloading) an array of ints will be high. i.e. only creating a single int[] array that's used over and over again by calls to getRow().
also using P3D will be faster than the JAVA renderer because the loadPixels() overhead will go away.
also, if getRow() isn't really needed, you may as well copy that whole matrix in one go, that way you don't have to deal with the overhead of calling getRow() multiple times, and creating the array of ints for the row, and doing the switch statement repeatedly.
i can't go much further without knowing more about how it's set up.. like if copyArrayToVectorPlanar() needn't deal with rows, then you might be in better shape.. but the changes listed should give you a large speed boost..