blob: 5ce7fba54ec5bf30defeec1d99d33d2ee5f0cd39 [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>
Mathias Agopian3db21642010-02-16 20:43:39 -080018#include <hardware/hardware.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
Mathias Agopian42e24582012-02-21 18:56:08 -080020// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021namespace android {
Mathias Agopian42e24582012-02-21 18:56:08 -080022// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
Mathias Agopian5773d3f2013-07-25 19:24:31 -070024ssize_t bytesPerPixel(PixelFormat format) {
Mathias Agopian3db21642010-02-16 20:43:39 -080025 switch (format) {
Mathias Agopianc2414bb2013-07-26 14:49:50 -070026 case PIXEL_FORMAT_RGBA_8888:
27 case PIXEL_FORMAT_RGBX_8888:
28 case PIXEL_FORMAT_BGRA_8888:
Dan Stoza6a5d35d2014-01-07 15:25:02 -080029 case PIXEL_FORMAT_sRGB_A_8888:
30 case PIXEL_FORMAT_sRGB_X_8888:
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 }
Mathias Agopian5773d3f2013-07-25 19:24:31 -070039 return BAD_VALUE;
40}
Mathias Agopian3db21642010-02-16 20:43:39 -080041
Mathias Agopian5773d3f2013-07-25 19:24:31 -070042ssize_t bitsPerPixel(PixelFormat format) {
43 switch (format) {
Mathias Agopianc2414bb2013-07-26 14:49:50 -070044 case PIXEL_FORMAT_RGBA_8888:
45 case PIXEL_FORMAT_RGBX_8888:
46 case PIXEL_FORMAT_BGRA_8888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070047 return 32;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070048 case PIXEL_FORMAT_RGB_888:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070049 return 24;
Mathias Agopianc2414bb2013-07-26 14:49:50 -070050 case PIXEL_FORMAT_RGB_565:
51 case PIXEL_FORMAT_RGBA_5551:
52 case PIXEL_FORMAT_RGBA_4444:
Mathias Agopian5773d3f2013-07-25 19:24:31 -070053 return 16;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054 }
Mathias Agopian5773d3f2013-07-25 19:24:31 -070055 return BAD_VALUE;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056}
57
Mathias Agopian42e24582012-02-21 18:56:08 -080058// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059}; // namespace android
Mathias Agopian42e24582012-02-21 18:56:08 -080060// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061