package android.media;
import android.graphics.ImageFormat;
+import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
* @param height the height in pixels of the Images that this reader will
* produce.
* @param format the format of the Image that this reader will produce. This
- * must be one of the {@link android.graphics.ImageFormat} constants.
+ * must be one of the {@link android.graphics.ImageFormat} or
+ * {@link android.graphics.PixelFormat} constants.
* @param maxImages the maximum number of images the user will want to
* access simultaneously. This should be as small as possible to limit
* memory use. Once maxImages Images are obtained by the user, one of them
}
}
+ /**
+ * Only a subset of the formats defined in {@link android.graphics.ImageFormat} and
+ * {@link android.graphics.PixelFormat} are supported by ImageReader. When reading RGB
+ * data from a surface, the formats defined in {@link android.graphics.PixelFormat}
+ * can be used, when reading YUV, JPEG or raw sensor data ( for example, from camera
+ * or video decoder), formats from {@link android.graphics.ImageFormat} are used.
+ */
private int getNumPlanesFromFormat() {
switch (mFormat) {
case ImageFormat.YV12:
return 3;
case ImageFormat.NV16:
return 2;
- case ImageFormat.RGB_565:
+ case PixelFormat.RGB_565:
+ case PixelFormat.RGBA_8888:
+ case PixelFormat.RGBX_8888:
+ case PixelFormat.RGB_888:
case ImageFormat.JPEG:
case ImageFormat.YUY2:
case ImageFormat.Y8:
uint32_t dataSize, ySize, cSize, cStride;
uint8_t *cb, *cr;
uint8_t *pData = NULL;
+ int bytesPerPixel = 0;
dataSize = ySize = cSize = cStride = 0;
int32_t fmt = buffer->format;
pData = buffer->data;
dataSize = buffer->width * 2 * buffer->height;
break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ // Single plane, 32bpp.
+ bytesPerPixel = 4;
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ pData = buffer->data;
+ dataSize = buffer->stride * buffer->height * bytesPerPixel;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_565:
+ // Single plane, 16bpp.
+ bytesPerPixel = 2;
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ pData = buffer->data;
+ dataSize = buffer->stride * buffer->height * bytesPerPixel;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ // Single plane, 24bpp.
+ bytesPerPixel = 3;
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ pData = buffer->data;
+ dataSize = buffer->stride * buffer->height * bytesPerPixel;
+ break;
default:
jniThrowExceptionFmt(env, "java/lang/UnsupportedOperationException",
"Pixel format: 0x%x is unsupported", fmt);
break;
case HAL_PIXEL_FORMAT_Y16:
case HAL_PIXEL_FORMAT_RAW_SENSOR:
+ case HAL_PIXEL_FORMAT_RGB_565:
// Single plane 16bpp data.
ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
pixelStride = 2;
break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ pixelStride = 4;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ // Single plane, 24bpp.
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ pixelStride = 3;
+ break;
default:
jniThrowExceptionFmt(env, "java/lang/UnsupportedOperationException",
"Pixel format: 0x%x is unsupported", fmt);
"Stride is not 16 pixel aligned %d", buffer->stride);
rowStride = buffer->stride * 2;
break;
+ case HAL_PIXEL_FORMAT_RGB_565:
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ rowStride = buffer->stride * 2;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ rowStride = buffer->stride * 4;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ // Single plane, 24bpp.
+ ALOG_ASSERT(idx == 0, "Wrong index: %d", idx);
+ rowStride = buffer->stride * 3;
+ break;
default:
ALOGE("%s Pixel format: 0x%x is unsupported", __FUNCTION__, fmt);
jniThrowException(env, "java/lang/UnsupportedOperationException",