• 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/image.h"
17 
18 #include "impl_factory.h"
19 #include "skia_adapter/skia_image.h"
20 #include "static_factory.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
BackendTexture()25 BackendTexture::BackendTexture() noexcept
26     : isValid_(false) {}
27 
BackendTexture(bool isValid)28 BackendTexture::BackendTexture(bool isValid) noexcept
29     : isValid_(isValid) {}
30 
IsValid() const31 bool BackendTexture::IsValid() const
32 {
33     return isValid_;
34 }
35 
SetTextureInfo(const TextureInfo & textureInfo)36 void BackendTexture::SetTextureInfo(const TextureInfo& textureInfo)
37 {
38     textureInfo_ = textureInfo;
39 }
40 
GetTextureInfo() const41 const TextureInfo& BackendTexture::GetTextureInfo() const
42 {
43     return textureInfo_;
44 }
45 
Image()46 Image::Image() noexcept : imageImplPtr(ImplFactory::CreateImageImpl()) {}
47 
Image(void * rawImg)48 Image::Image(void* rawImg) noexcept : imageImplPtr(ImplFactory::CreateImageImpl(rawImg)) {}
49 
BuildFromBitmap(const Bitmap & bitmap)50 bool Image::BuildFromBitmap(const Bitmap& bitmap)
51 {
52     return imageImplPtr->BuildFromBitmap(bitmap);
53 }
54 
MakeFromRaster(const Pixmap & pixmap,RasterReleaseProc rasterReleaseProc,ReleaseContext releaseContext)55 std::shared_ptr<Image> Image::MakeFromRaster(const Pixmap& pixmap,
56     RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)
57 {
58     return StaticFactory::MakeFromRaster(pixmap, rasterReleaseProc, releaseContext);
59 }
60 
MakeRasterData(const ImageInfo & info,std::shared_ptr<Data> pixels,size_t rowBytes)61 std::shared_ptr<Image> Image::MakeRasterData(const ImageInfo& info, std::shared_ptr<Data> pixels,
62     size_t rowBytes)
63 {
64     return StaticFactory::MakeRasterData(info, pixels, rowBytes);
65 }
66 
67 #ifdef RS_ENABLE_GPU
MakeFromYUVAPixmaps(GPUContext & gpuContext,const YUVInfo & info,void * memory)68 std::shared_ptr<Image> Image::MakeFromYUVAPixmaps(GPUContext& gpuContext, const YUVInfo& info, void* memory)
69 {
70     return StaticFactory::MakeFromYUVAPixmaps(gpuContext, info, memory);
71 }
72 
BuildFromBitmap(GPUContext & gpuContext,const Bitmap & bitmap)73 bool Image::BuildFromBitmap(GPUContext& gpuContext, const Bitmap& bitmap)
74 {
75     return imageImplPtr->BuildFromBitmap(gpuContext, bitmap);
76 }
77 #endif
78 
MakeFromEncoded(const std::shared_ptr<Data> & data)79 bool Image::MakeFromEncoded(const std::shared_ptr<Data>& data)
80 {
81 #ifdef RS_ENABLE_GPU
82     return imageImplPtr->MakeFromEncoded(data);
83 #else
84     return false;
85 #endif
86 }
87 
88 #ifdef RS_ENABLE_GPU
BuildFromCompressed(GPUContext & gpuContext,const std::shared_ptr<Data> & data,int width,int height,CompressedType type,const std::shared_ptr<ColorSpace> & colorSpace)89 bool Image::BuildFromCompressed(GPUContext& gpuContext, const std::shared_ptr<Data>& data, int width, int height,
90     CompressedType type, const std::shared_ptr<ColorSpace>& colorSpace)
91 {
92     return imageImplPtr->BuildFromCompressed(gpuContext, data, width, height, type, colorSpace);
93 }
94 
BuildFromSurface(GPUContext & gpuContext,Surface & surface,TextureOrigin origin,BitmapFormat bitmapFormat,const std::shared_ptr<ColorSpace> & colorSpace)95 bool Image::BuildFromSurface(GPUContext& gpuContext, Surface& surface, TextureOrigin origin,
96     BitmapFormat bitmapFormat, const std::shared_ptr<ColorSpace>& colorSpace)
97 {
98     return imageImplPtr->BuildFromSurface(gpuContext, surface, origin, bitmapFormat, colorSpace);
99 }
100 
BuildFromTexture(GPUContext & gpuContext,const TextureInfo & info,TextureOrigin origin,BitmapFormat bitmapFormat,const std::shared_ptr<ColorSpace> & colorSpace,void (* deleteFunc)(void *),void * cleanupHelper)101 bool Image::BuildFromTexture(GPUContext& gpuContext, const TextureInfo& info, TextureOrigin origin,
102     BitmapFormat bitmapFormat, const std::shared_ptr<ColorSpace>& colorSpace,
103     void (*deleteFunc)(void*), void* cleanupHelper)
104 {
105     return imageImplPtr->BuildFromTexture(gpuContext, info, origin, bitmapFormat,
106         colorSpace, deleteFunc, cleanupHelper);
107 }
108 
BuildSubset(const std::shared_ptr<Image> & image,const RectI & rect,GPUContext & gpuContext)109 bool Image::BuildSubset(const std::shared_ptr<Image>& image, const RectI& rect, GPUContext& gpuContext)
110 {
111     return imageImplPtr->BuildSubset(image, rect, gpuContext);
112 }
113 
GetBackendTexture(bool flushPendingGrContextIO,TextureOrigin * origin) const114 BackendTexture Image::GetBackendTexture(bool flushPendingGrContextIO, TextureOrigin* origin) const
115 {
116     return imageImplPtr->GetBackendTexture(flushPendingGrContextIO, origin);
117 }
118 
IsValid(GPUContext * context) const119 bool Image::IsValid(GPUContext* context) const
120 {
121     return imageImplPtr->IsValid(context);
122 }
123 #endif
124 
AsLegacyBitmap(Bitmap & bitmap) const125 bool Image::AsLegacyBitmap(Bitmap& bitmap) const
126 {
127     return imageImplPtr->AsLegacyBitmap(bitmap);
128 }
129 
GetWidth() const130 int Image::GetWidth() const
131 {
132     return imageImplPtr->GetWidth();
133 }
134 
GetHeight() const135 int Image::GetHeight() const
136 {
137     return imageImplPtr->GetHeight();
138 }
139 
GetColorType() const140 ColorType Image::GetColorType() const
141 {
142     return imageImplPtr->GetColorType();
143 }
144 
GetAlphaType() const145 AlphaType Image::GetAlphaType() const
146 {
147     return imageImplPtr->GetAlphaType();
148 }
149 
GetColorSpace() const150 std::shared_ptr<ColorSpace> Image::GetColorSpace() const
151 {
152     return imageImplPtr->GetColorSpace();
153 }
154 
GetUniqueID() const155 uint32_t Image::GetUniqueID() const
156 {
157     return imageImplPtr->GetUniqueID();
158 }
159 
GetImageInfo()160 ImageInfo Image::GetImageInfo()
161 {
162     return imageImplPtr->GetImageInfo();
163 }
164 
ReadPixels(Bitmap & bitmap,int x,int y)165 bool Image::ReadPixels(Bitmap& bitmap, int x, int y)
166 {
167     return imageImplPtr->ReadPixels(bitmap, x, y);
168 }
169 
ReadPixels(Pixmap & pixmap,int x,int y)170 bool Image::ReadPixels(Pixmap& pixmap, int x, int y)
171 {
172     return imageImplPtr->ReadPixels(pixmap, x, y);
173 }
174 
ReadPixels(const ImageInfo & dstInfo,void * dstPixels,size_t dstRowBytes,int32_t srcX,int32_t srcY) const175 bool Image::ReadPixels(const ImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
176     int32_t srcX, int32_t srcY) const
177 {
178     return imageImplPtr->ReadPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
179 }
180 
IsTextureBacked() const181 bool Image::IsTextureBacked() const
182 {
183     return imageImplPtr->IsTextureBacked();
184 }
185 
ScalePixels(const Bitmap & bitmap,const SamplingOptions & sampling,bool allowCachingHint) const186 bool Image::ScalePixels(const Bitmap& bitmap, const SamplingOptions& sampling, bool allowCachingHint) const
187 {
188     return imageImplPtr->ScalePixels(bitmap, sampling, allowCachingHint);
189 }
190 
EncodeToData(EncodedImageFormat encodedImageFormat,int quality) const191 std::shared_ptr<Data> Image::EncodeToData(EncodedImageFormat encodedImageFormat, int quality) const
192 {
193     return imageImplPtr->EncodeToData(encodedImageFormat, quality);
194 }
195 
IsLazyGenerated() const196 bool Image::IsLazyGenerated() const
197 {
198     return imageImplPtr->IsLazyGenerated();
199 }
200 
GetROPixels(Bitmap & bitmap) const201 bool Image::GetROPixels(Bitmap& bitmap) const
202 {
203     return imageImplPtr->GetROPixels(bitmap);
204 }
205 
MakeRasterImage() const206 std::shared_ptr<Image> Image::MakeRasterImage() const
207 {
208     return imageImplPtr->MakeRasterImage();
209 }
210 
CanPeekPixels() const211 bool Image::CanPeekPixels() const
212 {
213     return imageImplPtr->CanPeekPixels();
214 }
215 
IsOpaque() const216 bool Image::IsOpaque() const
217 {
218     return imageImplPtr->IsOpaque();
219 }
220 
HintCacheGpuResource() const221 void Image::HintCacheGpuResource() const
222 {
223     imageImplPtr->HintCacheGpuResource();
224 }
225 
Serialize() const226 std::shared_ptr<Data> Image::Serialize() const
227 {
228     return imageImplPtr->Serialize();
229 }
230 
Deserialize(std::shared_ptr<Data> data)231 bool Image::Deserialize(std::shared_ptr<Data> data)
232 {
233     return imageImplPtr->Deserialize(data);
234 }
235 
SetHeadroom(float headroom)236 void Image::SetHeadroom(float headroom)
237 {
238     imageImplPtr->SetHeadroom(headroom);
239 }
240 
GetHeadroom() const241 float Image::GetHeadroom() const
242 {
243     return imageImplPtr->GetHeadroom();
244 }
245 } // namespace Drawing
246 } // namespace Rosen
247 } // namespace OHOS
248