1/*
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>
18
19// ----------------------------------------------------------------------------
20namespace android {
21// ----------------------------------------------------------------------------
22
23uint32_t bytesPerPixel(PixelFormat format) {
24    switch (format) {
25        case PIXEL_FORMAT_RGBA_FP16:
26            return 8;
27        case PIXEL_FORMAT_RGBA_8888:
28        case PIXEL_FORMAT_RGBX_8888:
29        case PIXEL_FORMAT_BGRA_8888:
30        case PIXEL_FORMAT_RGBA_1010102:
31            return 4;
32        case PIXEL_FORMAT_RGB_888:
33            return 3;
34        case PIXEL_FORMAT_RGB_565:
35        case PIXEL_FORMAT_RGBA_5551:
36        case PIXEL_FORMAT_RGBA_4444:
37            return 2;
38    }
39    return 0;
40}
41
42uint32_t bitsPerPixel(PixelFormat format) {
43    switch (format) {
44        case PIXEL_FORMAT_RGBA_FP16:
45            return 64;
46        case PIXEL_FORMAT_RGBA_8888:
47        case PIXEL_FORMAT_RGBX_8888:
48        case PIXEL_FORMAT_BGRA_8888:
49        case PIXEL_FORMAT_RGBA_1010102:
50            return 32;
51        case PIXEL_FORMAT_RGB_888:
52            return 24;
53        case PIXEL_FORMAT_RGB_565:
54        case PIXEL_FORMAT_RGBA_5551:
55        case PIXEL_FORMAT_RGBA_4444:
56            return 16;
57    }
58    return 0;
59}
60
61// ----------------------------------------------------------------------------
62}; // namespace android
63// ----------------------------------------------------------------------------
64