1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.graphics;
18
19public class ImageFormat {
20    /*
21     * these constants are chosen to be binary compatible with their previous
22     * location in PixelFormat.java
23     */
24
25    public static final int UNKNOWN = 0;
26
27    /**
28     * RGB format used for pictures encoded as RGB_565 see
29     * {@link android.hardware.Camera.Parameters#setPictureFormat(int)}.
30     */
31    public static final int RGB_565 = 4;
32
33    /**
34     * Android YUV format:
35     *
36     * This format is exposed to software decoders and applications.
37     *
38     * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
39     * by (W/2) x (H/2) Cr and Cb planes.
40     *
41     * This format assumes
42     * - an even width
43     * - an even height
44     * - a horizontal stride multiple of 16 pixels
45     * - a vertical stride equal to the height
46     *
47     *   y_size = stride * height
48     *   c_size = ALIGN(stride/2, 16) * height/2
49     *   size = y_size + c_size * 2
50     *   cr_offset = y_size
51     *   cb_offset = y_size + c_size
52     *
53     * Whether this format is supported by the camera hardware can be determined
54     * by
55     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
56     */
57    public static final int YV12 = 0x32315659;
58
59    /**
60     * YCbCr format, used for video. Whether this format is supported by the
61     * camera hardware can be determined by
62     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
63     */
64    public static final int NV16 = 0x10;
65
66    /**
67     * YCrCb format used for images, which uses the NV21 encoding format. This
68     * is the default format for camera preview images, when not otherwise set
69     * with {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}.
70     */
71    public static final int NV21 = 0x11;
72
73    /**
74     * YCbCr format used for images, which uses YUYV (YUY2) encoding format.
75     * This is an alternative format for camera preview images. Whether this
76     * format is supported by the camera hardware can be determined by
77     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
78     */
79    public static final int YUY2 = 0x14;
80
81    /**
82     * Encoded formats. These are not necessarily supported by the hardware.
83     */
84    public static final int JPEG = 0x100;
85
86    /**
87     * Raw bayer format used for images, which is 10 bit precision samples
88     * stored in 16 bit words. The filter pattern is RGGB. Whether this format
89     * is supported by the camera hardware can be determined by
90     * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
91     *
92     * @hide
93     */
94    public static final int BAYER_RGGB = 0x200;
95
96    /**
97     * Use this function to retrieve the number of bits per pixel of an
98     * ImageFormat.
99     *
100     * @param format
101     * @return the number of bits per pixel of the given format or -1 if the
102     *         format doesn't exist or is not supported.
103     */
104    public static int getBitsPerPixel(int format) {
105        switch (format) {
106            case RGB_565:
107                return 16;
108            case NV16:
109                return 16;
110            case YUY2:
111                return 16;
112            case YV12:
113                return 12;
114            case NV21:
115                return 12;
116            case BAYER_RGGB:
117                return 16;
118        }
119        return -1;
120    }
121}
122