The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Mathias Agopian | 42e2458 | 2012-02-21 18:56:08 -0800 | [diff] [blame] | 19 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | namespace android { |
Mathias Agopian | 42e2458 | 2012-02-21 18:56:08 -0800 | [diff] [blame] | 21 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 23 | uint32_t bytesPerPixel(PixelFormat format) { |
Mathias Agopian | 3db2164 | 2010-02-16 20:43:39 -0800 | [diff] [blame] | 24 | switch (format) { |
Mathias Agopian | c2414bb | 2013-07-26 14:49:50 -0700 | [diff] [blame] | 25 | case PIXEL_FORMAT_RGBA_8888: |
| 26 | case PIXEL_FORMAT_RGBX_8888: |
| 27 | case PIXEL_FORMAT_BGRA_8888: |
Dan Stoza | 6a5d35d | 2014-01-07 15:25:02 -0800 | [diff] [blame] | 28 | case PIXEL_FORMAT_sRGB_A_8888: |
| 29 | case PIXEL_FORMAT_sRGB_X_8888: |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 30 | return 4; |
Mathias Agopian | c2414bb | 2013-07-26 14:49:50 -0700 | [diff] [blame] | 31 | case PIXEL_FORMAT_RGB_888: |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 32 | return 3; |
Mathias Agopian | c2414bb | 2013-07-26 14:49:50 -0700 | [diff] [blame] | 33 | case PIXEL_FORMAT_RGB_565: |
| 34 | case PIXEL_FORMAT_RGBA_5551: |
| 35 | case PIXEL_FORMAT_RGBA_4444: |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 36 | return 2; |
Mathias Agopian | 3db2164 | 2010-02-16 20:43:39 -0800 | [diff] [blame] | 37 | } |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 38 | return 0; |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 39 | } |
Mathias Agopian | 3db2164 | 2010-02-16 20:43:39 -0800 | [diff] [blame] | 40 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 41 | uint32_t bitsPerPixel(PixelFormat format) { |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 42 | switch (format) { |
Mathias Agopian | c2414bb | 2013-07-26 14:49:50 -0700 | [diff] [blame] | 43 | case PIXEL_FORMAT_RGBA_8888: |
| 44 | case PIXEL_FORMAT_RGBX_8888: |
| 45 | case PIXEL_FORMAT_BGRA_8888: |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 46 | return 32; |
Mathias Agopian | c2414bb | 2013-07-26 14:49:50 -0700 | [diff] [blame] | 47 | case PIXEL_FORMAT_RGB_888: |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 48 | return 24; |
Mathias Agopian | c2414bb | 2013-07-26 14:49:50 -0700 | [diff] [blame] | 49 | case PIXEL_FORMAT_RGB_565: |
| 50 | case PIXEL_FORMAT_RGBA_5551: |
| 51 | case PIXEL_FORMAT_RGBA_4444: |
Mathias Agopian | 5773d3f | 2013-07-25 19:24:31 -0700 | [diff] [blame] | 52 | return 16; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | } |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 54 | return 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Mathias Agopian | 42e2458 | 2012-02-21 18:56:08 -0800 | [diff] [blame] | 57 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | }; // namespace android |
Mathias Agopian | 42e2458 | 2012-02-21 18:56:08 -0800 | [diff] [blame] | 59 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |