Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package nextrek.jni;

import java.nio.ByteBuffer;

import android.graphics.Bitmap;

public class webp {

    static {
        System.loadLibrary("webp");
    }

    public static native byte[] WebPDecodeARGB(byte[] encoded, int encoded_length, int[] width, int[] height);

    public static native byte[] WebPDecodeRGB(byte[] encoded, int encoded_length, int[] width, int[] height);
    
    public static native byte[] WebPDecodeRGB565(byte[] encoded, int encoded_length, int[] width, int[] height);

    public static Bitmap byteArrayToBitmapARGB(byte[] encoded) {

        int[] width = new int[] { 0 };
        int[] height = new int[] { 0 };

        byte[] decoded = WebPDecodeARGB(encoded, encoded.length, width, height);

        ByteBuffer buffer = ByteBuffer.wrap(decoded);

        Bitmap bitmap = Bitmap.createBitmap(width[0], height[0], Bitmap.Config.ARGB_8888);
        bitmap.copyPixelsFromBuffer(buffer);

        return bitmap;
    }

    public static Bitmap byteArrayToBitmapRGB565(byte[] encoded) {

        int[] width = new int[] { 0 };
        int[] height = new int[] { 0 };

        byte[] decoded = WebPDecodeRGB565(encoded, encoded.length, width, height);

        ByteBuffer buffer = ByteBuffer.wrap(decoded);

        Bitmap bitmap = Bitmap.createBitmap(width[0], height[0], Bitmap.Config.RGB_565);
        bitmap.copyPixelsFromBuffer(buffer);

        return bitmap;
    }
}

Commits for Nextrek/Android/LibrerieNextrek/src/nextrek/jni/webp.java

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000