ImageFormat.java revision 9184ec307be30719b2b7bfc3fb3e0a1365ccdf73
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 * <p>Android YUV format.</p> 35 * 36 * <p>This format is exposed to software decoders and applications.</p> 37 * 38 * <p>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.</p> 40 * 41 * <p>This format assumes 42 * <ul> 43 * <li>an even width</li> 44 * <li>an even height</li> 45 * <li>a horizontal stride multiple of 16 pixels</li> 46 * <li>a vertical stride equal to the height</li> 47 * </ul> 48 * </p> 49 * 50 * <pre> y_size = stride * height 51 * c_size = ALIGN(stride/2, 16) * height/2 52 * size = y_size + c_size * 2 53 * cr_offset = y_size 54 * cb_offset = y_size + c_size</pre> 55 * 56 * This format is guaranteed to be supported for camera preview images since 57 * API level 12; for earlier API versions, check 58 * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. 59 * </p> 60 */ 61 public static final int YV12 = 0x32315659; 62 63 /** 64 * YCbCr format, used for video. Whether this format is supported by the 65 * camera hardware can be determined by 66 * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. 67 */ 68 public static final int NV16 = 0x10; 69 70 /** 71 * YCrCb format used for images, which uses the NV21 encoding format. This 72 * is the default format for camera preview images, when not otherwise set 73 * with {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}. 74 */ 75 public static final int NV21 = 0x11; 76 77 /** 78 * YCbCr format used for images, which uses YUYV (YUY2) encoding format. 79 * This is an alternative format for camera preview images. Whether this 80 * format is supported by the camera hardware can be determined by 81 * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. 82 */ 83 public static final int YUY2 = 0x14; 84 85 /** 86 * Encoded formats. These are not necessarily supported by the hardware. 87 */ 88 public static final int JPEG = 0x100; 89 90 /** 91 * Raw bayer format used for images, which is 10 bit precision samples 92 * stored in 16 bit words. The filter pattern is RGGB. Whether this format 93 * is supported by the camera hardware can be determined by 94 * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}. 95 * 96 * @hide 97 */ 98 public static final int BAYER_RGGB = 0x200; 99 100 /** 101 * Use this function to retrieve the number of bits per pixel of an 102 * ImageFormat. 103 * 104 * @param format 105 * @return the number of bits per pixel of the given format or -1 if the 106 * format doesn't exist or is not supported. 107 */ 108 public static int getBitsPerPixel(int format) { 109 switch (format) { 110 case RGB_565: 111 return 16; 112 case NV16: 113 return 16; 114 case YUY2: 115 return 16; 116 case YV12: 117 return 12; 118 case NV21: 119 return 12; 120 case BAYER_RGGB: 121 return 16; 122 } 123 return -1; 124 } 125} 126