package com.nucleus.texture.android;

import java.io.IOException;
import java.nio.ByteBuffer;

import com.nucleus.profiling.FrameSampler;
import com.nucleus.texturing.BaseImageFactory;
import com.nucleus.texturing.BufferImage;
import com.nucleus.texturing.BufferImage.ImageFormat;
import com.nucleus.texturing.ImageFactory;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class AndroidImageFactory extends BaseImageFactory implements ImageFactory {

    @Override
    public BufferImage createImage(String name, ImageFormat format) throws IOException {
        long start = System.currentTimeMillis();
        ClassLoader classLoader = getClass().getClassLoader();
        Bitmap b = BitmapFactory.decodeStream(classLoader.getResourceAsStream(name));
        long loaded = System.currentTimeMillis();
        FrameSampler.getInstance().logTag(FrameSampler.Samples.LOAD_IMAGE, start, loaded);
        if (b == null) {
            throw new IOException("Could not load " + name);
        }
        byte[] bytePixels = new byte[b.getWidth() * b.getHeight() * 4];
        ByteBuffer bb = ByteBuffer.wrap(bytePixels);
        b.copyPixelsToBuffer(bb);
        BufferImage image = new BufferImage(b.getWidth(), b.getHeight(), format);
        copyPixels(bytePixels, ImageFormat.RGBA, image);
        b.recycle();
        FrameSampler.getInstance().logTag(FrameSampler.Samples.COPY_IMAGE, " " + image.getFormat().toString(), loaded,
                System.currentTimeMillis());
        return image;
    }
}

@@ -274,16 +274,71 @@
 Format;%0A
+import com.nucleus.texturing.BufferImage.SourceFormat;%0A
 import c
@@ -1309,16 +1309,178 @@
 ormat);%0A
+        if (b.getConfig() != Bitmap.Config.ARGB_8888) %7B%0A            throw new IllegalArgumentException(%22Not supported Bitmap.Config %22 + b.getConfig());%0A        %7D%0A
         
@@ -1506,20 +1506,21 @@
 ls, 
-Imag
+Sourc
 eFormat.
 RGBA
@@ -1519,12 +1519,21 @@
 mat.
+TYPE_INT_A
 RGB
-A
 , im

Fix Android imagefactory, use sourceformat