blob: cab1dde3fac8619050dc3b272013724ad3dc542b [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 Stozad3182402014-11-17 12:03:59 -080023uint32_t bytesPerPixel(PixelFormat format) {
Mathias Agopian3db21642010-02-16 20:43:39 -080024 switch (format) {
Mathias Agopianc2414bb2013-07-26 14:49:50 -070025 case PIXEL_FORMAT_RGBA_8888:
26 case PIXEL_FORMAT_RGBX_8888:
27 case PIXEL_FORMAT_BGRA_8888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070028 return 4;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070029 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070030 return 3;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070031 case PIXEL_FORMAT_RGB_565:
32 case PIXEL_FORMAT_RGBA_5551:
33 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070034 return 2;
Mathias Agopian3db21642010-02-16 20:43:39 -080035 }
Dan Stozad3182402014-11-17 12:03:59 -080036 return 0;
Mathias Agopian5773d3f2013-07-25 19:24:31 -070037}
Mathias Agopian3db21642010-02-16 20:43:39 -080038
Dan Stozad3182402014-11-17 12:03:59 -080039uint32_t bitsPerPixel(PixelFormat format) {
Mathias Agopian5773d3f2013-07-25 19:24:31 -070040 switch (format) {
Mathias Agopianc2414bb2013-07-26 14:49:50 -070041 case PIXEL_FORMAT_RGBA_8888:
42 case PIXEL_FORMAT_RGBX_8888:
43 case PIXEL_FORMAT_BGRA_8888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070044 return 32;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070045 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070046 return 24;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070047 case PIXEL_FORMAT_RGB_565:
48 case PIXEL_FORMAT_RGBA_5551:
49 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070050 return 16;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 }
Dan Stozad3182402014-11-17 12:03:59 -080052 return 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053}
54
Mathias Agopian42e24582012-02-21 18:56:08 -080055// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056}; // namespace android
Mathias Agopian42e24582012-02-21 18:56:08 -080057// ----------------------------------------------------------------------------