public static ETC1Texture testSDKETC1ImageCompressor() { // RGB_565 is 2 bytes per pixel ETC1.encodeImage(buffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedImage); ETC1Texture texture = new ETC1Texture(bitmap.getWidth(), bitmap.getHeight(), compressedImage); buffer.rewind(); // if (texture != null) { // int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE // + texture.getHeight() * texture.getWidth() / 2; // File f = new // File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm"); // f.delete(); // f.createNewFile(); // ETC1Util.writeTexture(texture, new FileOutputStream(f)); // System.out.println("Texture PKM created "); // } // System.out.println("Texture PKM creation failed "); return texture; }
public static ETC1Texture testJavaETC1ImageCompressor() { // RGB_565 is 2 bytes per pixel JavaETC1.encodeImage(buffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedImage); ETC1Texture texture = new ETC1Texture(bitmap.getWidth(), bitmap.getHeight(), compressedImage); buffer.rewind(); // if (texture != null) { // int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE // + texture.getHeight() * texture.getWidth() / 2; // File f = new // File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm"); // f.delete(); // f.createNewFile(); // ETC1Util.writeTexture(texture, new FileOutputStream(f)); // System.out.println("Texture PKM created "); // } // System.out.println("Texture PKM creation failed "); return texture; }
private void makeImage(Render render, float angle, String name) throws IOException { Bitmap bitmap = render.getImage(angle); int dim = bitmap.getHeight(); ByteBuffer bb = ByteBuffer.allocateDirect(dim * dim * 3); for (int y = 0; y < dim; y += 1) { for (int x = 0; x < dim; x += 1) { int value = bitmap.getPixel(x, y); bb.put((byte) (value >> 16)); bb.put((byte) (value >> 8)); bb.put((byte) value); } } bb.rewind(); ETC1Texture compressed = ETC1Util.compressTexture(bb, dim, dim, 3, dim * 3); FileOutputStream outFile = openFileOutput(name, Context.MODE_PRIVATE); ETC1Util.writeTexture(compressed, outFile); outFile.close(); }
public void showEtc1Texture(ETC1Texture texture) { int width = texture.getWidth(); int height = texture.getHeight(); Buffer data = texture.getData(); int pixelSize = 2; int stride = pixelSize * width; ByteBuffer decodedData = ByteBuffer.allocateDirect(stride*height) .order(ByteOrder.nativeOrder()); ETC1.decodeImage((ByteBuffer) data, decodedData, width, height, pixelSize, stride); mBitmapOut.copyPixelsFromBuffer(decodedData); mDisplayView.invalidate(); }
public static ETC1Texture testRsETC1ImageCompressor(RenderScript rs, ScriptC_etc1compressor script) { Allocation alloc = Allocation.createFromBitmap(rs, bitmapARGB, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SHARED); // RGB_565 is 2 bytes per pixel RsETC1.encodeImage(rs, script, alloc, bitmapARGB.getWidth(), bitmapARGB.getHeight(), 4, 4 * bitmapARGB.getWidth(), compressedImage, null, false, false); ETC1Texture texture = new ETC1Texture(bitmapARGB.getWidth(), bitmapARGB.getHeight(), compressedImage); alloc.destroy(); // if (texture != null) { // int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE // + texture.getHeight() * texture.getWidth() / 2; // File f = new // File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm"); // f.delete(); // f.createNewFile(); // ETC1Util.writeTexture(texture, new FileOutputStream(f)); // System.out.println("Texture PKM created "); // } // System.out.println("Texture PKM creation failed "); return texture; }
public static ETC1Texture testRsETC1ImageCompressorWithAlpha(RenderScript rs, ScriptC_etc1compressor script) { Allocation alloc = Allocation.createFromBitmap(rs, bitmapARGB, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SHARED); // RGB_565 is 2 bytes per pixel RsETC1.encodeImage(rs, script, alloc, bitmapARGB.getWidth(), bitmapARGB.getHeight(), 4, 4 * bitmapARGB.getWidth(), compressedImage, compressedImageAlpha, false, true); ETC1Texture texture = new ETC1Texture(bitmapARGB.getWidth(), bitmapARGB.getHeight(), compressedImage); alloc.destroy(); // if (texture != null) { // int estimatedMemorySize = ETC1.ETC_PKM_HEADER_SIZE // + texture.getHeight() * texture.getWidth() / 2; // File f = new // File(Environment.getExternalStorageDirectory(),"bmngpkm.pkm"); // f.delete(); // f.createNewFile(); // ETC1Util.writeTexture(texture, new FileOutputStream(f)); // System.out.println("Texture PKM created "); // } // System.out.println("Texture PKM creation failed "); return texture; }
public static ETC1Texture encodeTextureAsETC1_Sdk(InputStream stream) throws IOException, FileNotFoundException { // stream.reset(); // stream.mark(1024); Options opts = new BitmapFactory.Options(); //opts.inPremultiplied = false; opts.inPreferredConfig = Config.RGB_565; Bitmap bitmap = BitmapFactory.decodeStream(stream, null, opts); if (bitmap != null) { ByteBuffer buffer = ByteBuffer.allocateDirect( bitmap.getRowBytes() * bitmap.getHeight()).order( ByteOrder.nativeOrder()); bitmap.copyPixelsToBuffer(buffer); buffer.position(0); System.out.println("Width : " + bitmap.getWidth()); System.out.println("Height : " + bitmap.getHeight()); System.out.println("Config : " + bitmap.getConfig()); if (bitmap.getConfig() == Bitmap.Config.ARGB_4444 || bitmap.getConfig() == Bitmap.Config.ARGB_8888) { System.out.println("Texture need aplha channel"); return null; } final int encodedImageSize = ETC1.getEncodedDataSize( bitmap.getWidth(), bitmap.getHeight()); ByteBuffer compressedImage = ByteBuffer.allocateDirect( encodedImageSize).order(ByteOrder.nativeOrder()); // RGB_565 is 2 bytes per pixel ETC1.encodeImage(buffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedImage); ETC1Texture texture = new ETC1Texture(bitmap.getWidth(), bitmap.getHeight(), compressedImage); return texture; } return null; }
public static ETC1Texture encodeTextureAsETC1_Java(InputStream stream) throws IOException, FileNotFoundException { // stream.reset(); // stream.mark(1024); Options opts = new BitmapFactory.Options(); //opts.inPremultiplied = false; opts.inPreferredConfig = Config.RGB_565; Bitmap bitmap = BitmapFactory.decodeStream(stream, null, opts); if (bitmap != null) { ByteBuffer buffer = ByteBuffer.allocateDirect( bitmap.getRowBytes() * bitmap.getHeight()).order( ByteOrder.nativeOrder()); bitmap.copyPixelsToBuffer(buffer); buffer.position(0); System.out.println("Width : " + bitmap.getWidth()); System.out.println("Height : " + bitmap.getHeight()); System.out.println("Config : " + bitmap.getConfig()); if (bitmap.getConfig() == Bitmap.Config.ARGB_4444 || bitmap.getConfig() == Bitmap.Config.ARGB_8888) { System.out.println("Texture need aplha channel"); return null; } final int encodedImageSize = JavaETC1.getEncodedDataSize( bitmap.getWidth(), bitmap.getHeight()); ByteBuffer compressedImage = ByteBuffer.allocateDirect( encodedImageSize).order(ByteOrder.nativeOrder()); // RGB_565 is 2 bytes per pixel JavaETC1.encodeImage(buffer, bitmap.getWidth(), bitmap.getHeight(), 2, 2 * bitmap.getWidth(), compressedImage); ETC1Texture texture = new ETC1Texture(bitmap.getWidth(), bitmap.getHeight(), compressedImage); return texture; } return null; }