Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | #ifndef FLOATCOLOR_H |
| 17 | #define FLOATCOLOR_H |
| 18 | |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame^] | 19 | #include "utils/Color.h" |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 20 | #include "utils/Macros.h" |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 21 | #include "utils/MathUtils.h" |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 22 | |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 23 | #include <stdint.h> |
| 24 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | struct FloatColor { |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame^] | 29 | // "color" is a gamma-encoded sRGB color |
| 30 | // After calling this method, the color is stored as a pre-multiplied linear color |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 31 | void set(uint32_t color) { |
| 32 | a = ((color >> 24) & 0xff) / 255.0f; |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame^] | 33 | r = a * EOCF_sRGB(((color >> 16) & 0xff) / 255.0f); |
| 34 | g = a * EOCF_sRGB(((color >> 8) & 0xff) / 255.0f); |
| 35 | b = a * EOCF_sRGB(((color ) & 0xff) / 255.0f); |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Chris Craik | 2bb8f56 | 2015-02-17 16:42:02 -0800 | [diff] [blame] | 38 | bool isNotBlack() { |
| 39 | return a < 1.0f |
| 40 | || r > 0.0f |
| 41 | || g > 0.0f |
| 42 | || b > 0.0f; |
| 43 | } |
| 44 | |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 45 | bool operator==(const FloatColor& other) const { |
| 46 | return MathUtils::areEqual(r, other.r) |
| 47 | && MathUtils::areEqual(g, other.g) |
| 48 | && MathUtils::areEqual(b, other.b) |
| 49 | && MathUtils::areEqual(a, other.a); |
| 50 | } |
| 51 | |
| 52 | bool operator!=(const FloatColor& other) const { |
| 53 | return !(*this == other); |
| 54 | } |
| 55 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 56 | float r; |
| 57 | float g; |
| 58 | float b; |
| 59 | float a; |
| 60 | }; |
| 61 | |
| 62 | REQUIRE_COMPATIBLE_LAYOUT(FloatColor); |
| 63 | |
| 64 | } /* namespace uirenderer */ |
| 65 | } /* namespace android */ |
| 66 | |
| 67 | #endif /* FLOATCOLOR_H */ |