Example usage for android.opengl ETC1 encodeImage

List of usage examples for android.opengl ETC1 encodeImage

Introduction

In this page you can find the example usage for android.opengl ETC1 encodeImage.

Prototype

public static native void encodeImage(Buffer in, int width, int height, int pixelSize, int stride, Buffer out);

Source Link

Document

Encode an entire image.

Usage

From source file:org.ros.android.rviz_for_android.drawable.loader.ColladaLoader.java

private ETC1Texture compressBitmap(Bitmap uncompressedBitmap) {
    // Rescale the bitmap to be half its current size
    Bitmap uncompressedBitmapResize = Bitmap.createScaledBitmap(uncompressedBitmap,
            uncompressedBitmap.getWidth() / 4, uncompressedBitmap.getHeight() / 4, true);
    uncompressedBitmap.recycle();//www. jav  a  2s. co  m

    // Copy the bitmap to a byte buffer
    ByteBuffer uncompressedBytes = ByteBuffer.allocateDirect(uncompressedBitmapResize.getByteCount())
            .order(ByteOrder.nativeOrder());
    uncompressedBitmapResize.copyPixelsToBuffer(uncompressedBytes);
    uncompressedBytes.position(0);

    int width = uncompressedBitmapResize.getWidth();
    int height = uncompressedBitmapResize.getHeight();

    // Compress the texture
    int encodedSize = ETC1.getEncodedDataSize(width, height);
    ByteBuffer compressed = ByteBuffer.allocateDirect(encodedSize).order(ByteOrder.nativeOrder());
    ETC1.encodeImage(uncompressedBytes, width, height, 2, 2 * width, compressed);

    ETC1Texture retval = new ETC1Texture(width, height, compressed);

    // We're done with the uncompressed bitmap, release it
    uncompressedBitmapResize.recycle();

    return retval;
}