/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2016 Sri Harsha Chilakapati
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.shc.silenceengine.backend.android;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.shc.silenceengine.core.SilenceException;
import com.shc.silenceengine.graphics.Color;
import com.shc.silenceengine.graphics.Image;
import com.shc.silenceengine.io.DirectBuffer;
import com.shc.silenceengine.io.ImageReader;
import com.shc.silenceengine.utils.TaskManager;
import com.shc.silenceengine.utils.functional.UniCallback;

import java.io.IOException;

/**
 * @author Sri Harsha Chilakapati
 */
public class AndroidImageReader extends ImageReader
{
    @Override
    public void readImage(DirectBuffer memory, UniCallback<Image> uniCallback)
    {
        new Thread(() -> {
            Bitmap bitmap = BitmapFactory.decodeStream(new DirectBufferInputStream(memory));

            if (bitmap == null)
                throw new SilenceException(new IOException("Error decoding image from memory"));

            Image image = new Image(bitmap.getWidth(), bitmap.getHeight());

            for (int x = 0; x < image.getWidth(); x++)
                for (int y = 0; y < image.getHeight(); y++)
                {
                    int rgba = bitmap.getPixel(x, y);

                    float r = ((rgba & 0x00FF0000) >> 16) / 255f;
                    float g = ((rgba & 0x0000FF00) >> 8) / 255f;
                    float b = (rgba & 0x000000FF) / 255f;
                    float a = ((rgba & 0xFF000000) >> 24) / 255f;

                    image.setPixel(x, y, new Color(r, g, b, a));
                }

            bitmap.recycle();
            bitmap = null;

            TaskManager.runOnUpdate(() -> uniCallback.invoke(image));
        }).start();
    }
}

@@ -2323,20 +2323,21 @@
     int 
-rgba
+pixel
  = bitma
@@ -2385,38 +2385,46 @@
 oat 
-r = ((rgba & 0x00FF0000) %3E%3E 16
+a = android.graphics.Color.alpha(pixel
 ) / 
@@ -2459,37 +2459,44 @@
 oat 
-g = ((rgba & 0x0000FF00) %3E%3E 8
+r = android.graphics.Color.red(pixel
 ) / 
@@ -2531,30 +2531,46 @@
 oat 
-b = (rgba & 0x000000FF
+g = android.graphics.Color.green(pixel
 ) / 
@@ -2605,38 +2605,45 @@
 oat 
-a = ((rgba & 0xFF000000) %3E%3E 24
+b = android.graphics.Color.blue(pixel
 ) / 

Use Android's Color class to get the pixels