blob: e88fdd5e84f5bab6aee572ddab438d700ea18a06 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080018
Mathias Agopian42e24582012-02-21 18:56:08 -080019// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020namespace android {
Mathias Agopian42e24582012-02-21 18:56:08 -080021// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022
Dan Stoza303b9a52014-11-17 12:03:59 -080023uint32_t bytesPerPixel(PixelFormat format) {
Mathias Agopian3db21642010-02-16 20:43:39 -080024 switch (format) {
Romain Guyff415142016-12-13 16:51:25 -080025 case PIXEL_FORMAT_RGBA_FP16:
Romain Guyff415142016-12-13 16:51:25 -080026 return 8;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070027 case PIXEL_FORMAT_RGBA_8888:
28 case PIXEL_FORMAT_RGBX_8888:
29 case PIXEL_FORMAT_BGRA_8888:
Romain Guy541f2262017-02-10 18:50:17 -080030 case PIXEL_FORMAT_RGBA_1010102:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070031 return 4;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070032 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070033 return 3;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070034 case PIXEL_FORMAT_RGB_565:
35 case PIXEL_FORMAT_RGBA_5551:
36 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070037 return 2;
Mathias Agopian3db21642010-02-16 20:43:39 -080038 }
Dan Stoza303b9a52014-11-17 12:03:59 -080039 return 0;
Mathias Agopian5773d3f2013-07-25 19:24:31 -070040}
Mathias Agopian3db21642010-02-16 20:43:39 -080041
Dan Stoza303b9a52014-11-17 12:03:59 -080042uint32_t bitsPerPixel(PixelFormat format) {
Mathias Agopian5773d3f2013-07-25 19:24:31 -070043 switch (format) {
Romain Guyff415142016-12-13 16:51:25 -080044 case PIXEL_FORMAT_RGBA_FP16:
Romain Guyff415142016-12-13 16:51:25 -080045 return 64;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070046 case PIXEL_FORMAT_RGBA_8888:
47 case PIXEL_FORMAT_RGBX_8888:
48 case PIXEL_FORMAT_BGRA_8888:
Romain Guy541f2262017-02-10 18:50:17 -080049 case PIXEL_FORMAT_RGBA_1010102:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070050 return 32;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070051 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070052 return 24;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070053 case PIXEL_FORMAT_RGB_565:
54 case PIXEL_FORMAT_RGBA_5551:
55 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070056 return 16;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 }
Dan Stoza303b9a52014-11-17 12:03:59 -080058 return 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059}
60
Mathias Agopian42e24582012-02-21 18:56:08 -080061// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062}; // namespace android
Mathias Agopian42e24582012-02-21 18:56:08 -080063// ----------------------------------------------------------------------------