ImageReader format overridden in some devices

眉间皱痕 提交于 2019-12-09 17:29:13

问题


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.

来源:https://stackoverflow.com/questions/34717969/imagereader-format-overridden-in-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!