blob: 26eb771d73c7e00a57b1c25d6c757cd48d1327f3 [file] [log] [blame]
Jooyung Han2d3a12a2019-03-04 16:28:48 +09001/*
2 * Copyright (C) 2019 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/PublicFormat.h>
18
19// ----------------------------------------------------------------------------
20namespace android {
21// ----------------------------------------------------------------------------
22
23int mapPublicFormatToHalFormat(PublicFormat f) {
24 switch (f) {
25 case PublicFormat::JPEG:
26 case PublicFormat::DEPTH_POINT_CLOUD:
27 return HAL_PIXEL_FORMAT_BLOB;
28 case PublicFormat::DEPTH16:
29 return HAL_PIXEL_FORMAT_Y16;
30 case PublicFormat::RAW_SENSOR:
31 case PublicFormat::RAW_DEPTH:
32 return HAL_PIXEL_FORMAT_RAW16;
33 default:
34 // Most formats map 1:1
35 return static_cast<int>(f);
36 }
37}
38
39android_dataspace mapPublicFormatToHalDataspace(PublicFormat f) {
40 switch (f) {
41 case PublicFormat::JPEG:
42 return HAL_DATASPACE_V0_JFIF;
43 case PublicFormat::DEPTH_POINT_CLOUD:
44 case PublicFormat::DEPTH16:
45 case PublicFormat::RAW_DEPTH:
46 return HAL_DATASPACE_DEPTH;
47 case PublicFormat::RAW_SENSOR:
48 case PublicFormat::RAW_PRIVATE:
49 case PublicFormat::RAW10:
50 case PublicFormat::RAW12:
51 return HAL_DATASPACE_ARBITRARY;
52 case PublicFormat::YUV_420_888:
53 case PublicFormat::NV21:
54 case PublicFormat::YV12:
55 return HAL_DATASPACE_V0_JFIF;
56 default:
57 // Most formats map to UNKNOWN
58 return HAL_DATASPACE_UNKNOWN;
59 }
60}
61
62PublicFormat mapHalFormatDataspaceToPublicFormat(int format, android_dataspace dataSpace) {
63 switch (format) {
64 case HAL_PIXEL_FORMAT_RGBA_8888:
65 case HAL_PIXEL_FORMAT_RGBX_8888:
66 case HAL_PIXEL_FORMAT_RGBA_FP16:
67 case HAL_PIXEL_FORMAT_RGBA_1010102:
68 case HAL_PIXEL_FORMAT_RGB_888:
69 case HAL_PIXEL_FORMAT_RGB_565:
70 case HAL_PIXEL_FORMAT_Y8:
71 case HAL_PIXEL_FORMAT_RAW10:
72 case HAL_PIXEL_FORMAT_RAW12:
73 case HAL_PIXEL_FORMAT_YCbCr_420_888:
74 case HAL_PIXEL_FORMAT_YV12:
75 // Enums overlap in both name and value
76 return static_cast<PublicFormat>(format);
77 case HAL_PIXEL_FORMAT_RAW16:
78 switch (dataSpace) {
79 case HAL_DATASPACE_DEPTH:
80 return PublicFormat::RAW_DEPTH;
81 default:
82 return PublicFormat::RAW_SENSOR;
83 }
84 case HAL_PIXEL_FORMAT_RAW_OPAQUE:
85 // Name differs, though value is the same
86 return PublicFormat::RAW_PRIVATE;
87 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
88 // Name differs, though the value is the same
89 return PublicFormat::NV16;
90 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
91 // Name differs, though the value is the same
92 return PublicFormat::NV21;
93 case HAL_PIXEL_FORMAT_YCbCr_422_I:
94 // Name differs, though the value is the same
95 return PublicFormat::YUY2;
96 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
97 // Name differs, though the value is the same
98 return PublicFormat::PRIVATE;
99 case HAL_PIXEL_FORMAT_Y16:
100 // Dataspace-dependent
101 switch (dataSpace) {
102 case HAL_DATASPACE_DEPTH:
103 return PublicFormat::DEPTH16;
104 default:
105 // Assume non-depth Y16 is just Y16.
106 return PublicFormat::Y16;
107 }
108 case HAL_PIXEL_FORMAT_BLOB:
109 // Dataspace-dependent
110 switch (dataSpace) {
111 case HAL_DATASPACE_DEPTH:
112 return PublicFormat::DEPTH_POINT_CLOUD;
113 case HAL_DATASPACE_V0_JFIF:
114 return PublicFormat::JPEG;
115 default:
116 // Assume otherwise-marked blobs are also JPEG
117 return PublicFormat::JPEG;
118 }
119 case HAL_PIXEL_FORMAT_BGRA_8888:
120 // Not defined in public API
121 return PublicFormat::UNKNOWN;
122
123 default:
124 return PublicFormat::UNKNOWN;
125 }
126}
127
128// ----------------------------------------------------------------------------
129}; // namespace android
130// ----------------------------------------------------------------------------