PixelFormat.cpp revision c2414bb0989763641ca57cf72c11ef6d86565a23
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#include <hardware/hardware.h>
19
20// ----------------------------------------------------------------------------
21namespace android {
22// ----------------------------------------------------------------------------
23
24ssize_t bytesPerPixel(PixelFormat format) {
25    switch (format) {
26        case PIXEL_FORMAT_RGBA_8888:
27        case PIXEL_FORMAT_RGBX_8888:
28        case PIXEL_FORMAT_BGRA_8888:
29            return 4;
30        case PIXEL_FORMAT_RGB_888:
31            return 3;
32        case PIXEL_FORMAT_RGB_565:
33        case PIXEL_FORMAT_RGBA_5551:
34        case PIXEL_FORMAT_RGBA_4444:
35            return 2;
36    }
37    return BAD_VALUE;
38}
39
40ssize_t bitsPerPixel(PixelFormat format) {
41    switch (format) {
42        case PIXEL_FORMAT_RGBA_8888:
43        case PIXEL_FORMAT_RGBX_8888:
44        case PIXEL_FORMAT_BGRA_8888:
45            return 32;
46        case PIXEL_FORMAT_RGB_888:
47            return 24;
48        case PIXEL_FORMAT_RGB_565:
49        case PIXEL_FORMAT_RGBA_5551:
50        case PIXEL_FORMAT_RGBA_4444:
51            return 16;
52    }
53    return BAD_VALUE;
54}
55
56// ----------------------------------------------------------------------------
57}; // namespace android
58// ----------------------------------------------------------------------------
59
60