Closed balbelias closed 7 years ago
Hi @balbelias ! I do not intend to implement JPEG compression in RenderScript because there is an easy way to do that using the current tools:
If you are starting with an Android Bitmap object you can just do this:
FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory() + "/imagename.jpeg");
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
If you are starting with an NV21 image, like a frame the Camera API, you can convert it to a Bitmap from it first to use the code above:
Bitmap myBitmap = Nv21Image.nv21ToBitmap(rs, nv21ByteArray, width, height);
Or just compress directly from NV21:
FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory() + "/imagename.jpg");
YuvImage yuvImage = new YuvImage(nv21bytearray, ImageFormat.NV21, width, height, null);
yuvImage.compressToJpeg(new Rect(0, 0, width, height), 100, fos);
fos.close();
I also happen to think it will be hard to beat the native code that Android provides to do the compression, as they seem to use optimized C code for this.
That said, it would be interesting to see a RenderScript implementation of JPEG compression and I would gladly welcome a pull request about it to see how it compares to the JPEG compression from the Android API.
Thanks for response!
I need JPEG compression for streaming from device camera via mjpeg protocol. Actually I found that mentioned by you direct NV21->jpeg compression is the fastest (~50ms for my settings).
However I will try to look into possible improvement using RS. I am not very familiar with it so it could take much time :) I will let you know if there will be valuable results.
Is it possible to update that tool to support jpeg compression? I have read that mentioned algorithm is not well suitable for gpu processing. do you planning to add that functionality?