1/* 2 * Copyright (C) 2006 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 PixelFormat 20{ 21 /* these constants need to match those 22 in ui/PixelFormat.h & pixelflinger/format.h */ 23 24 public static final int UNKNOWN = 0; 25 26 /** System chooses a format that supports translucency (many alpha bits) */ 27 public static final int TRANSLUCENT = -3; 28 29 /** 30 * System chooses a format that supports transparency 31 * (at least 1 alpha bit) 32 */ 33 public static final int TRANSPARENT = -2; 34 35 /** System chooses an opaque format (no alpha bits required) */ 36 public static final int OPAQUE = -1; 37 38 public static final int RGBA_8888 = 1; 39 public static final int RGBX_8888 = 2; 40 public static final int RGB_888 = 3; 41 public static final int RGB_565 = 4; 42 43 public static final int RGBA_5551 = 6; 44 public static final int RGBA_4444 = 7; 45 public static final int A_8 = 8; 46 public static final int L_8 = 9; 47 public static final int LA_88 = 0xA; 48 public static final int RGB_332 = 0xB; 49 50 /** 51 * YCbCr formats, used for video. These are not necessarily supported 52 * by the hardware. 53 */ 54 public static final int YCbCr_422_SP= 0x10; 55 56 /** YCbCr format used for images, which uses the NV21 encoding format. 57 * This is the default format for camera preview images, when not 58 * otherwise set with 59 * {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}. 60 */ 61 public static final int YCbCr_420_SP= 0x11; 62 63 /** 64 * Encoded formats. These are not necessarily supported by the hardware. 65 */ 66 public static final int JPEG = 0x100; 67 68 /* 69 * We use a class initializer to allow the native code to cache some 70 * field offsets. 71 */ 72 native private static void nativeClassInit(); 73 static { nativeClassInit(); } 74 75 public static native void getPixelFormatInfo(int format, PixelFormat info); 76 public static boolean formatHasAlpha(int format) { 77 switch (format) { 78 case PixelFormat.A_8: 79 case PixelFormat.LA_88: 80 case PixelFormat.RGBA_4444: 81 case PixelFormat.RGBA_5551: 82 case PixelFormat.RGBA_8888: 83 case PixelFormat.TRANSLUCENT: 84 case PixelFormat.TRANSPARENT: 85 return true; 86 } 87 return false; 88 } 89 90 public int bytesPerPixel; 91 public int bitsPerPixel; 92} 93