Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 <gui/HdrMetadata.h> |
| 18 | |
| 19 | namespace android { |
| 20 | |
| 21 | size_t HdrMetadata::getFlattenedSize() const { |
| 22 | size_t size = sizeof(validTypes); |
| 23 | if (validTypes & SMPTE2086) { |
| 24 | size += sizeof(smpte2086); |
| 25 | } |
| 26 | if (validTypes & CTA861_3) { |
| 27 | size += sizeof(cta8613); |
| 28 | } |
| 29 | return size; |
| 30 | } |
| 31 | |
| 32 | status_t HdrMetadata::flatten(void* buffer, size_t size) const { |
| 33 | if (size < getFlattenedSize()) { |
| 34 | return NO_MEMORY; |
| 35 | } |
| 36 | |
| 37 | FlattenableUtils::write(buffer, size, validTypes); |
| 38 | if (validTypes & SMPTE2086) { |
| 39 | FlattenableUtils::write(buffer, size, smpte2086); |
| 40 | } |
| 41 | if (validTypes & CTA861_3) { |
| 42 | FlattenableUtils::write(buffer, size, cta8613); |
| 43 | } |
| 44 | |
| 45 | return NO_ERROR; |
| 46 | } |
| 47 | |
| 48 | status_t HdrMetadata::unflatten(void const* buffer, size_t size) { |
| 49 | if (size < sizeof(validTypes)) { |
| 50 | return NO_MEMORY; |
| 51 | } |
| 52 | FlattenableUtils::read(buffer, size, validTypes); |
| 53 | if (validTypes & SMPTE2086) { |
| 54 | if (size < sizeof(smpte2086)) { |
| 55 | return NO_MEMORY; |
| 56 | } |
| 57 | FlattenableUtils::read(buffer, size, smpte2086); |
| 58 | } |
| 59 | if (validTypes & CTA861_3) { |
| 60 | if (size < sizeof(cta8613)) { |
| 61 | return NO_MEMORY; |
| 62 | } |
| 63 | FlattenableUtils::read(buffer, size, cta8613); |
| 64 | } |
| 65 | |
| 66 | return NO_ERROR; |
| 67 | } |
| 68 | |
| 69 | } // namespace android |