1a696f5d667227365da732481770767dcb330dd23Mathias Agopian/*
2a696f5d667227365da732481770767dcb330dd23Mathias Agopian * Copyright (C) 2010 The Android Open Source Project
3a696f5d667227365da732481770767dcb330dd23Mathias Agopian *
4a696f5d667227365da732481770767dcb330dd23Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5a696f5d667227365da732481770767dcb330dd23Mathias Agopian * you may not use this file except in compliance with the License.
6a696f5d667227365da732481770767dcb330dd23Mathias Agopian * You may obtain a copy of the License at
7a696f5d667227365da732481770767dcb330dd23Mathias Agopian *
8a696f5d667227365da732481770767dcb330dd23Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9a696f5d667227365da732481770767dcb330dd23Mathias Agopian *
10a696f5d667227365da732481770767dcb330dd23Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11a696f5d667227365da732481770767dcb330dd23Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12a696f5d667227365da732481770767dcb330dd23Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a696f5d667227365da732481770767dcb330dd23Mathias Agopian * See the License for the specific language governing permissions and
14a696f5d667227365da732481770767dcb330dd23Mathias Agopian * limitations under the License.
15a696f5d667227365da732481770767dcb330dd23Mathias Agopian */
16a696f5d667227365da732481770767dcb330dd23Mathias Agopian
17a696f5d667227365da732481770767dcb330dd23Mathias Agopianpackage android.graphics;
18a696f5d667227365da732481770767dcb330dd23Mathias Agopian
19058d0390a44f68b67788021bae9ca1775812997bMathias Agopianpublic class ImageFormat {
20525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /*
21525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * these constants are chosen to be binary compatible with their previous
22525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * location in PixelFormat.java
23525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
24a696f5d667227365da732481770767dcb330dd23Mathias Agopian
25525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int UNKNOWN = 0;
26a696f5d667227365da732481770767dcb330dd23Mathias Agopian
27525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
289184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * RGB format used for pictures encoded as RGB_565. See
29525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * {@link android.hardware.Camera.Parameters#setPictureFormat(int)}.
30525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
31525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int RGB_565 = 4;
32a696f5d667227365da732481770767dcb330dd23Mathias Agopian
33525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
349184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <p>Android YUV format.</p>
3558a7775d3e12efdc5aaaf19d0ac5e487d622cf36Mathias Agopian     *
369184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <p>This format is exposed to software decoders and applications.</p>
3758a7775d3e12efdc5aaaf19d0ac5e487d622cf36Mathias Agopian     *
389184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <p>YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
399184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * by (W/2) x (H/2) Cr and Cb planes.</p>
4058a7775d3e12efdc5aaaf19d0ac5e487d622cf36Mathias Agopian     *
419184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <p>This format assumes
429184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <ul>
439184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <li>an even width</li>
449184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <li>an even height</li>
459184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <li>a horizontal stride multiple of 16 pixels</li>
469184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <li>a vertical stride equal to the height</li>
479184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * </ul>
489184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * </p>
4958a7775d3e12efdc5aaaf19d0ac5e487d622cf36Mathias Agopian     *
509184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * <pre> y_size = stride * height
51951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * c_stride = ALIGN(stride/2, 16)
52951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * c_size = c_stride * height/2
539184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * size = y_size + c_size * 2
549184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * cr_offset = y_size
559184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * cb_offset = y_size + c_size</pre>
5658a7775d3e12efdc5aaaf19d0ac5e487d622cf36Mathias Agopian     *
57951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>This format is guaranteed to be supported for camera preview images since
589184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * API level 12; for earlier API versions, check
59525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
60951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *
61951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>Note that for camera preview callback use (see
62951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link android.hardware.Camera#setPreviewCallback}), the
63951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <var>stride</var> value is the smallest possible; that is, it is equal
64951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * to:
65951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *
66951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <pre>stride = ALIGN(width, 16)</pre>
67951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *
68951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setPreviewCallback
69951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setPreviewFormat
70951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
719184ec307be30719b2b7bfc3fb3e0a1365ccdf73Eino-Ville Talvala     * </p>
72525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
73525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int YV12 = 0x32315659;
74a696f5d667227365da732481770767dcb330dd23Mathias Agopian
75525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
761eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>Android Y8 format.</p>
771eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
781eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>Y8 is a YUV planar format comprised of a WxH Y plane only, with each pixel
791eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * being represented by 8 bits. It is equivalent to just the Y plane from {@link #YV12}
801eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * format.</p>
811eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
821eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>This format assumes
831eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <ul>
841eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <li>an even width</li>
851eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <li>an even height</li>
861eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <li>a horizontal stride multiple of 16 pixels</li>
871eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * </ul>
881eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * </p>
891eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
901eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <pre> y_size = stride * height </pre>
911eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
921eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>For example, the {@link android.media.Image} object can provide data
932f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * in this format from a {@link android.hardware.camera2.CameraDevice}
941eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * through a {@link android.media.ImageReader} object if this format is
952f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * supported by {@link android.hardware.camera2.CameraDevice}.</p>
961eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
971eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * @see android.media.Image
981eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * @see android.media.ImageReader
992f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * @see android.hardware.camera2.CameraDevice
1001eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1011eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * @hide
1021eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     */
1031eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He    public static final int Y8 = 0x20203859;
1041eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He
1051eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He    /**
1061eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>Android Y16 format.</p>
1071eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1081eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * Y16 is a YUV planar format comprised of a WxH Y plane, with each pixel
1091eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * being represented by 16 bits. It is just like {@link #Y8}, but has 16
1101eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * bits per pixel (little endian).</p>
1111eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1121eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>This format assumes
1131eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <ul>
1141eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <li>an even width</li>
1151eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <li>an even height</li>
1161eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <li>a horizontal stride multiple of 16 pixels</li>
1171eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * </ul>
1181eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * </p>
1191eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1201eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <pre> y_size = stride * height </pre>
1211eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1221eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * <p>For example, the {@link android.media.Image} object can provide data
1232f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * in this format from a {@link android.hardware.camera2.CameraDevice}
1241eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * through a {@link android.media.ImageReader} object if this format is
1252f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * supported by {@link android.hardware.camera2.CameraDevice}.</p>
1261eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1271eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * @see android.media.Image
1281eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * @see android.media.ImageReader
1292f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * @see android.hardware.camera2.CameraDevice
1301eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     *
1311eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     * @hide
1321eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He     */
1331eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He    public static final int Y16 = 0x20363159;
1341eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He
1351eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He    /**
136525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * YCbCr format, used for video. Whether this format is supported by the
137525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * camera hardware can be determined by
138525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
139525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
140525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int NV16 = 0x10;
141a696f5d667227365da732481770767dcb330dd23Mathias Agopian
142525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
143525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * YCrCb format used for images, which uses the NV21 encoding format. This
144525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * is the default format for camera preview images, when not otherwise set
145525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * with {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}.
146525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
147525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int NV21 = 0x11;
148a696f5d667227365da732481770767dcb330dd23Mathias Agopian
149525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
150525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * YCbCr format used for images, which uses YUYV (YUY2) encoding format.
151525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * This is an alternative format for camera preview images. Whether this
152525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * format is supported by the camera hardware can be determined by
153525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
154525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
155525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int YUY2 = 0x14;
156a696f5d667227365da732481770767dcb330dd23Mathias Agopian
157525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
158525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * Encoded formats. These are not necessarily supported by the hardware.
159525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
160525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static final int JPEG = 0x100;
161a696f5d667227365da732481770767dcb330dd23Mathias Agopian
162525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    /**
163b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * <p>Multi-plane Android YUV format</p>
164b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     *
165b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * <p>This format is a generic YCbCr format, capable of describing any 4:2:0
1667a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * chroma-subsampled planar or semiplanar buffer (but not fully interleaved),
1677a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * with 8 bits per color sample.</p>
168b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     *
169b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * <p>Images in this format are always represented by three separate buffers
170b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * of data, one for each color plane. Additional information always
171b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * accompanies the buffers, describing the row stride and the pixel stride
172b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * for each plane.</p>
173b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     *
1747a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * <p>The order of planes in the array returned by
1757a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * {@link android.media.Image#getPlanes() Image#getPlanes()} is guaranteed such that
1767a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * plane #0 is always Y, plane #1 is always U (Cb), and plane #2 is always V (Cr).</p>
1777a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     *
1787a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * <p>The Y-plane is guaranteed not to be interleaved with the U/V planes
1797a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * (in particular, pixel stride is always 1 in
1807a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * {@link android.media.Image.Plane#getPixelStride() yPlane.getPixelStride()}).</p>
1817a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     *
1827a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * <p>The U/V planes are guaranteed to have the same row stride and pixel stride
1837a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * (in particular,
1847a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * {@link android.media.Image.Plane#getRowStride() uPlane.getRowStride()}
1857a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * == {@link android.media.Image.Plane#getRowStride() vPlane.getRowStride()} and
1867a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * {@link android.media.Image.Plane#getPixelStride() uPlane.getPixelStride()}
1877a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * == {@link android.media.Image.Plane#getPixelStride() vPlane.getPixelStride()};
1887a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     * ).</p>
1897a600ff65fa79696a2668c7d33101b6ac6696f04Igor Murashkin     *
190b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * @see android.media.Image
191b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * @see android.media.ImageReader
1922f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * @see android.hardware.camera2.CameraDevice
193b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     */
194b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala    public static final int YUV_420_888 = 0x23;
195b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala
196b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala    /**
197b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * <p>General raw camera sensor image format, usually representing a
198b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * single-channel Bayer-mosaic image. Each pixel color sample is stored with
199b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * 16 bits of precision.</p>
200b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     *
201b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * <p>The layout of the color mosaic, the maximum and minimum encoding
202b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * values of the raw pixel data, the color space of the image, and all other
203b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * needed information to interpret a raw sensor image must be queried from
2042f1a2e423e0fbb64467d6fcfa4e82c6384f31210Eino-Ville Talvala     * the {@link android.hardware.camera2.CameraDevice} which produced the
205b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     * image.</p>
206cd925885283396c0379ec2dcaa94e318993f40f8Eino-Ville Talvala     *
207cd925885283396c0379ec2dcaa94e318993f40f8Eino-Ville Talvala     * @hide
208b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala     */
2091eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He    public static final int RAW_SENSOR = 0x20;
210b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala
211b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala    /**
21270fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     * Raw bayer format used for images, which is 10 bit precision samples
21370fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     * stored in 16 bit words. The filter pattern is RGGB. Whether this format
21470fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     * is supported by the camera hardware can be determined by
21570fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
21670fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     *
21770fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     * @hide
21870fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     */
21970fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li    public static final int BAYER_RGGB = 0x200;
22070fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li
22170fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li    /**
222525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * Use this function to retrieve the number of bits per pixel of an
223525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * ImageFormat.
22470fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li     *
225525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * @param format
226525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     * @return the number of bits per pixel of the given format or -1 if the
227525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     *         format doesn't exist or is not supported.
228525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian     */
229525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    public static int getBitsPerPixel(int format) {
230525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian        switch (format) {
231525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian            case RGB_565:
232525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian                return 16;
233525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian            case NV16:
234525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian                return 16;
235525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian            case YUY2:
236525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian                return 16;
237525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian            case YV12:
238525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian                return 12;
2391eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He            case Y8:
2401eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He                return 8;
2411eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He            case Y16:
2421eb818e5b3481ee1c9722ad6b7bd925afdadb441Zhijun He                return 16;
243525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian            case NV21:
244525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian                return 12;
245b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala            case YUV_420_888:
246b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala                return 12;
247b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala            case RAW_SENSOR:
248b2675542c2f414154125b534767ae0903fba581eEino-Ville Talvala                return 16;
24970fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li            case BAYER_RGGB:
25070fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li                return 16;
251525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian        }
252525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian        return -1;
253525af5d5b0fcd4de9bac2f4be016cdd2f3534a40Mathias Agopian    }
254a696f5d667227365da732481770767dcb330dd23Mathias Agopian}
255