blob: 99ed6f7830299344c658284922a215bcf480819d [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:
Dan Stoza6a5d35d2014-01-07 15:25:02 -080028 case PIXEL_FORMAT_sRGB_A_8888:
29 case PIXEL_FORMAT_sRGB_X_8888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070030 return 4;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070031 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070032 return 3;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070033 case PIXEL_FORMAT_RGB_565:
34 case PIXEL_FORMAT_RGBA_5551:
35 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070036 return 2;
Mathias Agopian3db21642010-02-16 20:43:39 -080037 }
Dan Stozad3182402014-11-17 12:03:59 -080038 return 0;
Mathias Agopian5773d3f2013-07-25 19:24:31 -070039}
Mathias Agopian3db21642010-02-16 20:43:39 -080040
Dan Stozad3182402014-11-17 12:03:59 -080041uint32_t bitsPerPixel(PixelFormat format) {
Mathias Agopian5773d3f2013-07-25 19:24:31 -070042 switch (format) {
Mathias Agopianc2414bb2013-07-26 14:49:50 -070043 case PIXEL_FORMAT_RGBA_8888:
44 case PIXEL_FORMAT_RGBX_8888:
45 case PIXEL_FORMAT_BGRA_8888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070046 return 32;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070047 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070048 return 24;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070049 case PIXEL_FORMAT_RGB_565:
50 case PIXEL_FORMAT_RGBA_5551:
51 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070052 return 16;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 }
Dan Stozad3182402014-11-17 12:03:59 -080054 return 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055}
56
Mathias Agopian42e24582012-02-21 18:56:08 -080057// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058}; // namespace android
Mathias Agopian42e24582012-02-21 18:56:08 -080059// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060