问题
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):
- Why is the buffer's format
YV12
, where is it set and can I change this? - I can add
YV12
support - but I need to know that this override occurred. But when callingimage.getFormat()
I receive 35 which meansYUV_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