Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3dd5a398 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Zhijun He
Browse files

Add DEPTH image formats, support in ImageReader

- Add an explicit mapping between public ImageFormat/
  PixelFormat enums and internal HAL format/dataspace.
- Add DEPTH16 and DEPTH_POINT_CLOUD formats
- Wire up mapping layer to ImageReader to support depth
  formats

Change-Id: I8197eccef900cc91baddcfcb934ccd4d8c972eff
parent 981e056c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10786,6 +10786,8 @@ package android.graphics {
  public class ImageFormat {
    ctor public ImageFormat();
    method public static int getBitsPerPixel(int);
    field public static final int DEPTH16 = 1144402265; // 0x44363159
    field public static final int DEPTH_POINT_CLOUD = 257; // 0x101
    field public static final int JPEG = 256; // 0x100
    field public static final int NV16 = 16; // 0x10
    field public static final int NV21 = 17; // 0x11
+2 −0
Original line number Diff line number Diff line
@@ -11092,6 +11092,8 @@ package android.graphics {
  public class ImageFormat {
    ctor public ImageFormat();
    method public static int getBitsPerPixel(int);
    field public static final int DEPTH16 = 1144402265; // 0x44363159
    field public static final int DEPTH_POINT_CLOUD = 257; // 0x101
    field public static final int JPEG = 256; // 0x100
    field public static final int NV16 = 16; // 0x10
    field public static final int NV21 = 17; // 0x11
+94 −0
Original line number Diff line number Diff line
@@ -129,6 +129,100 @@ jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env,
    return surfaceObj;
}

int android_view_Surface_mapPublicFormatToHalFormat(PublicFormat f) {

    switch(f) {
        case JPEG:
        case DEPTH_POINT_CLOUD:
            return HAL_PIXEL_FORMAT_BLOB;
        case DEPTH16:
            return HAL_PIXEL_FORMAT_Y16;
        case RAW_SENSOR:
            return HAL_PIXEL_FORMAT_RAW16;
        default:
            // Most formats map 1:1
            return static_cast<int>(f);
    }
}

android_dataspace android_view_Surface_mapPublicFormatToHalDataspace(
        PublicFormat f) {
    switch(f) {
        case JPEG:
            return HAL_DATASPACE_JFIF;
        case DEPTH_POINT_CLOUD:
        case DEPTH16:
            return HAL_DATASPACE_DEPTH;
        case RAW_SENSOR:
        case RAW10:
            return HAL_DATASPACE_ARBITRARY;
        case YUV_420_888:
        case NV21:
        case YV12:
            return HAL_DATASPACE_JFIF;
        default:
            // Most formats map to UNKNOWN
            return HAL_DATASPACE_UNKNOWN;
    }
}

PublicFormat android_view_Surface_mapHalFormatDataspaceToPublicFormat(
        int format, android_dataspace dataSpace) {
    switch(format) {
        case HAL_PIXEL_FORMAT_RGBA_8888:
        case HAL_PIXEL_FORMAT_RGBX_8888:
        case HAL_PIXEL_FORMAT_RGB_888:
        case HAL_PIXEL_FORMAT_RGB_565:
        case HAL_PIXEL_FORMAT_Y8:
        case HAL_PIXEL_FORMAT_RAW10:
        case HAL_PIXEL_FORMAT_YCbCr_420_888:
        case HAL_PIXEL_FORMAT_YV12:
            // Enums overlap in both name and value
            return static_cast<PublicFormat>(format);
        case HAL_PIXEL_FORMAT_RAW16:
            // Name differs, though value is the same
            return RAW_SENSOR;
        case HAL_PIXEL_FORMAT_YCbCr_422_SP:
            // Name differs, though the value is the same
            return NV16;
        case HAL_PIXEL_FORMAT_YCrCb_420_SP:
            // Name differs, though the value is the same
            return NV21;
        case HAL_PIXEL_FORMAT_YCbCr_422_I:
            // Name differs, though the value is the same
            return YUY2;
        case HAL_PIXEL_FORMAT_Y16:
            // Dataspace-dependent
            switch (dataSpace) {
                case HAL_DATASPACE_DEPTH:
                    return DEPTH16;
                default:
                    // Assume non-depth Y16 is just Y16.
                    return Y16;
            }
            break;
        case HAL_PIXEL_FORMAT_BLOB:
            // Dataspace-dependent
            switch (dataSpace) {
                case HAL_DATASPACE_DEPTH:
                    return DEPTH_POINT_CLOUD;
                case HAL_DATASPACE_JFIF:
                    return JPEG;
                default:
                    // Assume otherwise-marked blobs are also JPEG
                    return JPEG;
            }
            break;
        case HAL_PIXEL_FORMAT_BGRA_8888:
        case HAL_PIXEL_FORMAT_RAW_OPAQUE:
        case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
            // Not defined in public API
            return UNKNOWN;

        default:
            return UNKNOWN;
    }
}
// ----------------------------------------------------------------------------

static inline bool isSurfaceValid(const sp<Surface>& sur) {
+35 −0
Original line number Diff line number Diff line
@@ -355,6 +355,38 @@ public class ImageFormat {
     */
    public static final int RAW10 = 0x25;

    /**
     * Android dense depth image format.
     *
     * Each pixel is 16 bits, representing a depth ranging measurement from
     * a depth camera or similar sensor.
     *
     * <p>This format assumes
     * <ul>
     * <li>an even width</li>
     * <li>an even height</li>
     * <li>a horizontal stride multiple of 16 pixels</li>
     * </ul>
     * </p>
     *
     * <pre> y_size = stride * height </pre>
     *
     * When produced by a camera, the units are millimeters.
     */
    public static final int DEPTH16 = 0x44363159;

    /**
     * Android sparse depth point cloud format.
     *
     * <p>A variable-length list of 3D points, with each point represented
     * by a triple of floats.</p>
     *
     * <p>The number of points is {@code (size of the buffer in bytes) / 12}.
     *
     * The coordinate system and units depend on the source of the point cloud data.
     */
    public static final int DEPTH_POINT_CLOUD = 0x101;

    /**
     * Use this function to retrieve the number of bits per pixel of an
     * ImageFormat.
@@ -376,6 +408,7 @@ public class ImageFormat {
            case Y8:
                return 8;
            case Y16:
            case DEPTH16:
                return 16;
            case NV21:
                return 12;
@@ -412,6 +445,8 @@ public class ImageFormat {
            case YUV_420_888:
            case RAW_SENSOR:
            case RAW10:
            case DEPTH16:
            case DEPTH_POINT_CLOUD:
                return true;
        }

+42 −0
Original line number Diff line number Diff line
@@ -26,6 +26,33 @@ namespace android {
class Surface;
class IGraphicBufferProducer;

/**
 * Enum mirroring the public API definitions for image and pixel formats.
 * Some of these are hidden in the public API
 *
 * Keep up to date with android.graphics.ImageFormat and
 * android.graphics.PixelFormat
 */
enum PublicFormat {
    UNKNOWN           = 0x0,
    RGBA_8888         = 0x1,
    RGBX_8888         = 0x2,
    RGB_888           = 0x3,
    RGB_565           = 0x4,
    NV16              = 0x10,
    NV21              = 0x11,
    YUY2              = 0x14,
    RAW_SENSOR        = 0x20,
    YUV_420_888       = 0x23,
    RAW10             = 0x25,
    JPEG              = 0x100,
    DEPTH_POINT_CLOUD = 0x101,
    YV12              = 0x32315659,
    Y8                = 0x20203859, // @hide
    Y16               = 0x20363159, // @hide
    DEPTH16           = 0x44363159
};

/* Gets the underlying ANativeWindow for a Surface. */
extern sp<ANativeWindow> android_view_Surface_getNativeWindow(
        JNIEnv* env, jobject surfaceObj);
@@ -40,6 +67,21 @@ extern sp<Surface> android_view_Surface_getSurface(JNIEnv* env, jobject surfaceO
extern jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env,
        const sp<IGraphicBufferProducer>& bufferProducer);

/* Convert from android.graphics.ImageFormat/PixelFormat enums to graphics.h HAL
 * format */
extern int android_view_Surface_mapPublicFormatToHalFormat(PublicFormat f);

/* Convert from android.graphics.ImageFormat/PixelFormat enums to graphics.h HAL
 * dataspace */
extern android_dataspace android_view_Surface_mapPublicFormatToHalDataspace(
        PublicFormat f);

/* Convert from HAL format, dataspace pair to
 * android.graphics.ImageFormat/PixelFormat.
 * For unknown/unspecified pairs, returns PublicFormat::UNKNOWN */
extern PublicFormat android_view_Surface_mapHalFormatDataspaceToPublicFormat(
        int format, android_dataspace dataSpace);

} // namespace android

#endif // _ANDROID_VIEW_SURFACE_H
Loading