• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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       format_({ COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN })
26 {}
27 
~Bitmap()28 Bitmap::~Bitmap() {}
29 
Build(int32_t width,int32_t height,const BitmapFormat & format,int32_t stride)30 void Bitmap::Build(int32_t width, int32_t height, const BitmapFormat& format, int32_t stride)
31 {
32     format_ = format;
33     bmpImplPtr->Build(width, height, format, stride);
34 }
35 
Build(const ImageInfo & imageInfo,int32_t stride)36 void Bitmap::Build(const ImageInfo& imageInfo, int32_t stride)
37 {
38     imageInfo_ = imageInfo;
39     bmpImplPtr->Build(imageInfo_, stride);
40 }
41 
GetWidth() const42 int Bitmap::GetWidth() const
43 {
44     return bmpImplPtr->GetWidth();
45 }
46 
GetHeight() const47 int Bitmap::GetHeight() const
48 {
49     return bmpImplPtr->GetHeight();
50 }
51 
GetRowBytes() const52 int Bitmap::GetRowBytes() const
53 {
54     return bmpImplPtr->GetRowBytes();
55 }
56 
GetColorType() const57 ColorType Bitmap::GetColorType() const
58 {
59     return bmpImplPtr->GetColorType();
60 }
61 
GetAlphaType() const62 AlphaType Bitmap::GetAlphaType() const
63 {
64     return bmpImplPtr->GetAlphaType();
65 }
66 
PeekPixels(Pixmap & pixmap) const67 bool Bitmap::PeekPixels(Pixmap& pixmap) const
68 {
69     return bmpImplPtr->PeekPixels(pixmap);
70 }
71 
ComputeByteSize() const72 size_t Bitmap::ComputeByteSize() const
73 {
74     return bmpImplPtr->ComputeByteSize();
75 }
76 
SetPixels(void * pixel)77 void Bitmap::SetPixels(void* pixel)
78 {
79     bmpImplPtr->SetPixels(pixel);
80 }
81 
ExtractSubset(Bitmap & dst,const Rect & subset) const82 bool Bitmap::ExtractSubset(Bitmap& dst, const Rect& subset) const
83 {
84     return bmpImplPtr->ExtractSubset(dst, subset);
85 }
86 
ReadPixels(const ImageInfo & dstInfo,void * dstPixels,size_t dstRowBytes,int32_t srcX,int32_t srcY) const87 bool Bitmap::ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
88     int32_t srcX, int32_t srcY) const
89 {
90     return bmpImplPtr->ReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
91 }
92 
GetPixels() const93 void* Bitmap::GetPixels() const
94 {
95     return bmpImplPtr->GetPixels();
96 }
97 
CopyPixels(Bitmap & dst,int srcLeft,int srcTop) const98 void Bitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop) const
99 {
100     bmpImplPtr->CopyPixels(dst, srcLeft, srcTop);
101 }
102 
InstallPixels(const ImageInfo & info,void * pixels,size_t rowBytes,ReleaseProc releaseProc,void * context)103 bool Bitmap::InstallPixels(const ImageInfo& info, void* pixels, size_t rowBytes,
104     ReleaseProc releaseProc, void* context)
105 {
106     return bmpImplPtr->InstallPixels(info, pixels, rowBytes, releaseProc, context);
107 }
108 
IsImmutable()109 bool Bitmap::IsImmutable()
110 {
111     return bmpImplPtr->IsImmutable();
112 }
113 
SetImmutable()114 void Bitmap::SetImmutable()
115 {
116     bmpImplPtr->SetImmutable();
117 }
118 
ClearWithColor(const ColorQuad & color) const119 void Bitmap::ClearWithColor(const ColorQuad& color) const
120 {
121     bmpImplPtr->ClearWithColor(color);
122 }
123 
IsValid() const124 bool Bitmap::IsValid() const
125 {
126     return bmpImplPtr->IsValid();
127 }
128 
IsEmpty() const129 bool Bitmap::IsEmpty() const
130 {
131     return bmpImplPtr->IsEmpty();
132 }
133 
GetColor(int x,int y) const134 ColorQuad Bitmap::GetColor(int x, int y) const
135 {
136     return bmpImplPtr->GetColor(x, y);
137 }
138 
Free()139 void Bitmap::Free()
140 {
141     bmpImplPtr->Free();
142 }
143 
GetFormat() const144 BitmapFormat Bitmap::GetFormat() const
145 {
146     return format_;
147 }
148 
SetFormat(const BitmapFormat & format)149 void Bitmap::SetFormat(const BitmapFormat& format)
150 {
151     format_.alphaType = format.alphaType;
152     format_.colorType = format.colorType;
153 }
154 
SetInfo(const ImageInfo & info)155 void Bitmap::SetInfo(const ImageInfo& info)
156 {
157     imageInfo_ = info;
158     bmpImplPtr->SetInfo(info);
159 }
160 
GetImageInfo() const161 ImageInfo Bitmap::GetImageInfo() const
162 {
163     return imageInfo_;
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