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 #include "image/bitmap.h"
17 
18 #include "impl_factory.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
Bitmap()23 Bitmap::Bitmap()
24     : bmpImplPtr(ImplFactory::CreateBitmapImpl())
25 {}
26 
~Bitmap()27 Bitmap::~Bitmap() {}
28 
Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)29 bool Bitmap::Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)
30 {
31     return bmpImplPtr->Build(width, height, format, stride);
32 }
33 
Build(const ImageInfo& imageInfo, int32_t stride)34 bool Bitmap::Build(const ImageInfo& imageInfo, int32_t stride)
35 {
36     return bmpImplPtr->Build(imageInfo, stride);
37 }
38 
GetWidth() const39 int Bitmap::GetWidth() const
40 {
41     return bmpImplPtr->GetWidth();
42 }
43 
GetHeight() const44 int Bitmap::GetHeight() const
45 {
46     return bmpImplPtr->GetHeight();
47 }
48 
GetRowBytes() const49 int Bitmap::GetRowBytes() const
50 {
51     return bmpImplPtr->GetRowBytes();
52 }
53 
GetColorType() const54 ColorType Bitmap::GetColorType() const
55 {
56     return bmpImplPtr->GetColorType();
57 }
58 
GetAlphaType() const59 AlphaType Bitmap::GetAlphaType() const
60 {
61     return bmpImplPtr->GetAlphaType();
62 }
63 
PeekPixels(Pixmap& pixmap) const64 bool Bitmap::PeekPixels(Pixmap& pixmap) const
65 {
66     return bmpImplPtr->PeekPixels(pixmap);
67 }
68 
ComputeByteSize() const69 size_t Bitmap::ComputeByteSize() const
70 {
71     return bmpImplPtr->ComputeByteSize();
72 }
73 
SetPixels(void* pixel)74 void Bitmap::SetPixels(void* pixel)
75 {
76     bmpImplPtr->SetPixels(pixel);
77 }
78 
ExtractSubset(Bitmap& dst, const Rect& subset) const79 bool Bitmap::ExtractSubset(Bitmap& dst, const Rect& subset) const
80 {
81     return bmpImplPtr->ExtractSubset(dst, subset);
82 }
83 
ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int32_t srcX, int32_t srcY) const84 bool Bitmap::ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
85     int32_t srcX, int32_t srcY) const
86 {
87     return bmpImplPtr->ReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
88 }
89 
GetPixels() const90 void* Bitmap::GetPixels() const
91 {
92     return bmpImplPtr->GetPixels();
93 }
94 
CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const95 void Bitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const
96 {
97     bmpImplPtr->CopyPixels(dst, srcLeft, srcTop);
98 }
99 
InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes, ReleaseProc releaseProc, void* context)100 bool Bitmap::InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
101     ReleaseProc releaseProc, void* context)
102 {
103     return bmpImplPtr->InstallPixels(info, pixels, rowBytes, releaseProc, context);
104 }
105 
IsImmutable()106 bool Bitmap::IsImmutable()
107 {
108     return bmpImplPtr->IsImmutable();
109 }
110 
SetImmutable()111 void Bitmap::SetImmutable()
112 {
113     bmpImplPtr->SetImmutable();
114 }
115 
ClearWithColor(const ColorQuad& color) const116 void Bitmap::ClearWithColor(const ColorQuad& color) const
117 {
118     bmpImplPtr->ClearWithColor(color);
119 }
120 
IsValid() const121 bool Bitmap::IsValid() const
122 {
123     return bmpImplPtr->IsValid();
124 }
125 
IsEmpty() const126 bool Bitmap::IsEmpty() const
127 {
128     return bmpImplPtr->IsEmpty();
129 }
130 
GetColor(int x, int y) const131 ColorQuad Bitmap::GetColor(int x, int y) const
132 {
133     return bmpImplPtr->GetColor(x, y);
134 }
135 
Free()136 void Bitmap::Free()
137 {
138     bmpImplPtr->Free();
139 }
140 
GetFormat() const141 BitmapFormat Bitmap::GetFormat() const
142 {
143     ImageInfo imageInfo = GetImageInfo();
144     return {imageInfo.GetColorType(), imageInfo.GetAlphaType()};
145 }
146 
SetFormat(const BitmapFormat& format)147 void Bitmap::SetFormat(const BitmapFormat& format)
148 {
149     ImageInfo imageinfo = GetImageInfo();
150     imageinfo.SetColorType(format.colorType);
151     imageinfo.SetAlphaType(format.alphaType);
152     SetInfo(imageinfo);
153 }
154 
SetInfo(const ImageInfo& info)155 void Bitmap::SetInfo(const ImageInfo& info)
156 {
157     bmpImplPtr->SetInfo(info);
158 }
159 
GetImageInfo() const160 ImageInfo Bitmap::GetImageInfo() const
161 {
162     return bmpImplPtr->GetImageInfo();
163 }
164 
GetPixmap() const165 Pixmap Bitmap::GetPixmap() const
166 {
167     return bmpImplPtr->GetPixmap();
168 }
169 
MakeImage() const170 std::shared_ptr<Image> Bitmap::MakeImage() const
171 {
172     return bmpImplPtr->MakeImage();
173 }
174 
TryAllocPixels(const ImageInfo& info)175 bool Bitmap::TryAllocPixels(const ImageInfo& info)
176 {
177     return bmpImplPtr->TryAllocPixels(info);
178 }
179 
Serialize() const180 std::shared_ptr<Data> Bitmap::Serialize() const
181 {
182     return bmpImplPtr->Serialize();
183 }
184 
Deserialize(std::shared_ptr<Data> data)185 bool Bitmap::Deserialize(std::shared_ptr<Data> data)
186 {
187     return bmpImplPtr->Deserialize(data);
188 }
189 
190 } // namespace Drawing
191 } // namespace Rosen
192 } // namespace OHOS
193