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 BITMAPIMPL_H 17 #define BITMAPIMPL_H 18 19 #include "base_impl.h" 20 #include "draw/color.h" 21 #include "image/image_info.h" 22 #include "image/pixmap.h" 23 #include "utils/data.h" 24 #include "utils/rect.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 class Bitmap; 30 struct BitmapFormat; 31 typedef void (*ReleaseProc)(void* ptr, void* context); 32 class BitmapImpl : public BaseImpl { 33 public: BitmapImpl()34 BitmapImpl() {} ~BitmapImpl()35 ~BitmapImpl() override {} 36 37 virtual bool Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride = 0, 38 std::shared_ptr<Drawing::ColorSpace> colorSpace = nullptr) = 0; 39 virtual bool Build(const ImageInfo& imageInfo, int32_t stride = 0) = 0; 40 virtual int GetWidth() const = 0; 41 virtual int GetHeight() const = 0; 42 virtual int GetRowBytes() const = 0; 43 virtual ColorType GetColorType() const = 0; 44 virtual AlphaType GetAlphaType() const = 0; 45 virtual bool ExtractSubset(Bitmap& dst, const Rect& subset) const = 0; 46 virtual bool ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 47 int32_t srcX, int32_t srcY) const = 0; 48 virtual void* GetPixels() const = 0; 49 virtual void SetPixels(void* pixel) = 0; 50 virtual void CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const = 0; 51 virtual bool InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes, 52 ReleaseProc releaseProc, void* context) = 0; 53 virtual bool PeekPixels(Pixmap& pixmap) const = 0; 54 virtual size_t ComputeByteSize() const = 0; 55 virtual bool IsImmutable() = 0; 56 virtual void SetImmutable() = 0; 57 virtual void ClearWithColor(const ColorQuad& color) const = 0; 58 virtual ColorQuad GetColor(int x, int y) const = 0; 59 virtual void Free() = 0; 60 virtual bool IsValid() const = 0; 61 virtual bool IsEmpty() const = 0; 62 virtual Pixmap GetPixmap() const = 0; 63 virtual std::shared_ptr<Image> MakeImage() const = 0; 64 virtual void SetInfo(const ImageInfo& info) = 0; 65 virtual bool TryAllocPixels(const ImageInfo& info) = 0; 66 virtual std::shared_ptr<Data> Serialize() const = 0; 67 virtual bool Deserialize(std::shared_ptr<Data> data) = 0; 68 virtual ImageInfo GetImageInfo() = 0; 69 }; 70 } // namespace Drawing 71 } // namespace Rosen 72 } // namespace OHOS 73 #endif 74