1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COLOR_H 17 #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COLOR_H 18 19 #include <sys/types.h> 20 #include <stdint.h> 21 22 #include "common/rs_macros.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 class RSB_EXPORT RSColor final { 27 public: RSColor()28 RSColor() noexcept : alpha_(0), blue_(0), green_(0), red_(0) {} 29 explicit RSColor(uint32_t rgba) noexcept; 30 RSColor(int16_t red, int16_t green, int16_t blue) noexcept; 31 RSColor(int16_t red, int16_t green, int16_t blue, int16_t alpha) noexcept; 32 RSColor(const RSColor& rhs) noexcept = default; 33 RSColor& operator=(const RSColor& rhs) noexcept = default; 34 ~RSColor() = default; 35 bool operator==(const RSColor& rhs) const; 36 inline bool operator!=(const RSColor& rhs) const 37 { 38 return !operator==(rhs); 39 } 40 RSColor operator+(const RSColor& rhs) const; 41 RSColor operator-(const RSColor& rhs) const; 42 RSColor operator*(float scale) const; 43 RSColor operator/(float scale) const; 44 RSColor& operator*=(float scale); 45 uint32_t AsRgbaInt() const; 46 static RSColor FromRgbaInt(uint32_t rgba); 47 uint32_t AsArgbInt() const; 48 static RSColor FromArgbInt(uint32_t rgba); 49 uint32_t AsBgraInt() const; 50 static RSColor FromBgraInt(uint32_t bgra); 51 52 int16_t GetBlue() const; 53 int16_t GetGreen() const; 54 int16_t GetRed() const; 55 int16_t GetAlpha() const; 56 void SetBlue(int16_t blue); 57 void SetGreen(int16_t green); 58 void SetRed(int16_t red); 59 void SetAlpha(int16_t alpha); 60 void MultiplyAlpha(float alpha); 61 GetBytesPerPixelInt()62 static constexpr size_t GetBytesPerPixelInt() 63 { 64 return sizeof(int64_t); 65 } 66 67 private: 68 struct { 69 int16_t alpha_ : 16; 70 int16_t blue_ : 16; 71 int16_t green_ : 16; 72 int16_t red_ : 16; 73 }; 74 }; 75 } // namespace Rosen 76 } // namespace OHOS 77 78 using Color = OHOS::Rosen::RSColor; 79 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_COLOR_H 80