ImageFormat.java revision a696f5d667227365da732481770767dcb330dd23
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
22     * their previous location in PixelFormat.java */
23
24    public static final int UNKNOWN = 0;
25
26    /** RGB format used for pictures encoded as RGB_565
27     *  see {@link android.hardware.Camera.Parameters#setPictureFormat(int)}.
28     */
29    public static final int RGB_565 = 4;
30
31    /**
32     * YCbCr formats, used for video. These are not necessarily supported
33     * by the hardware.
34     */
35    public static final int NV16 = 0x10;
36
37
38    /** YCrCb format used for images, which uses the NV21 encoding format.
39     *  This is the default format for camera preview images, when not
40     *  otherwise set with
41     *  {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}.
42     */
43    public static final int NV21 = 0x11;
44
45
46    /** YCbCr format used for images, which uses YUYV (YUY2) encoding format.
47     *  This is an alternative format for camera preview images. Whether this
48     *  format is supported by the camera hardware can be determined by
49     *  {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
50     */
51    public static final int YUY2 = 0x14;
52
53
54    /**
55     * Encoded formats.  These are not necessarily supported by the hardware.
56     */
57    public static final int JPEG = 0x100;
58
59
60    /**
61     * Use this function to retrieve the number of bits per pixel of
62     * an ImageFormat.
63     * @param format
64     * @return the number of bits per pixel of the given format or -1 if the
65     * format doesn't exist or is not supported.
66     */
67    public static int getBitsPerPixel(int format) {
68        switch (format) {
69            case RGB_565:   return 16;
70            case NV16:      return 16;
71            case NV21:      return 12;
72            case YUY2:      return 16;
73        }
74        return -1;
75    }
76}
77