• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <memory>
17 
18 #include "image_source.h"
19 
20 #include "base/marcos.h"
21 #include "base/pixel_map.h"
22 
23 namespace OHOS {
24 namespace Ace {
25 namespace Drawable {
26 
27 class PixelMapImpl final : public PixelMap {
28 public:
PixelMapImpl(const std::shared_ptr<Media::PixelMap> & pixmap)29     explicit PixelMapImpl(const std::shared_ptr<Media::PixelMap>& pixmap) : pixmap_(std::move(pixmap)) {}
30     ~PixelMapImpl() = default;
31 
32     int32_t GetWidth() const override;
33     int32_t GetHeight() const override;
34     const uint8_t* GetPixels() const override;
35     int32_t GetRowStride() const override;
36     int32_t GetRowBytes() const override;
37     int32_t GetByteCount() const override;
38     void* GetRawPixelMapPtr() const override;
39     std::shared_ptr<Media::PixelMap> GetPixelMapSharedPtr() override;
40     bool IsHdr() const override;
41     void SetMemoryName(std::string pixelMapName) const override;
42 
43 private:
44     std::shared_ptr<Media::PixelMap> pixmap_;
45 };
46 
Create(std::unique_ptr<Media::PixelMap> && pixmap)47 std::shared_ptr<PixelMap> PixelMap::Create(std::unique_ptr<Media::PixelMap>&& pixmap)
48 {
49     return std::make_shared<PixelMapImpl>(std::move(pixmap));
50 }
51 
Create(const std::shared_ptr<Media::PixelMap> & pixmap)52 std::shared_ptr<PixelMap>  PixelMap::Create(const std::shared_ptr<Media::PixelMap>& pixmap)
53 {
54     return std::make_shared<PixelMapImpl>(pixmap);
55 }
56 
GetWidth() const57 int32_t PixelMapImpl::GetWidth() const
58 {
59     CHECK_NULL_RETURN(pixmap_, 0);
60     return pixmap_->GetWidth();
61 }
62 
GetHeight() const63 int32_t PixelMapImpl::GetHeight() const
64 {
65     CHECK_NULL_RETURN(pixmap_, 0);
66     return pixmap_->GetHeight();
67 }
68 
GetPixels() const69 const uint8_t* PixelMapImpl::GetPixels() const
70 {
71     CHECK_NULL_RETURN(pixmap_, nullptr);
72     return pixmap_->GetPixels();
73 }
74 
GetRowStride() const75 int32_t PixelMapImpl::GetRowStride() const
76 {
77     CHECK_NULL_RETURN(pixmap_, 0);
78     return pixmap_->GetRowStride();
79 }
80 
GetRowBytes() const81 int32_t PixelMapImpl::GetRowBytes() const
82 {
83     CHECK_NULL_RETURN(pixmap_, 0);
84     return pixmap_->GetRowBytes();
85 }
86 
GetByteCount() const87 int32_t PixelMapImpl::GetByteCount() const
88 {
89     CHECK_NULL_RETURN(pixmap_, 0);
90     return pixmap_->GetByteCount();
91 }
92 
IsHdr() const93 bool PixelMapImpl::IsHdr() const
94 {
95     CHECK_NULL_RETURN(pixmap_, false);
96     return pixmap_->IsHdr();
97 }
98 
GetRawPixelMapPtr() const99 void* PixelMapImpl::GetRawPixelMapPtr() const
100 {
101     CHECK_NULL_RETURN(pixmap_, nullptr);
102     return pixmap_.get();
103 }
104 
GetPixelMapSharedPtr()105 std::shared_ptr<Media::PixelMap> PixelMapImpl::GetPixelMapSharedPtr()
106 {
107     return pixmap_;
108 }
109 
SetMemoryName(std::string pixelMapName) const110 void PixelMapImpl::SetMemoryName(std::string pixelMapName) const
111 {
112     CHECK_NULL_VOID(pixmap_);
113     pixmap_->SetMemoryName(pixelMapName);
114 }
115 } // namespace Drawable
116 } // namespace Ace
117 } // namespace OHOS
118