From eebb83493418d8dcd82f33919c41b9a5d2ec898a Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Fri, 22 May 2015 17:13:02 -0700 Subject: ImageFormat: Update definition of depth formats for confidence. DEPTH16: Use high 3 bits for confidence measurement, with 0 = 100% confidence, 1 = 0% confidence, 2 = 1/7 (14.3%) confidence, etc. DEPTH_POINT_CLOUD: Add confidence as 4th entry to each point, with a value in range 0.f - 1.f inclusive. Bug: 20123879 Change-Id: I23317b922ac727751156fa418ed239a696a898e5 --- graphics/java/android/graphics/ImageFormat.java | 50 ++++++++++++++++++++----- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/graphics/java/android/graphics/ImageFormat.java b/graphics/java/android/graphics/ImageFormat.java index d6f8ccad2563..7aa0aef2d06b 100644 --- a/graphics/java/android/graphics/ImageFormat.java +++ b/graphics/java/android/graphics/ImageFormat.java @@ -587,10 +587,29 @@ public class ImageFormat { public static final int RAW12 = 0x26; /** - * Android dense depth image format. - * - * Each pixel is 16 bits, representing a depth ranging measurement from - * a depth camera or similar sensor. + *

Android dense depth image format.

+ * + *

Each pixel is 16 bits, representing a depth ranging measurement from a depth camera or + * similar sensor. The 16-bit sample consists of a confidence value and the actual ranging + * measurement.

+ * + *

The confidence value is an estimate of correctness for this sample. It is encoded in the + * 3 most significant bits of the sample, with a value of 0 representing 100% confidence, a + * value of 1 representing 0% confidence, a value of 2 representing 1/7, a value of 3 + * representing 2/7, and so on.

+ * + *

As an example, the following sample extracts the range and confidence from the first pixel + * of a DEPTH16-format {@link android.media.Image}, and converts the confidence to a + * floating-point value between 0 and 1.f inclusive, with 1.f representing maximum confidence: + * + *

+     *    ShortBuffer shortDepthBuffer = img.getPlanes()[0].getBuffer().asShortBuffer();
+     *    short depthSample = shortDepthBuffer.get()
+     *    short depthRange = (short) (depthSample & 0x1FFF);
+     *    short depthConfidence = (short) ((depthSample >> 13) & 0x7);
+     *    float depthPercentage = depthConfidence == 0 ? 1.f : (depthConfidence - 1) / 7.f;
+     * 
+ *

* *

This format assumes *