• 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 "image_log.h"
17 #include "image_taihe_utils.h"
18 #include "media_errors.h"
19 #include "pixel_map_taihe_ani.h"
20 #include "pixel_map_taihe.h"
21 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
22 #include <regex>
23 #include "pixel_map_from_surface.h"
24 #include "sync_fence.h"
25 #include "transaction/rs_interfaces.h"
26 #endif
27 
28 namespace ANI::Image {
29 
MakeEmptySize()30 Size MakeEmptySize()
31 {
32     return {0, 0};
33 }
34 
MakeEmptyImageInfo()35 ImageInfo MakeEmptyImageInfo()
36 {
37     return {MakeEmptySize(), 0, 0, PixelMapFormat(PixelMapFormat::key_t::UNKNOWN),
38         AlphaType(AlphaType::key_t::UNKNOWN), "", false};
39 }
40 
CreatePixelMapByBufferAndOptionsSync(array_view<uint8_t> colors,InitializationOptions const & options)41 PixelMap CreatePixelMapByBufferAndOptionsSync(array_view<uint8_t> colors, InitializationOptions const& options)
42 {
43     return make_holder<PixelMapImpl, PixelMap>(colors, options);
44 }
45 
CreatePixelMapByOptionsSync(InitializationOptions const & options)46 PixelMap CreatePixelMapByOptionsSync(InitializationOptions const& options)
47 {
48     return make_holder<PixelMapImpl, PixelMap>(options);
49 }
50 
CreatePixelMapByPtr(int64_t ptr)51 PixelMap CreatePixelMapByPtr(int64_t ptr)
52 {
53     return make_holder<PixelMapImpl, PixelMap>(ptr);
54 }
55 
56 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
GetSurfaceSize(std::string const & surfaceId,Media::Rect & region)57 static bool GetSurfaceSize(std::string const& surfaceId, Media::Rect& region)
58 {
59     if (region.width <= 0 || region.height <= 0) {
60         sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(std::stoull(surfaceId));
61         if (surface == nullptr) {
62             IMAGE_LOGE("[PixelMap ANI] GetSurfaceSize: GetSurface failed");
63             return false;
64         }
65         sptr<SyncFence> fence = SyncFence::InvalidFence();
66         // 4 * 4 idetity matrix
67         float matrix[16] = {
68             1, 0, 0, 0,
69             0, 1, 0, 0,
70             0, 0, 1, 0,
71             0, 0, 0, 1
72         };
73         sptr<SurfaceBuffer> surfaceBuffer = nullptr;
74         GSError ret = surface->GetLastFlushedBuffer(surfaceBuffer, fence, matrix);
75         if (ret != GSERROR_OK || surfaceBuffer == nullptr) {
76             IMAGE_LOGE("[PixelMap ANI] GetSurfaceSize: GetLastFlushedBuffer fail, ret = %{public}d", ret);
77             return false;
78         }
79         region.width = surfaceBuffer->GetWidth();
80         region.height = surfaceBuffer->GetHeight();
81     }
82     return true;
83 }
84 
CreatePixelMapFromSurface(std::string const & surfaceId,Media::Rect & region)85 static PixelMap CreatePixelMapFromSurface(std::string const& surfaceId, Media::Rect& region)
86 {
87     if (!std::regex_match(surfaceId, std::regex("\\d+"))) {
88         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Empty or invalid surfaceId");
89         return make_holder<PixelMapImpl, PixelMap>();
90     }
91     if (!GetSurfaceSize(surfaceId, region)) {
92         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Get surface size failed");
93         return make_holder<PixelMapImpl, PixelMap>();
94     }
95 
96     auto &rsClient = Rosen::RSInterfaces::GetInstance();
97     OHOS::Rect r = {
98         .x = region.left,
99         .y = region.top,
100         .w = region.width,
101         .h = region.height,
102     };
103     std::shared_ptr<Media::PixelMap> pixelMap = rsClient.CreatePixelMapFromSurfaceId(std::stoull(surfaceId), r);
104 #ifndef EXT_PIXEL
105     if (pixelMap == nullptr) {
106         pixelMap = CreatePixelMapFromSurfaceId(std::stoull(surfaceId), region);
107     }
108 #endif
109     return make_holder<PixelMapImpl, PixelMap>(std::move(pixelMap));
110 }
111 #endif
112 
CreatePixelMapFromSurfaceByIdSync(string_view etsSurfaceId)113 PixelMap CreatePixelMapFromSurfaceByIdSync(string_view etsSurfaceId)
114 {
115 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
116     return make_holder<PixelMapImpl, PixelMap>();
117 #else
118     std::string surfaceId(etsSurfaceId);
119     Media::Rect region;
120     IMAGE_LOGD("[PixelMap ANI] createPixelMapFromSurfaceByIdSync: id=%{public}s", surfaceId.c_str());
121     return CreatePixelMapFromSurface(surfaceId, region);
122 #endif
123 }
124 
CreatePixelMapFromSurfaceByIdAndRegionSync(string_view etsSurfaceId,ohos::multimedia::image::image::Region const & etsRegion)125 PixelMap CreatePixelMapFromSurfaceByIdAndRegionSync(string_view etsSurfaceId,
126     ohos::multimedia::image::image::Region const& etsRegion)
127 {
128 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
129     return make_holder<PixelMapImpl, PixelMap>();
130 #else
131     std::string surfaceId(etsSurfaceId);
132     Media::Rect region = {etsRegion.x, etsRegion.y, etsRegion.size.width, etsRegion.size.height};
133     IMAGE_LOGD("[PixelMap ANI] createPixelMapFromSurfaceByIdAndRegionSync: id=%{public}s, area=%{public}d,%{public}d,"
134         "%{public}d,%{public}d", surfaceId.c_str(), region.left, region.top, region.width, region.height);
135     if (region.width <= 0 || region.height <= 0) {
136         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Invalid region");
137         return make_holder<PixelMapImpl, PixelMap>();
138     }
139     return CreatePixelMapFromSurface(surfaceId, region);
140 #endif
141 }
142 
PixelMapImpl()143 PixelMapImpl::PixelMapImpl() {}
144 
PixelMapImpl(array_view<uint8_t> const & colors,InitializationOptions const & etsOptions)145 PixelMapImpl::PixelMapImpl(array_view<uint8_t> const& colors, InitializationOptions const& etsOptions)
146 {
147     Media::InitializationOptions options;
148     ParseInitializationOptions(etsOptions, options);
149     if (!Is10BitFormat(options.pixelFormat)) {
150         nativePixelMap_ = Media::PixelMap::Create(reinterpret_cast<uint32_t*>(colors.data()),
151             colors.size() / sizeof(uint32_t), options);
152     }
153     if (nativePixelMap_ == nullptr) {
154         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER,
155             "Create PixelMap by buffer and options failed");
156     }
157 }
158 
PixelMapImpl(InitializationOptions const & etsOptions)159 PixelMapImpl::PixelMapImpl(InitializationOptions const& etsOptions)
160 {
161     Media::InitializationOptions options;
162     ParseInitializationOptions(etsOptions, options);
163     if (Is10BitFormat(options.pixelFormat)) {
164         options.useDMA = true;
165     }
166     nativePixelMap_ = Media::PixelMap::Create(options);
167     if (nativePixelMap_ == nullptr) {
168         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Create PixelMap by options failed");
169     }
170 }
171 
PixelMapImpl(std::shared_ptr<Media::PixelMap> pixelMap)172 PixelMapImpl::PixelMapImpl(std::shared_ptr<Media::PixelMap> pixelMap)
173 {
174     nativePixelMap_ = pixelMap;
175     if (nativePixelMap_ == nullptr) {
176         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Create PixelMap failed");
177     }
178 }
179 
PixelMapImpl(int64_t aniPtr)180 PixelMapImpl::PixelMapImpl(int64_t aniPtr)
181 {
182     Media::PixelMapTaiheAni* pixelMapAni = reinterpret_cast<Media::PixelMapTaiheAni*>(aniPtr);
183     nativePixelMap_ = pixelMapAni->nativePixelMap_;
184     if (nativePixelMap_ == nullptr) {
185         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Create PixelMap failed");
186     }
187 }
188 
~PixelMapImpl()189 PixelMapImpl::~PixelMapImpl()
190 {
191     Release();
192 }
193 
GetImplPtr()194 int64_t PixelMapImpl::GetImplPtr()
195 {
196     return reinterpret_cast<uintptr_t>(this);
197 }
198 
GetNativePtr()199 std::shared_ptr<Media::PixelMap> PixelMapImpl::GetNativePtr()
200 {
201     return nativePixelMap_;
202 }
203 
GetPixelMap(PixelMap etsPixelMap)204 std::shared_ptr<Media::PixelMap> PixelMapImpl::GetPixelMap(PixelMap etsPixelMap)
205 {
206     PixelMapImpl *pixelMapImpl = reinterpret_cast<PixelMapImpl *>(etsPixelMap->GetImplPtr());
207     if (pixelMapImpl == nullptr) {
208         IMAGE_LOGE("%{public}s etsPixelMap is nullptr", __func__);
209         return nullptr;
210     }
211     return pixelMapImpl->GetNativePtr();
212 }
213 
CreatePixelMap(std::shared_ptr<Media::PixelMap> pixelMap)214 PixelMap PixelMapImpl::CreatePixelMap(std::shared_ptr<Media::PixelMap> pixelMap)
215 {
216     return make_holder<PixelMapImpl, PixelMap>(pixelMap);
217 }
218 
GetImageInfoSync()219 ImageInfo PixelMapImpl::GetImageInfoSync()
220 {
221     if (nativePixelMap_ == nullptr) {
222         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
223         return MakeEmptyImageInfo();
224     }
225     if (!aniEditable_) {
226         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
227         return MakeEmptyImageInfo();
228     }
229 
230     Media::ImageInfo imageInfo;
231     nativePixelMap_->GetImageInfo(imageInfo);
232     ImageInfo result = ImageTaiheUtils::ToTaiheImageInfo(imageInfo, nativePixelMap_->IsHdr());
233     result.density = imageInfo.baseDensity;
234     result.stride = nativePixelMap_->GetRowStride();
235     return result;
236 }
237 
ReadPixelsToBufferSync(array_view<uint8_t> dst)238 void PixelMapImpl::ReadPixelsToBufferSync(array_view<uint8_t> dst)
239 {
240     if (nativePixelMap_ == nullptr) {
241         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
242         return;
243     }
244     if (!aniEditable_) {
245         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
246         return;
247     }
248 
249     uint32_t status = nativePixelMap_->ReadPixels(dst.size(), dst.data());
250     if (status != Media::SUCCESS) {
251         IMAGE_LOGE("[PixelMap ANI] ReadPixels failed");
252     }
253 }
254 
ReadPixelsSync(weak::PositionArea area)255 void PixelMapImpl::ReadPixelsSync(weak::PositionArea area)
256 {
257     if (nativePixelMap_ == nullptr) {
258         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
259         return;
260     }
261     if (!aniEditable_) {
262         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
263         return;
264     }
265 
266     ohos::multimedia::image::image::Region etsRegion = area->GetRegion();
267     Media::Rect region = {etsRegion.x, etsRegion.y, etsRegion.size.width, etsRegion.size.height};
268     array<uint8_t> etsPixels = area->GetPixels();
269     uint32_t status = nativePixelMap_->ReadPixels(etsPixels.size(), area->GetOffset(), area->GetStride(), region,
270         etsPixels.data());
271     if (status == Media::SUCCESS) {
272         area->SetPixels(etsPixels);
273     } else {
274         IMAGE_LOGE("[PixelMap ANI] ReadPixels by region failed");
275     }
276 }
277 
WriteBufferToPixelsSync(array_view<uint8_t> src)278 void PixelMapImpl::WriteBufferToPixelsSync(array_view<uint8_t> src)
279 {
280     if (nativePixelMap_ == nullptr) {
281         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
282         return;
283     }
284     if (!aniEditable_) {
285         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
286         return;
287     }
288 
289     uint32_t status = nativePixelMap_->WritePixels(src.data(), src.size());
290     if (status != Media::SUCCESS) {
291         IMAGE_LOGE("[PixelMap ANI] WritePixels failed");
292     }
293 }
294 
CreateAlphaPixelmapSync()295 PixelMap PixelMapImpl::CreateAlphaPixelmapSync()
296 {
297     if (nativePixelMap_ == nullptr) {
298         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
299         return make_holder<PixelMapImpl, PixelMap>();
300     }
301     if (!aniEditable_) {
302         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
303         return make_holder<PixelMapImpl, PixelMap>();
304     }
305 
306     Media::InitializationOptions options;
307     options.pixelFormat = Media::PixelFormat::ALPHA_8;
308     auto alphaPixelMap = Media::PixelMap::Create(*nativePixelMap_, options);
309     return make_holder<PixelMapImpl, PixelMap>(std::move(alphaPixelMap));
310 }
311 
GetBytesNumberPerRow()312 int32_t PixelMapImpl::GetBytesNumberPerRow()
313 {
314     if (nativePixelMap_ == nullptr) {
315         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
316         return 0;
317     }
318     if (!aniEditable_) {
319         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
320         return 0;
321     }
322 
323     return nativePixelMap_->GetRowBytes();
324 }
325 
GetPixelBytesNumber()326 int32_t PixelMapImpl::GetPixelBytesNumber()
327 {
328     if (nativePixelMap_ == nullptr) {
329         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
330         return 0;
331     }
332     if (!aniEditable_) {
333         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
334         return 0;
335     }
336 
337     return nativePixelMap_->GetByteCount();
338 }
339 
ScaleSync(double x,double y)340 void PixelMapImpl::ScaleSync(double x, double y)
341 {
342     if (nativePixelMap_ == nullptr) {
343         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
344         return;
345     }
346     if (!aniEditable_) {
347         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
348         return;
349     }
350 
351     nativePixelMap_->scale(static_cast<float>(x), static_cast<float>(y));
352 }
353 
ScaleWithAntiAliasingSync(double x,double y,AntiAliasingLevel level)354 void PixelMapImpl::ScaleWithAntiAliasingSync(double x, double y, AntiAliasingLevel level)
355 {
356     if (nativePixelMap_ == nullptr) {
357         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
358         return;
359     }
360     if (!aniEditable_) {
361         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
362         return;
363     }
364 
365     nativePixelMap_->scale(static_cast<float>(x), static_cast<float>(y), Media::AntiAliasingOption(level.get_value()));
366 }
367 
CropSync(ohos::multimedia::image::image::Region const & region)368 void PixelMapImpl::CropSync(ohos::multimedia::image::image::Region const& region)
369 {
370     if (nativePixelMap_ == nullptr) {
371         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
372         return;
373     }
374     if (!aniEditable_) {
375         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
376         return;
377     }
378 
379     Media::Rect rect = {region.x, region.y, region.size.width, region.size.height};
380     uint32_t status = nativePixelMap_->crop(rect);
381     if (status != Media::SUCCESS) {
382         IMAGE_LOGE("[PixelMap ANI] crop failed");
383     }
384 }
385 
RotateSync(double angle)386 void PixelMapImpl::RotateSync(double angle)
387 {
388     if (nativePixelMap_ == nullptr) {
389         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
390         return;
391     }
392     if (!aniEditable_) {
393         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
394         return;
395     }
396 
397     nativePixelMap_->rotate(static_cast<float>(angle));
398 }
399 
FlipSync(bool horizontal,bool vertical)400 void PixelMapImpl::FlipSync(bool horizontal, bool vertical)
401 {
402     if (nativePixelMap_ == nullptr) {
403         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
404         return;
405     }
406     if (!aniEditable_) {
407         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
408         return;
409     }
410 
411     nativePixelMap_->flip(horizontal, vertical);
412 }
413 
OpacitySync(double rate)414 void PixelMapImpl::OpacitySync(double rate)
415 {
416     if (nativePixelMap_ == nullptr) {
417         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
418         return;
419     }
420     if (!aniEditable_) {
421         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
422         return;
423     }
424 
425     uint32_t status = nativePixelMap_->SetAlpha(static_cast<float>(rate));
426     if (status != Media::SUCCESS) {
427         IMAGE_LOGE("[PixelMap ANI] SetAlpha failed");
428     }
429 }
430 
SetMemoryNameSync(string_view name)431 void PixelMapImpl::SetMemoryNameSync(string_view name)
432 {
433     if (nativePixelMap_ == nullptr) {
434         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
435         return;
436     }
437     if (!aniEditable_) {
438         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "PixelMap has crossed threads");
439         return;
440     }
441 
442     uint32_t status = nativePixelMap_->SetMemoryName(std::string(name));
443     if (status == Media::ERR_MEMORY_NOT_SUPPORT) {
444         ImageTaiheUtils::ThrowExceptionError(Media::ERR_MEMORY_NOT_SUPPORT, "Set memory name not supported");
445     } else if (status == Media::COMMON_ERR_INVALID_PARAMETER) {
446         ImageTaiheUtils::ThrowExceptionError(Media::COMMON_ERR_INVALID_PARAMETER, "Memory name size out of range");
447     }
448 }
449 
ReleaseSync()450 void PixelMapImpl::ReleaseSync()
451 {
452     if (nativePixelMap_ != nullptr) {
453         if (!nativePixelMap_->IsModifiable()) {
454             ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Unable to release the PixelMap "
455                 "because it's locked or unmodifiable");
456         } else {
457             IMAGE_LOGD("[PixelMap ANI] Releasing PixelMap with ID: %{public}d", nativePixelMap_->GetUniqueId());
458             nativePixelMap_.reset();
459         }
460     }
461 }
462 
GetIsStrideAlignment()463 bool PixelMapImpl::GetIsStrideAlignment()
464 {
465     if (nativePixelMap_ == nullptr) {
466         ImageTaiheUtils::ThrowExceptionError(Media::ERR_RESOURCE_UNAVAILABLE, "Native PixelMap is nullptr");
467         return false;
468     }
469 
470     return nativePixelMap_->IsStrideAlignment();
471 }
472 
SetCaptureId(int32_t captureId)473 void PixelMapImpl::SetCaptureId(int32_t captureId)
474 {
475     captureId_ = captureId;
476 }
477 
GetCaptureId()478 int32_t PixelMapImpl::GetCaptureId()
479 {
480     return captureId_;
481 }
482 
SetTimestamp(int64_t timestamp)483 void PixelMapImpl::SetTimestamp(int64_t timestamp)
484 {
485     timestamp_ = timestamp;
486 }
487 
GetTimestamp()488 int64_t PixelMapImpl::GetTimestamp()
489 {
490     return timestamp_;
491 }
492 
Is10BitFormat(Media::PixelFormat format)493 bool PixelMapImpl::Is10BitFormat(Media::PixelFormat format)
494 {
495     return format == Media::PixelFormat::RGBA_1010102 || format == Media::PixelFormat::YCBCR_P010 ||
496         format == Media::PixelFormat::YCRCB_P010;
497 }
498 
ParseInitializationOptions(InitializationOptions const & etsOptions,Media::InitializationOptions & options)499 void PixelMapImpl::ParseInitializationOptions(InitializationOptions const& etsOptions,
500     Media::InitializationOptions &options)
501 {
502     options.size = {etsOptions.size.width, etsOptions.size.height};
503     if (etsOptions.srcPixelFormat) {
504         options.srcPixelFormat = Media::PixelFormat(etsOptions.srcPixelFormat->get_value());
505     }
506     if (etsOptions.pixelFormat) {
507         options.pixelFormat = Media::PixelFormat(etsOptions.pixelFormat->get_value());
508     }
509     if (etsOptions.editable) {
510         options.editable = *etsOptions.editable;
511     }
512     if (etsOptions.alphaType) {
513         options.alphaType = Media::AlphaType(etsOptions.alphaType->get_value());
514     }
515     if (etsOptions.scaleMode) {
516         options.scaleMode = Media::ScaleMode(etsOptions.scaleMode->get_value());
517     }
518 }
519 
Release()520 void PixelMapImpl::Release()
521 {
522     if (nativePixelMap_ != nullptr) {
523         nativePixelMap_.reset();
524     }
525 }
526 
527 } // namespace ANI::Image
528 
529 TH_EXPORT_CPP_API_MakeEmptySize(ANI::Image::MakeEmptySize);
530 TH_EXPORT_CPP_API_MakeEmptyImageInfo(ANI::Image::MakeEmptyImageInfo);
531 TH_EXPORT_CPP_API_CreatePixelMapByBufferAndOptionsSync(ANI::Image::CreatePixelMapByBufferAndOptionsSync);
532 TH_EXPORT_CPP_API_CreatePixelMapByOptionsSync(ANI::Image::CreatePixelMapByOptionsSync);
533 TH_EXPORT_CPP_API_CreatePixelMapByPtr(ANI::Image::CreatePixelMapByPtr);
534 TH_EXPORT_CPP_API_CreatePixelMapFromSurfaceByIdSync(ANI::Image::CreatePixelMapFromSurfaceByIdSync);
535 TH_EXPORT_CPP_API_CreatePixelMapFromSurfaceByIdAndRegionSync(ANI::Image::CreatePixelMapFromSurfaceByIdAndRegionSync);