7

I want to use the onPreviewFrame to post-process the image before displaying it to the user (i.e. apply a color tint, sepia, etc). As I understand, the byte[] data returned to the callback is encoded in YUV420sp. Have people been decoding this to RGB in Java or using NDK (native code)? Does anyone have an example of a function that decodes this to RGB and how the RGB values are used afterwards?

Thanks.

2 Answers 2

7

I found a sample application that translates the YUV420 into RGB and displays (sort of) real time histograms over the preview image.

http://www.stanford.edu/class/ee368/Android/index.html

Sign up to request clarification or add additional context in comments.

2 Comments

Nice link, thanks. I'm running it in a Android virtual target, however the YUV420->RGB decoding is REALLY slow, despite it being just simple additions/multiplications/clamping. Is this something that would be expected in my debugging environment ?? (I'm a complete noob! :)
Yes, the implementation in that code is not optimized at all. If I were doing that sort of thing in a real app I would implement the bit-twiddling in native code.
1

This helps?

Parameters params = mCamera.getParameters(); param.setPreviewFormat(ImageFormat.RGB_565); mCamera.setParameters(param); 

First check if rgb is supported

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getPreviewFormat%28%29

and then set preview format to rgb

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setPreviewFormat%28int%29

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.