• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef PIXEL_MAP_H
16 #define PIXEL_MAP_H
17 
18 #include <string>
19 
20 #include "ffi_remote_data.h"
21 #include "pixel_map.h"
22 
23 namespace OHOS {
24 namespace Media {
25 class FFI_EXPORT PixelMapImpl : public OHOS::FFI::FFIData {
26     DECL_TYPE(PixelMapImpl, OHOS::FFI::FFIData)
27 public:
28     explicit PixelMapImpl(std::shared_ptr<PixelMap> ptr_);
PixelMapImpl(std::shared_ptr<PixelMap> ptr,bool isEditable,bool transferDetach)29     explicit PixelMapImpl(std::shared_ptr<PixelMap> ptr, bool isEditable, bool transferDetach)
30         : real_(ptr), isPixelMapImplEditable(isEditable), transferDetach_(transferDetach) {};
31     std::shared_ptr<PixelMap> GetRealPixelMap();
32     uint32_t ReadPixelsToBuffer(uint64_t& bufferSize, uint8_t* dst);
33     uint32_t WriteBufferToPixels(uint8_t* source, uint64_t& bufferSize);
34     int32_t GetDensity();
35     uint32_t Opacity(float percent);
36     uint32_t Crop(Rect& rect);
37     uint32_t ToSdr();
38     uint32_t GetPixelBytesNumber();
39     uint32_t GetBytesNumberPerRow();
40     uint32_t ReadPixels(uint64_t& bufferSize, uint32_t& offset, uint32_t& stride, Rect& region, uint8_t* dst);
41     uint32_t WritePixels(uint8_t* source, uint64_t& bufferSize, uint32_t& offset, uint32_t& stride, Rect& region);
42     uint32_t SetColorSpace(std::shared_ptr<OHOS::ColorManager::ColorSpace> colorSpace);
43     std::shared_ptr<OHOS::ColorManager::ColorSpace> GetColorSpace();
44     uint32_t ApplyColorSpace(std::shared_ptr<OHOS::ColorManager::ColorSpace> colorSpace);
45 
46     void GetImageInfo(ImageInfo& imageInfo);
47     void Scale(float xAxis, float yAxis);
48     void Scale(float xAxis, float yAxis, AntiAliasingOption option);
49     void Flip(bool xAxis, bool yAxis);
50     void Rotate(float degrees);
51     void Translate(float xAxis, float yAxis);
52 
53     bool GetIsEditable();
54     bool GetIsStrideAlignment();
55 
GetTransferDetach()56     bool GetTransferDetach()
57     {
58         return transferDetach_;
59     }
60 
SetTransferDetach(bool detach)61     void SetTransferDetach(bool detach)
62     {
63         transferDetach_ = detach;
64     }
65 
GetPixelMapImplEditable()66     bool GetPixelMapImplEditable()
67     {
68         return isPixelMapImplEditable;
69     }
70 
71     static std::unique_ptr<PixelMap> CreatePixelMap(const InitializationOptions& opts);
72     static std::unique_ptr<PixelMap> CreatePixelMap(
73         uint32_t* colors, uint32_t colorLength, InitializationOptions& opts);
74     static std::unique_ptr<PixelMap> CreateAlphaPixelMap(PixelMap& source, InitializationOptions& opts);
75     static uint32_t CreatePremultipliedPixelMap(std::shared_ptr<PixelMap> src, std::shared_ptr<PixelMap> dst);
76     static uint32_t CreateUnpremultipliedPixelMap(std::shared_ptr<PixelMap> src, std::shared_ptr<PixelMap> dst);
77 
78 private:
79     std::shared_ptr<PixelMap> real_;
80     bool isPixelMapImplEditable = true;
81     bool transferDetach_ = false;
82 };
83 } // namespace Media
84 } // namespace OHOS
85 
86 #endif
87