I have an image (of size 1024x1024) in an int array (int[] pixels) and I am inverting one channel using the following loop...
int i = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
int color = pixels[i];
pixels[i] = Color.argb(Color.alpha(color), 255 - Color.red(color), Color.green(color), Color.blue(color));
i++;
}
}
This takes more than 1 second on my new Galaxy S4 phone. Similar loop runs in a blink of an eye even on an older iPhone. Is there something I am doing wrong here?
If I replace "Color.argb(Color.alpha(color), 255 - Color.red(color), Color.green(color), Color.blue(color))" with "Color.BLUE", it gets much faster.
Found a workaround.
If I use my own bitwise operators instead of Color functions, it gets much faster...
int i = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
int color = pixels[i];
int red = ((color & 0x00ff0000) >> 16);
pixels[i] = (color & 0xff00ffff) | ((255 - red) << 16);
//pixels[i] = Color.argb(Color.alpha(color), 255 - Color.red(color), Color.green(color), Color.blue(color));
i++;
}
}