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 BITMAP_H 17 #define BITMAP_H 18 19 #include "drawing/engine_adapter/impl_interface/bitmap_impl.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 namespace Drawing { 24 struct BitmapFormat { 25 ColorType colorType; 26 AlphaType alphaType; 27 }; 28 29 class Bitmap { 30 public: 31 Bitmap(); 32 virtual ~Bitmap(); 33 void Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0); 34 35 /* 36 * @brief Gets the width of Bitmap. 37 */ 38 int GetWidth() const; 39 40 /* 41 * @brief Gets the height of Bitmap. 42 */ 43 int GetHeight() const; 44 45 /* 46 * @brief Gets the pointer to Bitmap buffer. 47 */ 48 void* GetPixels() const; 49 void SetPixels(void* pixel); 50 void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const; 51 void ClearWithColor(const ColorQuad& color) const; 52 bool IsValid() const; 53 ColorQuad GetColor(int x, int y) const; 54 void Free(); 55 BitmapFormat GetFormat() const; 56 template<typename T> GetImpl()57 const std::shared_ptr<T> GetImpl() const 58 { 59 return bmpImplPtr->DowncastingTo<T>(); 60 } 61 62 private: 63 std::shared_ptr<BitmapImpl> bmpImplPtr; 64 BitmapFormat format_; 65 }; 66 } // namespace Drawing 67 } // namespace Rosen 68 } // namespace OHOS 69 #endif 70