I have the image_source
that is the source bitmap with some picture and image_new
— temporary bitmap
I do this code, that makes image_source
be anaglyph background layer:
int [] pixel = {0x0, 0x0, 0x0};
int [] image_params = {image_source.getWidth() - 2 * anaglyph_amplitude, image_source.getHeight()};
Bitmap image_new = Bitmap.createScaledBitmap(image_source, image_params[0], image_params[1], false);
for(int i = 0; i < image_params[0]; ++i)
for(int j = 0; j < image_params[1]; ++j) {
pixel[0] = image_source.getPixel(i, j);
pixel[1] = image_source.getPixel(i + 2 * anaglyph_amplitude, j);
pixel[2] = pixel[0] + pixel[1] % 0x10000 - pixel[0] % 0x10000;
image_new.setPixel(i, j, pixel[2]);
}
image_source = Bitmap.createBitmap(image_new);
image_new = null;
Then image_source
is drawn to canvas (drawing to canvas at ones is not available).
The problem is that this programm takes about 5 seconds to process image with 1000x1000 size on smart Android device.
Are there any other ways to run bitmap pixels?
Another minor tweak. In the inner loop, no reason to use an array for pixel[1] etc. Have three ints, p0, p1 and p2.
EDIT ADDED
I'm less familiar with Android than Swing, but I was hoping that Android's Bitmap has a "get me a bunch of pixels at a time" method similar to a Raster. It does.
I think you should be using the Bitmap method javadocs link here
If you have the memory available, get all 1,000,000 at once.
You could cache the calculation of
2 * anaglyph_amplitude
so it has not to be calculated on each iteration.Here is solution: I get array of pixels and worked with it.
There is some performance enhancement for snippet code. I am not sure it is enough for you.
First change
instead of
-
instead of