7

I have an ImageReader that is used to get the preview frame's data (byte array). It is configured with the recommended image format of YUV_420_888 like so:

mPreviewImageReader = ImageReader.newInstance(width,
            height, ImageFormat.YUV_420_888, 2);

When the listener I set in mPreviewImageReader.setOnImageAvailableListener(); is called, I retrieve an image:

Image image = reader.acquireLatestImage();

In some phones, I see in the log the following printout with a ImageReader_JNI tag:

ImageReader_imageSetup: Overriding buffer format YUV_420_888 to 32315659.

I searched and it appears that the format is overridden to YV12. I tried looking at the c++ code of ImageReader and discovered where this happens:

int bufFmt = buffer->format;
if (imgReaderFmt == HAL_PIXEL_FORMAT_YCbCr_420_888) {
    bufFmt = buffer->flexFormat;
}
if (imgReaderFmt != bufFmt) {
    if (imgReaderFmt == HAL_PIXEL_FORMAT_YCbCr_420_888 && (bufFmt ==
            HAL_PIXEL_FORMAT_YCrCb_420_SP || bufFmt == HAL_PIXEL_FORMAT_YV12)) {
        // Special casing for when producer switches to a format compatible with flexible YUV
        // (HAL_PIXEL_FORMAT_YCbCr_420_888).
        ctx->setBufferFormat(bufFmt);
        ALOGD("%s: Overriding buffer format YUV_420_888 to %x.", __FUNCTION__, bufFmt);
}
// ... rest of the code

So it seems that the buffer's format is YV12 while the ImageReader's format is YUV_420_888 as I set it.

That brings me to 2 questions regarding this situation that correspond with the 2 options that I have (as far as I can see):

  1. Why is the buffer's format YV12, where is it set and can I change this?
  2. I can add YV12 support - but I need to know that this override occurred. But when calling image.getFormat() I receive 35 which means YUV_420_888. Is there a way to know if this override took place?

Any other ideas are welcome.

3
  • 1
    On my devices this only happens in devices that have LEGACY hardware level and that support the YV12 format. If that format is available, I just select it as the ImageReader format, otherwise I stay with YUV_420_888. Do you also get a gralloc warning with YV12?
    – user1906
    Commented Mar 8, 2016 at 22:31
  • Did you found a solution you can share ?
    – Kiroxas
    Commented Jul 25, 2018 at 16:18
  • Unfortunately no. It's weird that this issue isn't more popular with all of the AR and image recognition apps. Looks like many are still using the original Camera API. Commented Jul 26, 2018 at 7:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.