public void setBitmap(Bitmap bitmap) { mBitmap = bitmap; int imageSize = bitmap.getRowBytes() * bitmap.getHeight(); ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize); bitmap.copyPixelsToBuffer(uncompressedBuffer); uncompressedBuffer.position(0); ByteBuffer compressedBuffer = ByteBuffer.allocateDirect( ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder()); ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedBuffer); mByteBuffers = new ByteBuffer[]{compressedBuffer}; setWidth(bitmap.getWidth()); setHeight(bitmap.getHeight()); }
private ETC1Util.ETC1Texture createTexture(InputStream input) throws IOException { int width = 0; int height = 0; byte[] ioBuffer = new byte[4096]; { if (input.read(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE) != ETC1.ETC_PKM_HEADER_SIZE) { throw new IOException("Unable to read PKM file header."); } if(headerBuffer==null){ headerBuffer = ByteBuffer.allocateDirect(ETC1.ETC_PKM_HEADER_SIZE) .order(ByteOrder.nativeOrder()); } headerBuffer.put(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE).position(0); if (!ETC1.isValid(headerBuffer)) { throw new IOException("Not a PKM file."); } width = ETC1.getWidth(headerBuffer); height = ETC1.getHeight(headerBuffer); } int encodedSize = ETC1.getEncodedDataSize(width, height); ByteBuffer dataBuffer = ByteBuffer.allocateDirect(encodedSize).order(ByteOrder.nativeOrder()); int len; while ((len =input.read(ioBuffer))!=-1){ dataBuffer.put(ioBuffer,0,len); } dataBuffer.position(0); return new ETC1Util.ETC1Texture(width, height, dataBuffer); }
@Override protected void onSizeChanged(int width, int height) { emptyBuffer=ByteBuffer.allocateDirect(ETC1.getEncodedDataSize(width,height)); this.width=width; this.height=height; GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,GLES20.GL_ONE_MINUS_SRC_ALPHA); }
@Override protected void onSizeChanged(int width, int height) { emptyBuffer=ByteBuffer.allocateDirect(ETC1.getEncodedDataSize(width,height)); this.width=width; this.height=height; GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,GLES20.GL_ONE_MINUS_SRC_ALPHA); mBaseFilter.setSize(width, height); }
private void setBitmap(Bitmap bitmap) { mBitmap = bitmap; int imageSize = bitmap.getRowBytes() * bitmap.getHeight(); ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize); bitmap.copyPixelsToBuffer(uncompressedBuffer); uncompressedBuffer.position(0); ByteBuffer compressedBuffer = ByteBuffer.allocateDirect( ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder()); ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedBuffer); setCompressionFormat(ETC1.ETC1_RGB8_OES); mByteBuffers = new ByteBuffer[]{compressedBuffer}; setWidth(bitmap.getWidth()); setHeight(bitmap.getHeight()); } }
public void setBitmap(Bitmap bitmap) { mBitmap = bitmap; int imageSize = bitmap.getRowBytes() * bitmap.getHeight(); ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize); bitmap.copyPixelsToBuffer(uncompressedBuffer); uncompressedBuffer.position(0); ByteBuffer compressedBuffer = ByteBuffer.allocateDirect( ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder()); ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedBuffer); mByteBuffers = new ByteBuffer[]{compressedBuffer}; setWidth(bitmap.getWidth()); setHeight(bitmap.getHeight()); }
private void setBitmap(Bitmap bitmap) { mBitmap = bitmap; int imageSize = bitmap.getRowBytes() * bitmap.getHeight(); ByteBuffer uncompressedBuffer = ByteBuffer.allocateDirect(imageSize); bitmap.copyPixelsToBuffer(uncompressedBuffer); uncompressedBuffer.position(0); ByteBuffer compressedBuffer = ByteBuffer.allocateDirect( ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight())).order(ByteOrder.nativeOrder()); ETC1.encodeImage(uncompressedBuffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedBuffer); setCompressionFormat(ETC1.ETC1_RGB8_OES); mByteBuffers = new ByteBuffer[]{compressedBuffer}; setWidth(bitmap.getWidth()); setHeight(bitmap.getHeight()); } }