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 17 package android.graphics; 18 19 import android.annotation.IntDef; 20 21 import java.lang.annotation.Retention; 22 import java.lang.annotation.RetentionPolicy; 23 24 public class PixelFormat { 25 26 /** @hide */ 27 @IntDef({UNKNOWN, TRANSLUCENT, TRANSPARENT, OPAQUE}) 28 @Retention(RetentionPolicy.SOURCE) 29 public @interface Opacity {} 30 31 /* these constants need to match those in hardware/hardware.h */ 32 33 public static final int UNKNOWN = 0; 34 35 /** System chooses a format that supports translucency (many alpha bits) */ 36 public static final int TRANSLUCENT = -3; 37 38 /** 39 * System chooses a format that supports transparency 40 * (at least 1 alpha bit) 41 */ 42 public static final int TRANSPARENT = -2; 43 44 /** System chooses an opaque format (no alpha bits required) */ 45 public static final int OPAQUE = -1; 46 47 public static final int RGBA_8888 = 1; 48 public static final int RGBX_8888 = 2; 49 public static final int RGB_888 = 3; 50 public static final int RGB_565 = 4; 51 52 @Deprecated 53 public static final int RGBA_5551 = 6; 54 @Deprecated 55 public static final int RGBA_4444 = 7; 56 @Deprecated 57 public static final int A_8 = 8; 58 @Deprecated 59 public static final int L_8 = 9; 60 @Deprecated 61 public static final int LA_88 = 0xA; 62 @Deprecated 63 public static final int RGB_332 = 0xB; 64 65 66 /** 67 * @deprecated use {@link android.graphics.ImageFormat#NV16 68 * ImageFormat.NV16} instead. 69 */ 70 @Deprecated 71 public static final int YCbCr_422_SP= 0x10; 72 73 /** 74 * @deprecated use {@link android.graphics.ImageFormat#NV21 75 * ImageFormat.NV21} instead. 76 */ 77 @Deprecated 78 public static final int YCbCr_420_SP= 0x11; 79 80 /** 81 * @deprecated use {@link android.graphics.ImageFormat#YUY2 82 * ImageFormat.YUY2} instead. 83 */ 84 @Deprecated 85 public static final int YCbCr_422_I = 0x14; 86 87 /** 88 * @deprecated use {@link android.graphics.ImageFormat#JPEG 89 * ImageFormat.JPEG} instead. 90 */ 91 @Deprecated 92 public static final int JPEG = 0x100; 93 getPixelFormatInfo(int format, PixelFormat info)94 public static void getPixelFormatInfo(int format, PixelFormat info) { 95 switch (format) { 96 case RGBA_8888: 97 case RGBX_8888: 98 info.bitsPerPixel = 32; 99 info.bytesPerPixel = 4; 100 break; 101 case RGB_888: 102 info.bitsPerPixel = 24; 103 info.bytesPerPixel = 3; 104 break; 105 case RGB_565: 106 case RGBA_5551: 107 case RGBA_4444: 108 case LA_88: 109 info.bitsPerPixel = 16; 110 info.bytesPerPixel = 2; 111 break; 112 case A_8: 113 case L_8: 114 case RGB_332: 115 info.bitsPerPixel = 8; 116 info.bytesPerPixel = 1; 117 break; 118 case YCbCr_422_SP: 119 case YCbCr_422_I: 120 info.bitsPerPixel = 16; 121 info.bytesPerPixel = 1; 122 break; 123 case YCbCr_420_SP: 124 info.bitsPerPixel = 12; 125 info.bytesPerPixel = 1; 126 break; 127 default: 128 throw new IllegalArgumentException("unknown pixel format " + format); 129 } 130 } 131 formatHasAlpha(int format)132 public static boolean formatHasAlpha(int format) { 133 switch (format) { 134 case PixelFormat.A_8: 135 case PixelFormat.LA_88: 136 case PixelFormat.RGBA_4444: 137 case PixelFormat.RGBA_5551: 138 case PixelFormat.RGBA_8888: 139 case PixelFormat.TRANSLUCENT: 140 case PixelFormat.TRANSPARENT: 141 return true; 142 } 143 return false; 144 } 145 146 public int bytesPerPixel; 147 public int bitsPerPixel; 148 149 /** 150 * Determine whether or not this is a public-visible and non-deprecated {@code format}. 151 * 152 * <p>In particular, {@code @hide} formats will return {@code false}.</p> 153 * 154 * <p>Any other indirect formats (such as {@code TRANSPARENT} or {@code TRANSLUCENT}) 155 * will return {@code false}.</p> 156 * 157 * @param format an integer format 158 * @return a boolean 159 * 160 * @hide 161 */ isPublicFormat(int format)162 public static boolean isPublicFormat(int format) { 163 switch (format) { 164 case RGBA_8888: 165 case RGBX_8888: 166 case RGB_888: 167 case RGB_565: 168 return true; 169 } 170 171 return false; 172 } 173 } 174