List of usage examples for android.opengl ETC1 getEncodedDataSize
public static native int getEncodedDataSize(int width, int height);
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();/*from w ww . j a v a 2 s .c o 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; }