1 /* 2 * Copyright (c) 2021 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(const int width, const int height, const BitmapFormat& format); 34 int GetWidth(); 35 int GetHeight(); 36 void* GetPixels(); 37 void SetPixels(void* pixel); 38 void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const; 39 void ClearWithColor(const ColorQuad& color) const; 40 bool IsValid() const; 41 ColorQuad GetColor(int x, int y) const; 42 void Free(); 43 BitmapFormat GetFormat() const; 44 template<typename T> GetImpl()45 const std::shared_ptr<T> GetImpl() const 46 { 47 return bmpImplPtr->DowncastingTo<T>(); 48 } 49 50 private: 51 std::shared_ptr<BitmapImpl> bmpImplPtr; 52 void* pixels_; 53 int width_; 54 int height_; 55 BitmapFormat format_; 56 }; 57 } // namespace Drawing 58 } // namespace Rosen 59 } // namespace OHOS 60 #endif 61