• 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     uint32_t Marshalling(int64_t rpcId);
46     std::shared_ptr<PixelMap> Unmarshalling(int64_t rpcId, uint32_t* errCode);
47     uint32_t ConvertPixelMapFormat(PixelFormat destFormat);
48 
49     void GetImageInfo(ImageInfo& imageInfo);
50     void Scale(float xAxis, float yAxis);
51     void Scale(float xAxis, float yAxis, AntiAliasingOption option);
52     void Flip(bool xAxis, bool yAxis);
53     void Rotate(float degrees);
54     void Translate(float xAxis, float yAxis);
55 
56     bool GetIsEditable();
57     bool GetIsStrideAlignment();
58 
GetTransferDetach()59     bool GetTransferDetach()
60     {
61         return transferDetach_;
62     }
63 
SetTransferDetach(bool detach)64     void SetTransferDetach(bool detach)
65     {
66         transferDetach_ = detach;
67     }
68 
GetPixelMapImplEditable()69     bool GetPixelMapImplEditable()
70     {
71         return isPixelMapImplEditable;
72     }
73 
74     static std::unique_ptr<PixelMap> CreatePixelMap(const InitializationOptions& opts);
75     static std::unique_ptr<PixelMap> CreatePixelMap(
76         uint32_t* colors, uint32_t colorLength, InitializationOptions& opts);
77     static std::unique_ptr<PixelMap> CreateAlphaPixelMap(PixelMap& source, InitializationOptions& opts);
78     static uint32_t CreatePremultipliedPixelMap(std::shared_ptr<PixelMap> src, std::shared_ptr<PixelMap> dst);
79     static uint32_t CreateUnpremultipliedPixelMap(std::shared_ptr<PixelMap> src, std::shared_ptr<PixelMap> dst);
80     static std::shared_ptr<PixelMap> CreatePixelMapFromSurface(
81         char* surfaceId, Rect region, size_t argc, uint32_t* errCode);
82     static std::shared_ptr<PixelMap> CreatePixelMapFromParcel(int64_t rpcId, uint32_t* errCode);
83 
84 private:
85     std::shared_ptr<PixelMap> real_;
86     bool isPixelMapImplEditable = true;
87     bool transferDetach_ = false;
88 };
89 } // namespace Media
90 } // namespace OHOS
91 
92 #endif
93