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