• 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 
42 private:
43     std::shared_ptr<Media::PixelMap> pixmap_;
44 };
45 
Create(std::unique_ptr<Media::PixelMap> && pixmap)46 std::shared_ptr<PixelMap> PixelMap::Create(std::unique_ptr<Media::PixelMap>&& pixmap)
47 {
48     return std::make_shared<PixelMapImpl>(std::move(pixmap));
49 }
50 
Create(const std::shared_ptr<Media::PixelMap> & pixmap)51 std::shared_ptr<PixelMap>  PixelMap::Create(const std::shared_ptr<Media::PixelMap>& pixmap)
52 {
53     return std::make_shared<PixelMapImpl>(pixmap);
54 }
55 
GetWidth() const56 int32_t PixelMapImpl::GetWidth() const
57 {
58     CHECK_NULL_RETURN(pixmap_, 0);
59     return pixmap_->GetWidth();
60 }
61 
GetHeight() const62 int32_t PixelMapImpl::GetHeight() const
63 {
64     CHECK_NULL_RETURN(pixmap_, 0);
65     return pixmap_->GetHeight();
66 }
67 
GetPixels() const68 const uint8_t* PixelMapImpl::GetPixels() const
69 {
70     CHECK_NULL_RETURN(pixmap_, nullptr);
71     return pixmap_->GetPixels();
72 }
73 
GetRowStride() const74 int32_t PixelMapImpl::GetRowStride() const
75 {
76     CHECK_NULL_RETURN(pixmap_, 0);
77     return pixmap_->GetRowStride();
78 }
79 
GetRowBytes() const80 int32_t PixelMapImpl::GetRowBytes() const
81 {
82     CHECK_NULL_RETURN(pixmap_, 0);
83     return pixmap_->GetRowBytes();
84 }
85 
GetByteCount() const86 int32_t PixelMapImpl::GetByteCount() const
87 {
88     CHECK_NULL_RETURN(pixmap_, 0);
89     return pixmap_->GetByteCount();
90 }
91 
IsHdr() const92 bool PixelMapImpl::IsHdr() const
93 {
94     CHECK_NULL_RETURN(pixmap_, false);
95     return pixmap_->IsHdr();
96 }
97 
GetRawPixelMapPtr() const98 void* PixelMapImpl::GetRawPixelMapPtr() const
99 {
100     CHECK_NULL_RETURN(pixmap_, nullptr);
101     return pixmap_.get();
102 }
103 
GetPixelMapSharedPtr()104 std::shared_ptr<Media::PixelMap> PixelMapImpl::GetPixelMapSharedPtr()
105 {
106     return pixmap_;
107 }
108 } // namespace Drawable
109 } // namespace Ace
110 } // namespace OHOS
111