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.

Justin
  • 1,881
  • 4
  • 20
  • 40
kevin
  • 71
  • 1
  • 1
  • 2

2 Answers2

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

Community
  • 1
  • 1
anelson
  • 2,569
  • 1
  • 19
  • 30
  • 1
    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! :) – Robert Jul 25 '11 at 10:51
  • 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. – anelson Aug 06 '11 at 04:12
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

bmkay
  • 462
  • 6
  • 9