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,std::shared_ptr<Drawing::ColorSpace> colorSpace)29 bool Bitmap::Build(int32_t width, int32_t height, const BitmapFormat& format,
30     int32_t stride, std::shared_ptr<Drawing::ColorSpace> colorSpace)
31 {
32     return bmpImplPtr->Build(width, height, format, stride, colorSpace);
33 }
34 
Build(const ImageInfo & imageInfo,int32_t stride)35 bool Bitmap::Build(const ImageInfo& imageInfo, int32_t stride)
36 {
37     return bmpImplPtr->Build(imageInfo, stride);
38 }
39 
GetWidth() const40 int Bitmap::GetWidth() const
41 {
42     return bmpImplPtr->GetWidth();
43 }
44 
GetHeight() const45 int Bitmap::GetHeight() const
46 {
47     return bmpImplPtr->GetHeight();
48 }
49 
GetRowBytes() const50 int Bitmap::GetRowBytes() const
51 {
52     return bmpImplPtr->GetRowBytes();
53 }
54 
GetColorType() const55 ColorType Bitmap::GetColorType() const
56 {
57     return bmpImplPtr->GetColorType();
58 }
59 
GetAlphaType() const60 AlphaType Bitmap::GetAlphaType() const
61 {
62     return bmpImplPtr->GetAlphaType();
63 }
64 
PeekPixels(Pixmap & pixmap) const65 bool Bitmap::PeekPixels(Pixmap& pixmap) const
66 {
67     return bmpImplPtr->PeekPixels(pixmap);
68 }
69 
ComputeByteSize() const70 size_t Bitmap::ComputeByteSize() const
71 {
72     return bmpImplPtr->ComputeByteSize();
73 }
74 
SetPixels(void * pixel)75 void Bitmap::SetPixels(void* pixel)
76 {
77     bmpImplPtr->SetPixels(pixel);
78 }
79 
ExtractSubset(Bitmap & dst,const Rect & subset) const80 bool Bitmap::ExtractSubset(Bitmap& dst, const Rect& subset) const
81 {
82     return bmpImplPtr->ExtractSubset(dst, subset);
83 }
84 
ReadPixels(const ImageInfo & dstInfo,void * dstPixels,size_t dstRowBytes,int32_t srcX,int32_t srcY) const85 bool Bitmap::ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
86     int32_t srcX, int32_t srcY) const
87 {
88     return bmpImplPtr->ReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
89 }
90 
GetPixels() const91 void* Bitmap::GetPixels() const
92 {
93     return bmpImplPtr->GetPixels();
94 }
95 
CopyPixels(Bitmap & dst,int srcLeft,int srcTop) const96 void Bitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const
97 {
98     bmpImplPtr->CopyPixels(dst, srcLeft, srcTop);
99 }
100 
InstallPixels(const ImageInfo & info,void * pixels,size_t rowBytes,ReleaseProc releaseProc,void * context)101 bool Bitmap::InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
102     ReleaseProc releaseProc, void* context)
103 {
104     return bmpImplPtr->InstallPixels(info, pixels, rowBytes, releaseProc, context);
105 }
106 
IsImmutable()107 bool Bitmap::IsImmutable()
108 {
109     return bmpImplPtr->IsImmutable();
110 }
111 
SetImmutable()112 void Bitmap::SetImmutable()
113 {
114     bmpImplPtr->SetImmutable();
115 }
116 
ClearWithColor(const ColorQuad & color) const117 void Bitmap::ClearWithColor(const ColorQuad& color) const
118 {
119     bmpImplPtr->ClearWithColor(color);
120 }
121 
IsValid() const122 bool Bitmap::IsValid() const
123 {
124     return bmpImplPtr->IsValid();
125 }
126 
IsEmpty() const127 bool Bitmap::IsEmpty() const
128 {
129     return bmpImplPtr->IsEmpty();
130 }
131 
GetColor(int x,int y) const132 ColorQuad Bitmap::GetColor(int x, int y) const
133 {
134     return bmpImplPtr->GetColor(x, y);
135 }
136 
Free()137 void Bitmap::Free()
138 {
139     bmpImplPtr->Free();
140 }
141 
GetFormat() const142 BitmapFormat Bitmap::GetFormat() const
143 {
144     ImageInfo imageInfo = GetImageInfo();
145     return {imageInfo.GetColorType(), imageInfo.GetAlphaType()};
146 }
147 
SetFormat(const BitmapFormat & format)148 void Bitmap::SetFormat(const BitmapFormat& format)
149 {
150     ImageInfo imageinfo = GetImageInfo();
151     imageinfo.SetColorType(format.colorType);
152     imageinfo.SetAlphaType(format.alphaType);
153     SetInfo(imageinfo);
154 }
155 
SetInfo(const ImageInfo & info)156 void Bitmap::SetInfo(const ImageInfo& info)
157 {
158     bmpImplPtr->SetInfo(info);
159 }
160 
GetImageInfo() const161 ImageInfo Bitmap::GetImageInfo() const
162 {
163     return bmpImplPtr->GetImageInfo();
164 }
165 
GetPixmap() const166 Pixmap Bitmap::GetPixmap() const
167 {
168     return bmpImplPtr->GetPixmap();
169 }
170 
MakeImage() const171 std::shared_ptr<Image> Bitmap::MakeImage() const
172 {
173     return bmpImplPtr->MakeImage();
174 }
175 
TryAllocPixels(const ImageInfo & info)176 bool Bitmap::TryAllocPixels(const ImageInfo& info)
177 {
178     return bmpImplPtr->TryAllocPixels(info);
179 }
180 
Serialize() const181 std::shared_ptr<Data> Bitmap::Serialize() const
182 {
183     return bmpImplPtr->Serialize();
184 }
185 
Deserialize(std::shared_ptr<Data> data)186 bool Bitmap::Deserialize(std::shared_ptr<Data> data)
187 {
188     return bmpImplPtr->Deserialize(data);
189 }
190 
191 } // namespace Drawing
192 } // namespace Rosen
193 } // namespace OHOS
194