• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_bridge.h"
16 
17 #include "base/image/pixel_map.h"
18 #include "base/memory/referenced.h"
19 #include "base/utils/utils.h"
20 #include "bridge/common/utils/engine_helper.h"
21 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
22 #include "bridge/declarative_frontend/engine/js_types.h"
23 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
24 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h"
25 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
26 #include "bridge/declarative_frontend/engine/jsi/jsi_types.h"
27 #include "bridge/declarative_frontend/jsview/js_image.h"
28 #include "bridge/declarative_frontend/jsview/js_utils.h"
29 #include "core/components/common/layout/constants.h"
30 #include "core/components/image/image_event.h"
31 #include "core/components/theme/theme_attributes.h"
32 #include "core/components_ng/pattern/image/image_model_ng.h"
33 #include "core/image/image_source_info.h"
34 #include "core/pipeline/base/constants.h"
35 
36 namespace OHOS::Ace::NG {
37 constexpr int32_t INDEX_0 = 0;      // Arg Index
38 constexpr int32_t INDEX_1 = 1;      // Arg Index
39 constexpr int32_t INDEX_2 = 2;      // Arg Index
40 constexpr int32_t INDEX_3 = 3;      // Arg Index
41 constexpr int32_t INDEX_4 = 4;      // Arg Index
42 constexpr int32_t SIZE_OF_FOUR = 4; // Border Radius array size
43 constexpr int32_t BORDER_RADIUS_INDEX_1 = 2;
44 constexpr int32_t BORDER_RADIUS_INDEX_2 = 3;
45 constexpr int32_t BORDER_RADIUS_INDEX_3 = 4;
46 constexpr int32_t BORDER_RADIUS_INDEX_4 = 4;
47 constexpr int32_t BORDER_RADIUS_VALUE = 0;
48 
PushOuterBorderDimensionVector(const std::optional<CalcDimension> & valueDim,std::vector<ArkUI_Float32> & options)49 void PushOuterBorderDimensionVector(const std::optional<CalcDimension>& valueDim, std::vector<ArkUI_Float32> &options)
50 {
51     options.push_back(static_cast<ArkUI_Float32>(valueDim.has_value()));
52     if (valueDim.has_value()) {
53         options.push_back(static_cast<ArkUI_Float32>(valueDim.value().Value()));
54         options.push_back(static_cast<ArkUI_Float32>(valueDim.value().Unit()));
55     } else {
56         options.push_back(BORDER_RADIUS_VALUE);
57         options.push_back(BORDER_RADIUS_VALUE);
58     }
59 }
60 
ParseOuterBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<ArkUI_Float32> & values)61 void ParseOuterBorderRadius(
62     ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::vector<ArkUI_Float32>& values)
63 {
64     Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(BORDER_RADIUS_INDEX_1);
65     Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(BORDER_RADIUS_INDEX_2);
66     Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(BORDER_RADIUS_INDEX_3);
67     Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(BORDER_RADIUS_INDEX_4);
68 
69     std::optional<CalcDimension> topLeftOptional;
70     std::optional<CalcDimension> topRightOptional;
71     std::optional<CalcDimension> bottomLeftOptional;
72     std::optional<CalcDimension> bottomRightOptional;
73 
74     ArkTSUtils::ParseOuterBorder(vm, topLeftArgs, topLeftOptional);
75     ArkTSUtils::ParseOuterBorder(vm, topRightArgs, topRightOptional);
76     ArkTSUtils::ParseOuterBorder(vm, bottomLeftArgs, bottomLeftOptional);
77     ArkTSUtils::ParseOuterBorder(vm, bottomRightArgs, bottomRightOptional);
78 
79     PushOuterBorderDimensionVector(topLeftOptional, values);
80     PushOuterBorderDimensionVector(topRightOptional, values);
81     PushOuterBorderDimensionVector(bottomLeftOptional, values);
82     PushOuterBorderDimensionVector(bottomRightOptional, values);
83 }
84 
85 const std::vector<float> DEFAULT_COLOR_FILTER_MATRIX = {
86     1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0
87 };
88 
ParseResizableCalcDimensions(ArkUIRuntimeCallInfo * runtimeCallInfo,uint32_t offset,uint32_t count,std::vector<std::optional<CalcDimension>> & results,const CalcDimension & defValue)89 void ParseResizableCalcDimensions(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t offset, uint32_t count,
90     std::vector<std::optional<CalcDimension>>& results, const CalcDimension& defValue)
91 {
92     auto end = offset + count;
93     auto argsNumber = runtimeCallInfo->GetArgsNumber();
94     if (end > argsNumber) {
95         return;
96     }
97     CalcDimension defaultDimension(defValue);
98     EcmaVM* vm = runtimeCallInfo->GetVM();
99     for (uint32_t index = offset; index < end; index++) {
100         auto arg = runtimeCallInfo->GetCallArgRef(index);
101         std::optional<CalcDimension> optCalcDimension;
102         CalcDimension dimension(defValue);
103         if (ArkTSUtils::ParseJsDimensionVp(vm, arg, dimension, false)) {
104             optCalcDimension = dimension;
105         } else {
106             optCalcDimension = defaultDimension;
107         }
108         results.push_back(optCalcDimension);
109     }
110 }
111 
PushDimensionsToVector(std::vector<ArkUIStringAndFloat> & results,const std::vector<std::optional<CalcDimension>> & optDimensions)112 void PushDimensionsToVector(std::vector<ArkUIStringAndFloat>& results,
113     const std::vector<std::optional<CalcDimension>>& optDimensions)
114 {
115     for (uint32_t index = 0; index < optDimensions.size(); index++) {
116         auto optDimension = optDimensions[index];
117         auto hasValue = optDimension.has_value();
118         DimensionUnit unit = DimensionUnit::PX;
119         ArkUIStringAndFloat value = { 0.0, nullptr };
120         if (hasValue) {
121             unit = optDimension.value().Unit();
122             if (unit == DimensionUnit::CALC) {
123                 value.valueStr = optDimension.value().CalcValue().c_str();
124             } else {
125                 value.value = optDimension.value().Value();
126             }
127         }
128         results.push_back(ArkUIStringAndFloat { static_cast<double>(hasValue), nullptr });
129         results.push_back(value);
130         results.push_back(ArkUIStringAndFloat { static_cast<double>(unit), nullptr });
131     }
132 }
133 
CheckIsCard()134 bool ImageBridge::CheckIsCard()
135 {
136     auto container = Container::Current();
137     CHECK_NULL_RETURN(container, false);
138     auto context = PipelineBase::GetCurrentContext();
139     CHECK_NULL_RETURN(context, false);
140     return context->IsFormRender() && !container->IsDynamicRender();
141 }
142 
SetImageShowSrc(ArkUIRuntimeCallInfo * runtimeCallInfo)143 ArkUINativeModuleValue ImageBridge::SetImageShowSrc(ArkUIRuntimeCallInfo* runtimeCallInfo)
144 {
145     EcmaVM* vm = runtimeCallInfo->GetVM();
146     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
147     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
148     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
149     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
150     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
151 
152     bool isCard = CheckIsCard();
153     std::string src;
154     int32_t resId = 0;
155     if (info[1]->IsNumber()) {
156         GetArkUINodeModifiers()->getImageModifier()->resetImageContent(nativeNode);
157         return panda::JSValueRef::Undefined(vm);
158     }
159     if (info[0]->IsObject()) {
160         Framework::JSRef<Framework::JSObject> jsObj = Framework::JSRef<Framework::JSObject>::Cast(info[0]);
161         Framework::JSRef<Framework::JSVal> tmp = jsObj->GetProperty("id");
162         if (!tmp->IsNull() && tmp->IsNumber()) {
163             resId = tmp->ToNumber<int32_t>();
164         }
165     }
166     bool srcValid = ArkTSUtils::ParseJsMedia(vm, secondArg, src);
167     if (isCard && secondArg->IsString(vm)) {
168         SrcType srcType = ImageSourceInfo::ResolveURIType(src);
169         bool notSupport = (srcType == SrcType::NETWORK || srcType == SrcType::FILE || srcType == SrcType::DATA_ABILITY);
170         if (notSupport) {
171             src.clear();
172         }
173     }
174     std::string bundleName;
175     std::string moduleName;
176     ArkTSUtils::GetJsMediaBundleInfo(vm, secondArg, bundleName, moduleName);
177     RefPtr<PixelMap> pixmap = nullptr;
178     if (!srcValid && !isCard) {
179 #if defined (PIXEL_MAP_SUPPORTED)
180         if (Framework::IsDrawable(info[1])) {
181             pixmap = Framework::GetDrawablePixmap(info[1]);
182         } else {
183             pixmap = Framework::CreatePixelMapFromNapiValue(info[1]);
184         }
185 #endif
186     }
187     if (pixmap) {
188         ImageModelNG::SetInitialPixelMap(reinterpret_cast<FrameNode*>(nativeNode), pixmap);
189     } else {
190         GetArkUINodeModifiers()->getImageModifier()->setImageShowSrc(
191             nativeNode, src.c_str(), bundleName.c_str(), moduleName.c_str(), (resId == -1));
192     }
193     return panda::JSValueRef::Undefined(vm);
194 }
195 
SetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)196 ArkUINativeModuleValue ImageBridge::SetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
197 {
198     EcmaVM* vm = runtimeCallInfo->GetVM();
199     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
200     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
201     Local<JSValueRef> optionArg = runtimeCallInfo->GetCallArgRef(1);
202     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
203     if (optionArg->IsNumber()) {
204         int32_t option = optionArg->Int32Value(vm);
205         GetArkUINodeModifiers()->getImageModifier()->setCopyOption(nativeNode, option);
206     } else {
207         GetArkUINodeModifiers()->getImageModifier()->resetCopyOption(nativeNode);
208     }
209     return panda::JSValueRef::Undefined(vm);
210 }
211 
ResetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)212 ArkUINativeModuleValue ImageBridge::ResetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
213 {
214     EcmaVM* vm = runtimeCallInfo->GetVM();
215     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
216     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
217     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
218     GetArkUINodeModifiers()->getImageModifier()->resetCopyOption(nativeNode);
219     return panda::JSValueRef::Undefined(vm);
220 }
221 
SetAutoResize(ArkUIRuntimeCallInfo * runtimeCallInfo)222 ArkUINativeModuleValue ImageBridge::SetAutoResize(ArkUIRuntimeCallInfo* runtimeCallInfo)
223 {
224     EcmaVM* vm = runtimeCallInfo->GetVM();
225     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
226     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
227     Local<JSValueRef> autoResizeArg = runtimeCallInfo->GetCallArgRef(1);
228     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
229     if (autoResizeArg->IsBoolean()) {
230         bool autoResize = autoResizeArg->ToBoolean(vm)->Value();
231         GetArkUINodeModifiers()->getImageModifier()->setAutoResize(nativeNode, autoResize);
232     } else {
233         GetArkUINodeModifiers()->getImageModifier()->resetAutoResize(nativeNode);
234     }
235     return panda::JSValueRef::Undefined(vm);
236 }
237 
ResetAutoResize(ArkUIRuntimeCallInfo * runtimeCallInfo)238 ArkUINativeModuleValue ImageBridge::ResetAutoResize(ArkUIRuntimeCallInfo* runtimeCallInfo)
239 {
240     EcmaVM* vm = runtimeCallInfo->GetVM();
241     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
242     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
243     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
244     GetArkUINodeModifiers()->getImageModifier()->resetCopyOption(nativeNode);
245     return panda::JSValueRef::Undefined(vm);
246 }
247 
SetObjectRepeat(ArkUIRuntimeCallInfo * runtimeCallInfo)248 ArkUINativeModuleValue ImageBridge::SetObjectRepeat(ArkUIRuntimeCallInfo* runtimeCallInfo)
249 {
250     EcmaVM* vm = runtimeCallInfo->GetVM();
251     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
252     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
253     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
254     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
255     if (secondArg->IsNumber()) {
256         int32_t imageRepeat = secondArg->Int32Value(vm);
257         GetArkUINodeModifiers()->getImageModifier()->setObjectRepeat(nativeNode, imageRepeat);
258     } else {
259         GetArkUINodeModifiers()->getImageModifier()->resetObjectRepeat(nativeNode);
260     }
261     return panda::JSValueRef::Undefined(vm);
262 }
263 
ResetObjectRepeat(ArkUIRuntimeCallInfo * runtimeCallInfo)264 ArkUINativeModuleValue ImageBridge::ResetObjectRepeat(ArkUIRuntimeCallInfo* runtimeCallInfo)
265 {
266     EcmaVM* vm = runtimeCallInfo->GetVM();
267     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
268     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
269     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
270     GetArkUINodeModifiers()->getImageModifier()->resetObjectRepeat(nativeNode);
271     return panda::JSValueRef::Undefined(vm);
272 }
273 
SetEdgeAntialiasing(ArkUIRuntimeCallInfo * runtimeCallInfo)274 ArkUINativeModuleValue ImageBridge::SetEdgeAntialiasing(ArkUIRuntimeCallInfo* runtimeCallInfo)
275 {
276     EcmaVM* vm = runtimeCallInfo->GetVM();
277     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
278     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
279     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
280     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
281     if (secondArg->IsNumber()) {
282         float edgeAntialiasing = secondArg->ToNumber(vm)->Value();
283         GetArkUINodeModifiers()->getImageModifier()->setEdgeAntialiasing(nativeNode, edgeAntialiasing);
284     } else {
285         GetArkUINodeModifiers()->getImageModifier()->resetEdgeAntialiasing(nativeNode);
286     }
287     return panda::JSValueRef::Undefined(vm);
288 }
289 
ResetEdgeAntialiasing(ArkUIRuntimeCallInfo * runtimeCallInfo)290 ArkUINativeModuleValue ImageBridge::ResetEdgeAntialiasing(ArkUIRuntimeCallInfo* runtimeCallInfo)
291 {
292     EcmaVM* vm = runtimeCallInfo->GetVM();
293     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
294     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
295     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
296     GetArkUINodeModifiers()->getImageModifier()->resetEdgeAntialiasing(nativeNode);
297     return panda::JSValueRef::Undefined(vm);
298 }
299 
SetResizableLattice(ArkUIRuntimeCallInfo * runtimeCallInfo)300 ArkUINativeModuleValue ImageBridge::SetResizableLattice(ArkUIRuntimeCallInfo* runtimeCallInfo)
301 {
302     EcmaVM* vm = runtimeCallInfo->GetVM();
303     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
304     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
305     if (info.Length() > 1 && info[1]->IsObject()) {
306         auto drawingLattice = Ace::Framework::CreateDrawingLattice(info[1]);
307         if (drawingLattice) {
308             Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(INDEX_0);
309             auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
310             ImageModelNG::SetResizableLattice(reinterpret_cast<FrameNode*>(nativeNode), drawingLattice);
311         }
312     }
313     return panda::JSValueRef::Undefined(vm);
314 }
315 
SetResizable(ArkUIRuntimeCallInfo * runtimeCallInfo)316 ArkUINativeModuleValue ImageBridge::SetResizable(ArkUIRuntimeCallInfo* runtimeCallInfo)
317 {
318     EcmaVM* vm = runtimeCallInfo->GetVM();
319     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
320     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(INDEX_0);
321     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
322 
323     std::vector<ArkUIStringAndFloat> options;
324     std::vector<std::optional<CalcDimension>> sliceDimensions;
325     ParseResizableCalcDimensions(runtimeCallInfo, INDEX_1, INDEX_4, sliceDimensions, CalcDimension(0.0));
326     PushDimensionsToVector(options, sliceDimensions);
327 
328     GetArkUINodeModifiers()->getImageModifier()->setResizable(nativeNode, options.data());
329     return panda::JSValueRef::Undefined(vm);
330 }
331 
ResetResizable(ArkUIRuntimeCallInfo * runtimeCallInfo)332 ArkUINativeModuleValue ImageBridge::ResetResizable(ArkUIRuntimeCallInfo* runtimeCallInfo)
333 {
334     EcmaVM* vm = runtimeCallInfo->GetVM();
335     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
336     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
337     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
338     GetArkUINodeModifiers()->getImageModifier()->resetResizable(nativeNode);
339     return panda::JSValueRef::Undefined(vm);
340 }
341 
SetDynamicRangeMode(ArkUIRuntimeCallInfo * runtimeCallInfo)342 ArkUINativeModuleValue ImageBridge::SetDynamicRangeMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
343 {
344     EcmaVM* vm = runtimeCallInfo->GetVM();
345     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
346     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
347     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
348     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
349     if (secondArg->IsNumber()) {
350         int32_t objectFitValue = secondArg->Int32Value(vm);
351         GetArkUINodeModifiers()->getImageModifier()->setDynamicRangeMode(nativeNode, objectFitValue);
352     } else {
353         GetArkUINodeModifiers()->getImageModifier()->resetDynamicRangeMode(nativeNode);
354     }
355     return panda::JSValueRef::Undefined(vm);
356 }
357 
ResetDynamicRangeMode(ArkUIRuntimeCallInfo * runtimeCallInfo)358 ArkUINativeModuleValue ImageBridge::ResetDynamicRangeMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
359 {
360     EcmaVM* vm = runtimeCallInfo->GetVM();
361     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
362     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
363     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
364     GetArkUINodeModifiers()->getImageModifier()->resetDynamicRangeMode(nativeNode);
365     return panda::JSValueRef::Undefined(vm);
366 }
367 
SetEnhancedImageQuality(ArkUIRuntimeCallInfo * runtimeCallInfo)368 ArkUINativeModuleValue ImageBridge::SetEnhancedImageQuality(ArkUIRuntimeCallInfo* runtimeCallInfo)
369 {
370     EcmaVM* vm = runtimeCallInfo->GetVM();
371     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
372     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
373     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
374     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
375     if (secondArg->IsNumber()) {
376         int32_t objectFitValue = secondArg->Int32Value(vm);
377         GetArkUINodeModifiers()->getImageModifier()->setEnhancedImageQuality(nativeNode, objectFitValue);
378     } else {
379         GetArkUINodeModifiers()->getImageModifier()->resetEnhancedImageQuality(nativeNode);
380     }
381     return panda::JSValueRef::Undefined(vm);
382 }
383 
ResetEnhancedImageQuality(ArkUIRuntimeCallInfo * runtimeCallInfo)384 ArkUINativeModuleValue ImageBridge::ResetEnhancedImageQuality(ArkUIRuntimeCallInfo* runtimeCallInfo)
385 {
386     EcmaVM* vm = runtimeCallInfo->GetVM();
387     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
388     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
389     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
390     GetArkUINodeModifiers()->getImageModifier()->resetEnhancedImageQuality(nativeNode);
391     return panda::JSValueRef::Undefined(vm);
392 }
393 
SetPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)394 ArkUINativeModuleValue ImageBridge::SetPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
395 {
396     EcmaVM* vm = runtimeCallInfo->GetVM();
397     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
398     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
399     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
400     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
401     uint32_t sensitive = false;
402     if (secondArg->IsBoolean()) {
403         sensitive = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
404     }
405     GetArkUINodeModifiers()->getImageModifier()->setImagePrivacySensitive(nativeNode, sensitive);
406     return panda::JSValueRef::Undefined(vm);
407 }
408 
ResetPrivacySensitive(ArkUIRuntimeCallInfo * runtimeCallInfo)409 ArkUINativeModuleValue ImageBridge::ResetPrivacySensitive(ArkUIRuntimeCallInfo* runtimeCallInfo)
410 {
411     EcmaVM* vm = runtimeCallInfo->GetVM();
412     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
413     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
414     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
415     GetArkUINodeModifiers()->getImageModifier()->resetImagePrivacySensitive(nativeNode);
416     return panda::JSValueRef::Undefined(vm);
417 }
418 
SetRenderMode(ArkUIRuntimeCallInfo * runtimeCallInfo)419 ArkUINativeModuleValue ImageBridge::SetRenderMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
420 {
421     EcmaVM* vm = runtimeCallInfo->GetVM();
422     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
423     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
424     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
425     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
426     if (secondArg->IsNumber()) {
427         int32_t imageRenderMode = secondArg->Int32Value(vm);
428         GetArkUINodeModifiers()->getImageModifier()->setRenderMode(nativeNode, imageRenderMode);
429     } else {
430         GetArkUINodeModifiers()->getImageModifier()->resetRenderMode(nativeNode);
431     }
432     return panda::JSValueRef::Undefined(vm);
433 }
434 
ResetRenderMode(ArkUIRuntimeCallInfo * runtimeCallInfo)435 ArkUINativeModuleValue ImageBridge::ResetRenderMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
436 {
437     EcmaVM* vm = runtimeCallInfo->GetVM();
438     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
439     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
440     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
441     GetArkUINodeModifiers()->getImageModifier()->resetRenderMode(nativeNode);
442     return panda::JSValueRef::Undefined(vm);
443 }
444 
SetSyncLoad(ArkUIRuntimeCallInfo * runtimeCallInfo)445 ArkUINativeModuleValue ImageBridge::SetSyncLoad(ArkUIRuntimeCallInfo* runtimeCallInfo)
446 {
447     EcmaVM* vm = runtimeCallInfo->GetVM();
448     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
449     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
450     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
451     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
452     if (secondArg->IsBoolean()) {
453         bool syncLoadValue = secondArg->ToBoolean(vm)->Value();
454         GetArkUINodeModifiers()->getImageModifier()->setSyncLoad(nativeNode, syncLoadValue);
455     } else {
456         GetArkUINodeModifiers()->getImageModifier()->resetSyncLoad(nativeNode);
457     }
458     return panda::JSValueRef::Undefined(vm);
459 }
460 
ResetSyncLoad(ArkUIRuntimeCallInfo * runtimeCallInfo)461 ArkUINativeModuleValue ImageBridge::ResetSyncLoad(ArkUIRuntimeCallInfo* runtimeCallInfo)
462 {
463     EcmaVM* vm = runtimeCallInfo->GetVM();
464     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
465     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
466     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
467     GetArkUINodeModifiers()->getImageModifier()->resetSyncLoad(nativeNode);
468     return panda::JSValueRef::Undefined(vm);
469 }
470 
SetImageMatrix(ArkUIRuntimeCallInfo * runtimeCallInfo)471 ArkUINativeModuleValue ImageBridge::SetImageMatrix(ArkUIRuntimeCallInfo *runtimeCallInfo)
472 {
473     EcmaVM *vm = runtimeCallInfo->GetVM();
474     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
475     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
476     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
477     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
478 
479     if (!jsValue->IsArray(vm)) {
480         GetArkUINodeModifiers()->getImageModifier()->resetImageMatrix(nativeNode);
481         return panda::JSValueRef::Undefined(vm);
482     }
483 
484     const auto matrix4Len = Matrix4::DIMENSION * Matrix4::DIMENSION;
485     float matrix[matrix4Len];
486     Local<panda::ArrayRef> transArray = static_cast<Local<panda::ArrayRef>>(jsValue);
487     for (size_t i = 0; i < transArray->Length(vm); i++) {
488         Local<JSValueRef> value = transArray->GetValueAt(vm, jsValue, i);
489         matrix[i] = value->ToNumber(vm)->Value();
490     }
491     GetArkUINodeModifiers()->getImageModifier()->setImageMatrix(nativeNode, matrix);
492     return panda::JSValueRef::Undefined(vm);
493 }
494 
ResetImageMatrix(ArkUIRuntimeCallInfo * runtimeCallInfo)495 ArkUINativeModuleValue ImageBridge::ResetImageMatrix(ArkUIRuntimeCallInfo *runtimeCallInfo)
496 {
497     EcmaVM *vm = runtimeCallInfo->GetVM();
498     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
499     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
500     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
501 
502     GetArkUINodeModifiers()->getImageModifier()->resetImageMatrix(nativeNode);
503     return panda::JSValueRef::Undefined(vm);
504 }
505 
SetObjectFit(ArkUIRuntimeCallInfo * runtimeCallInfo)506 ArkUINativeModuleValue ImageBridge::SetObjectFit(ArkUIRuntimeCallInfo* runtimeCallInfo)
507 {
508     EcmaVM* vm = runtimeCallInfo->GetVM();
509     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
510     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
511     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
512     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
513     if (secondArg->IsNumber()) {
514         int32_t objectFitValue = secondArg->Int32Value(vm);
515         GetArkUINodeModifiers()->getImageModifier()->setObjectFit(nativeNode, objectFitValue);
516     } else {
517         GetArkUINodeModifiers()->getImageModifier()->resetObjectFit(nativeNode);
518     }
519     return panda::JSValueRef::Undefined(vm);
520 }
521 
ResetObjectFit(ArkUIRuntimeCallInfo * runtimeCallInfo)522 ArkUINativeModuleValue ImageBridge::ResetObjectFit(ArkUIRuntimeCallInfo* runtimeCallInfo)
523 {
524     EcmaVM* vm = runtimeCallInfo->GetVM();
525     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
526     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
527     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
528     GetArkUINodeModifiers()->getImageModifier()->resetObjectFit(nativeNode);
529     return panda::JSValueRef::Undefined(vm);
530 }
531 
SetFitOriginalSize(ArkUIRuntimeCallInfo * runtimeCallInfo)532 ArkUINativeModuleValue ImageBridge::SetFitOriginalSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
533 {
534     EcmaVM* vm = runtimeCallInfo->GetVM();
535     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
536     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
537     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
538     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
539     if (secondArg->IsBoolean()) {
540         bool fitOriginalSize = secondArg->ToBoolean(vm)->Value();
541         GetArkUINodeModifiers()->getImageModifier()->setFitOriginalSize(nativeNode, fitOriginalSize);
542     } else {
543         GetArkUINodeModifiers()->getImageModifier()->resetFitOriginalSize(nativeNode);
544     }
545     return panda::JSValueRef::Undefined(vm);
546 }
547 
ResetFitOriginalSize(ArkUIRuntimeCallInfo * runtimeCallInfo)548 ArkUINativeModuleValue ImageBridge::ResetFitOriginalSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
549 {
550     EcmaVM* vm = runtimeCallInfo->GetVM();
551     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
552     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
553     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
554     GetArkUINodeModifiers()->getImageModifier()->resetFitOriginalSize(nativeNode);
555     return panda::JSValueRef::Undefined(vm);
556 }
557 
SetSourceSize(ArkUIRuntimeCallInfo * runtimeCallInfo)558 ArkUINativeModuleValue ImageBridge::SetSourceSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
559 {
560     EcmaVM* vm = runtimeCallInfo->GetVM();
561     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
562     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
563     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
564     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(2);
565     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
566 
567     if (secondArg->IsNumber() && thirdArg->IsNumber() && secondArg->ToNumber(vm)->Value() >= 0 &&
568         thirdArg->ToNumber(vm)->Value() >= 0) {
569         double width = secondArg->ToNumber(vm)->Value();
570         double height = thirdArg->ToNumber(vm)->Value();
571         GetArkUINodeModifiers()->getImageModifier()->setSourceSize(nativeNode, width, height);
572     } else {
573         GetArkUINodeModifiers()->getImageModifier()->resetSourceSize(nativeNode);
574     }
575     return panda::JSValueRef::Undefined(vm);
576 }
577 
ResetSourceSize(ArkUIRuntimeCallInfo * runtimeCallInfo)578 ArkUINativeModuleValue ImageBridge::ResetSourceSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
579 {
580     EcmaVM* vm = runtimeCallInfo->GetVM();
581     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
582     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
583     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
584     GetArkUINodeModifiers()->getImageModifier()->resetSourceSize(nativeNode);
585     return panda::JSValueRef::Undefined(vm);
586 }
587 
SetMatchTextDirection(ArkUIRuntimeCallInfo * runtimeCallInfo)588 ArkUINativeModuleValue ImageBridge::SetMatchTextDirection(ArkUIRuntimeCallInfo* runtimeCallInfo)
589 {
590     EcmaVM* vm = runtimeCallInfo->GetVM();
591     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
592     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
593     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
594     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
595 
596     if (secondArg->IsBoolean()) {
597         uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
598         GetArkUINodeModifiers()->getImageModifier()->setMatchTextDirection(nativeNode, value);
599     } else {
600         GetArkUINodeModifiers()->getImageModifier()->resetMatchTextDirection(nativeNode);
601     }
602     return panda::JSValueRef::Undefined(vm);
603 }
604 
ResetMatchTextDirection(ArkUIRuntimeCallInfo * runtimeCallInfo)605 ArkUINativeModuleValue ImageBridge::ResetMatchTextDirection(ArkUIRuntimeCallInfo* runtimeCallInfo)
606 {
607     EcmaVM* vm = runtimeCallInfo->GetVM();
608     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
609     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
610     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
611     GetArkUINodeModifiers()->getImageModifier()->resetMatchTextDirection(nativeNode);
612     return panda::JSValueRef::Undefined(vm);
613 }
614 
SetFillColor(ArkUIRuntimeCallInfo * runtimeCallInfo)615 ArkUINativeModuleValue ImageBridge::SetFillColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
616 {
617     EcmaVM* vm = runtimeCallInfo->GetVM();
618     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
619     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
620     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
621     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
622     Color color;
623     if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
624         GetArkUINodeModifiers()->getImageModifier()->setFillColor(nativeNode, color.GetValue());
625     } else if (ArkTSUtils::ParseJsColorContent(vm, colorArg)) {
626         GetArkUINodeModifiers()->getImageModifier()->resetImageFill(nativeNode);
627     } else {
628         GetArkUINodeModifiers()->getImageModifier()->resetFillColor(nativeNode);
629     }
630     return panda::JSValueRef::Undefined(vm);
631 }
632 
ResetFillColor(ArkUIRuntimeCallInfo * runtimeCallInfo)633 ArkUINativeModuleValue ImageBridge::ResetFillColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
634 {
635     EcmaVM* vm = runtimeCallInfo->GetVM();
636     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
637     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
638     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
639     GetArkUINodeModifiers()->getImageModifier()->resetFillColor(nativeNode);
640     return panda::JSValueRef::Undefined(vm);
641 }
642 
SetAlt(ArkUIRuntimeCallInfo * runtimeCallInfo)643 ArkUINativeModuleValue ImageBridge::SetAlt(ArkUIRuntimeCallInfo* runtimeCallInfo)
644 {
645     EcmaVM* vm = runtimeCallInfo->GetVM();
646     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
647     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
648     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
649     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
650     std::string src;
651     if (!ArkTSUtils::ParseJsMedia(vm, secondArg, src)) {
652         return panda::JSValueRef::Undefined(vm);
653     }
654     if (ImageSourceInfo::ResolveURIType(src) == SrcType::NETWORK) {
655         return panda::JSValueRef::Undefined(vm);
656     }
657     std::string bundleName;
658     std::string moduleName;
659     ArkTSUtils::GetJsMediaBundleInfo(vm, secondArg, bundleName, moduleName);
660     GetArkUINodeModifiers()->getImageModifier()->setAlt(
661         nativeNode, src.c_str(), bundleName.c_str(), moduleName.c_str());
662     return panda::JSValueRef::Undefined(vm);
663 }
664 
ResetAlt(ArkUIRuntimeCallInfo * runtimeCallInfo)665 ArkUINativeModuleValue ImageBridge::ResetAlt(ArkUIRuntimeCallInfo* runtimeCallInfo)
666 {
667     EcmaVM* vm = runtimeCallInfo->GetVM();
668     return panda::JSValueRef::Undefined(vm);
669 }
670 
SetImageInterpolation(ArkUIRuntimeCallInfo * runtimeCallInfo)671 ArkUINativeModuleValue ImageBridge::SetImageInterpolation(ArkUIRuntimeCallInfo* runtimeCallInfo)
672 {
673     EcmaVM* vm = runtimeCallInfo->GetVM();
674     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
675     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
676     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
677     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
678     if (secondArg->IsNumber()) {
679         int32_t value = secondArg->Int32Value(vm);
680         GetArkUINodeModifiers()->getImageModifier()->setImageInterpolation(nativeNode, value);
681     } else {
682         GetArkUINodeModifiers()->getImageModifier()->resetImageInterpolation(nativeNode);
683     }
684     return panda::JSValueRef::Undefined(vm);
685 }
686 
ResetImageInterpolation(ArkUIRuntimeCallInfo * runtimeCallInfo)687 ArkUINativeModuleValue ImageBridge::ResetImageInterpolation(ArkUIRuntimeCallInfo* runtimeCallInfo)
688 {
689     EcmaVM* vm = runtimeCallInfo->GetVM();
690     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
691     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
692     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
693     GetArkUINodeModifiers()->getImageModifier()->resetImageInterpolation(nativeNode);
694     return panda::JSValueRef::Undefined(vm);
695 }
696 
SetColorFilterObject(const EcmaVM * vm,const Local<JSValueRef> & jsObjArg,ArkUINodeHandle nativeNode)697 void SetColorFilterObject(const EcmaVM* vm, const Local<JSValueRef>& jsObjArg, ArkUINodeHandle nativeNode)
698 {
699     Framework::JSColorFilter* colorFilter;
700     if (!jsObjArg->IsUndefined() && !jsObjArg->IsNull()) {
701         colorFilter = static_cast<Framework::JSColorFilter*>(jsObjArg->ToObject(vm)->GetNativePointerField(vm, 0));
702     } else {
703         GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
704             nativeNode, &(*DEFAULT_COLOR_FILTER_MATRIX.begin()), COLOR_FILTER_MATRIX_SIZE);
705         return;
706     }
707     if (colorFilter && colorFilter->GetColorFilterMatrix().size() == COLOR_FILTER_MATRIX_SIZE) {
708         GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
709             nativeNode, &(*colorFilter->GetColorFilterMatrix().begin()), COLOR_FILTER_MATRIX_SIZE);
710     } else {
711         GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
712             nativeNode, &(*DEFAULT_COLOR_FILTER_MATRIX.begin()), COLOR_FILTER_MATRIX_SIZE);
713         return;
714     }
715     GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
716         nativeNode, &(*DEFAULT_COLOR_FILTER_MATRIX.begin()), COLOR_FILTER_MATRIX_SIZE);
717 }
718 
SetColorFilter(ArkUIRuntimeCallInfo * runtimeCallInfo)719 ArkUINativeModuleValue ImageBridge::SetColorFilter(ArkUIRuntimeCallInfo* runtimeCallInfo)
720 {
721     EcmaVM* vm = runtimeCallInfo->GetVM();
722     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
723     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
724     Local<JSValueRef> jsObjArg = runtimeCallInfo->GetCallArgRef(1);
725     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
726     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
727     if (!jsObjArg->IsArray(vm) && !jsObjArg->IsObject(vm)) {
728         GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
729             nativeNode, &(*DEFAULT_COLOR_FILTER_MATRIX.begin()), COLOR_FILTER_MATRIX_SIZE);
730         return panda::JSValueRef::Undefined(vm);
731     }
732     if (jsObjArg->IsObject(vm) && !jsObjArg->IsArray(vm)) {
733         auto drawingColorFilter = Ace::Framework::CreateDrawingColorFilter(info[1]);
734         if (drawingColorFilter) {
735             ImageModelNG::SetDrawingColorFilter(reinterpret_cast<FrameNode*>(nativeNode), drawingColorFilter);
736             return panda::JSValueRef::Undefined(vm);
737         }
738 
739         SetColorFilterObject(vm, jsObjArg, nativeNode);
740         return panda::JSValueRef::Undefined(vm);
741     }
742     auto array = panda::CopyableGlobal<panda::ArrayRef>(vm, jsObjArg);
743     if (array->Length(vm) != COLOR_FILTER_MATRIX_SIZE) {
744         GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
745             nativeNode, &(*DEFAULT_COLOR_FILTER_MATRIX.begin()), COLOR_FILTER_MATRIX_SIZE);
746         return panda::JSValueRef::Undefined(vm);
747     }
748     std::vector<float> colorFilter;
749     for (size_t i = 0; i < array->Length(vm); i++) {
750         auto value = array->GetValueAt(vm, jsObjArg, i);
751         if (value->IsNumber()) {
752             colorFilter.emplace_back(value->ToNumber(vm)->Value());
753         } else {
754             GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
755                 nativeNode, &(*DEFAULT_COLOR_FILTER_MATRIX.begin()), COLOR_FILTER_MATRIX_SIZE);
756             return panda::JSValueRef::Undefined(vm);
757         }
758     }
759     GetArkUINodeModifiers()->getImageModifier()->setColorFilter(
760         nativeNode, &(*colorFilter.begin()), COLOR_FILTER_MATRIX_SIZE);
761     return panda::JSValueRef::Undefined(vm);
762 }
763 
ResetColorFilter(ArkUIRuntimeCallInfo * runtimeCallInfo)764 ArkUINativeModuleValue ImageBridge::ResetColorFilter(ArkUIRuntimeCallInfo* runtimeCallInfo)
765 {
766     EcmaVM* vm = runtimeCallInfo->GetVM();
767     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
768     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
769     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
770     GetArkUINodeModifiers()->getImageModifier()->resetColorFilter(nativeNode);
771     return panda::JSValueRef::Undefined(vm);
772 }
773 
SetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)774 ArkUINativeModuleValue ImageBridge::SetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
775 {
776     EcmaVM* vm = runtimeCallInfo->GetVM();
777     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
778     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
779     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
780     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
781     bool value;
782     if (secondArg->IsBoolean()) {
783         value = secondArg->ToBoolean(vm)->Value();
784         GetArkUINodeModifiers()->getImageModifier()->setImageDraggable(nativeNode, value);
785     } else {
786         GetArkUINodeModifiers()->getImageModifier()->resetImageDraggable(nativeNode);
787     }
788 
789     return panda::JSValueRef::Undefined(vm);
790 }
791 
ResetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)792 ArkUINativeModuleValue ImageBridge::ResetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
793 {
794     EcmaVM* vm = runtimeCallInfo->GetVM();
795     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
796     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
797     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
798     GetArkUINodeModifiers()->getImageModifier()->resetImageDraggable(nativeNode);
799     return panda::JSValueRef::Undefined(vm);
800 }
801 
SetBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)802 ArkUINativeModuleValue ImageBridge::SetBorderRadius(ArkUIRuntimeCallInfo *runtimeCallInfo)
803 {
804     EcmaVM *vm = runtimeCallInfo->GetVM();
805     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
806     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
807     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
808     Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(INDEX_1);
809     Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(INDEX_2);
810     Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(INDEX_3);
811     Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(INDEX_4);
812     if (topLeftArgs->IsUndefined() && topRightArgs->IsUndefined() && bottomLeftArgs->IsUndefined() &&
813         bottomRightArgs->IsUndefined()) {
814         GetArkUINodeModifiers()->getCommonModifier()->resetBorderRadius(nativeNode);
815         return panda::JSValueRef::Undefined(vm);
816     }
817 
818     CalcDimension topLeft;
819     CalcDimension topRight;
820     CalcDimension bottomLeft;
821     CalcDimension bottomRight;
822 
823     bool isLengthMetrics = false;
824     if (ArkTSUtils::ParseJsLengthMetrics(vm, topLeftArgs, topLeft) ||
825         ArkTSUtils::ParseJsLengthMetrics(vm, topRightArgs, topRight) ||
826         ArkTSUtils::ParseJsLengthMetrics(vm, bottomLeftArgs, bottomLeft) ||
827         ArkTSUtils::ParseJsLengthMetrics(vm, bottomRightArgs, bottomRight)) {
828         isLengthMetrics = true;
829     } else {
830         ArkTSUtils::ParseAllBorder(vm, topLeftArgs, topLeft);
831         ArkTSUtils::ParseAllBorder(vm, topRightArgs, topRight);
832         ArkTSUtils::ParseAllBorder(vm, bottomLeftArgs, bottomLeft);
833         ArkTSUtils::ParseAllBorder(vm, bottomRightArgs, bottomRight);
834     }
835     auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
836     auto directionChanged = isRightToLeft && isLengthMetrics;
837     uint32_t size = SIZE_OF_FOUR;
838     ArkUI_Float32 values[size];
839     int units[size];
840     values[INDEX_0] = directionChanged ? topRight.Value() : topLeft.Value();
841     units[INDEX_0] = directionChanged ? static_cast<int>(topRight.Unit()) : static_cast<int>(topLeft.Unit());
842     values[INDEX_1] = directionChanged ? topLeft.Value() : topRight.Value();
843     units[INDEX_1] = directionChanged ? static_cast<int>(topLeft.Unit()) : static_cast<int>(topRight.Unit());
844     values[INDEX_2] = directionChanged ? bottomRight.Value() : bottomLeft.Value();
845     units[INDEX_2] = directionChanged ? static_cast<int>(bottomRight.Unit()) : static_cast<int>(bottomLeft.Unit());
846     values[INDEX_3] = directionChanged ? bottomLeft.Value() : bottomRight.Value();
847     units[INDEX_3] = directionChanged ? static_cast<int>(bottomLeft.Unit()) : static_cast<int>(bottomRight.Unit());
848 
849     GetArkUINodeModifiers()->getImageModifier()->setImageBorderRadius(nativeNode, values, units, SIZE_OF_FOUR);
850 
851     return panda::JSValueRef::Undefined(vm);
852 }
853 
ResetBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)854 ArkUINativeModuleValue ImageBridge::ResetBorderRadius(ArkUIRuntimeCallInfo *runtimeCallInfo)
855 {
856     EcmaVM *vm = runtimeCallInfo->GetVM();
857     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
858     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
859     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
860     GetArkUINodeModifiers()->getImageModifier()->resetImageBorderRadius(nativeNode);
861     return panda::JSValueRef::Undefined(vm);
862 }
863 
SetImageBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)864 ArkUINativeModuleValue ImageBridge::SetImageBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
865 {
866     CommonBridge::SetBorder(runtimeCallInfo);
867     EcmaVM* vm = runtimeCallInfo->GetVM();
868     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
869     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:node info
870     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
871     if (!Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_FOURTEEN)) {
872         GetArkUINodeModifiers()->getImageModifier()->setImageBorder(nativeNode);
873         return panda::JSValueRef::Undefined(vm);
874     }
875     std::vector<ArkUI_Float32> options;
876     ParseOuterBorderRadius(runtimeCallInfo, vm, options); // Border Radius args start index
877     GetArkUINodeModifiers()->getImageModifier()->setImageBorderWithValues(nativeNode, options.data(), options.size());
878     return panda::JSValueRef::Undefined(vm);
879 }
880 
ResetImageBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)881 ArkUINativeModuleValue ImageBridge::ResetImageBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
882 {
883     EcmaVM* vm = runtimeCallInfo->GetVM();
884     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
885     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:node info
886     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
887     GetArkUINodeModifiers()->getCommonModifier()->resetBorder(nativeNode);
888     return panda::JSValueRef::Undefined(vm);
889 }
890 
SetImageOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)891 ArkUINativeModuleValue ImageBridge::SetImageOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
892 {
893     EcmaVM* vm = runtimeCallInfo->GetVM();
894     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
895     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:node info
896     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
897     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
898     if (ImageModelNG::IsSrcSvgImage(frameNode)) {
899         CommonBridge::SetOpacity(runtimeCallInfo);
900     } else {
901         Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1); // 1:value info
902         double opacity;
903         if (!ArkTSUtils::ParseJsDouble(vm, valueArg, opacity)) {
904             GetArkUINodeModifiers()->getImageModifier()->resetImageOpacity(nativeNode);
905         } else {
906             GetArkUINodeModifiers()->getImageModifier()->setImageOpacity(nativeNode, opacity);
907         }
908     }
909     return panda::JSValueRef::Undefined(vm);
910 }
911 
ResetImageOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)912 ArkUINativeModuleValue ImageBridge::ResetImageOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
913 {
914     EcmaVM* vm = runtimeCallInfo->GetVM();
915     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
916     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:node info
917     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
918     GetArkUINodeModifiers()->getImageModifier()->resetImageOpacity(nativeNode);
919     return panda::JSValueRef::Undefined(vm);
920 }
921 
SetImageTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)922 ArkUINativeModuleValue ImageBridge::SetImageTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
923 {
924     EcmaVM* vm = runtimeCallInfo->GetVM();
925     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
926     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:node info
927     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
928     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
929     if (ImageModelNG::IsSrcSvgImage(frameNode)) {
930         CommonBridge::SetTransition(runtimeCallInfo);
931     } else {
932         CommonBridge::SetTransitionPassThrough(runtimeCallInfo);
933     }
934     return panda::JSValueRef::Undefined(vm);
935 }
936 
ResetImageTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)937 ArkUINativeModuleValue ImageBridge::ResetImageTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
938 {
939     EcmaVM* vm = runtimeCallInfo->GetVM();
940     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
941     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0:node info
942     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
943     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
944     if (ImageModelNG::IsSrcSvgImage(frameNode)) {
945         CommonBridge::ResetTransition(runtimeCallInfo);
946     } else {
947         CommonBridge::ResetTransitionPassThrough(runtimeCallInfo);
948     }
949     return panda::JSValueRef::Undefined(vm);
950 }
951 
EnableAnalyzer(ArkUIRuntimeCallInfo * runtimeCallInfo)952 ArkUINativeModuleValue ImageBridge::EnableAnalyzer(ArkUIRuntimeCallInfo* runtimeCallInfo)
953 {
954     EcmaVM* vm = runtimeCallInfo->GetVM();
955     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
956     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(INDEX_0);
957     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
958     Local<JSValueRef> enableValue = runtimeCallInfo->GetCallArgRef(1);
959 
960     if (enableValue->IsBoolean()) {
961         bool enable = enableValue->ToBoolean(vm)->Value();
962         GetArkUINodeModifiers()->getImageModifier()->enableAnalyzer(nativeNode, enable);
963     }
964     return panda::JSValueRef::Undefined(vm);
965 }
966 
AnalyzerConfig(ArkUIRuntimeCallInfo * runtimeCallInfo)967 ArkUINativeModuleValue ImageBridge::AnalyzerConfig(ArkUIRuntimeCallInfo* runtimeCallInfo)
968 {
969     EcmaVM* vm = runtimeCallInfo->GetVM();
970     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
971     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(INDEX_0);
972     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
973     Local<JSValueRef> configValue = runtimeCallInfo->GetCallArgRef(1);
974     JSValueWrapper valueWrapper = configValue;
975     auto engine = EngineHelper::GetCurrentEngine();
976     CHECK_NULL_RETURN(engine, panda::NativePointerRef::New(vm, nullptr));
977     NativeEngine* nativeEngine = engine->GetNativeEngine();
978     Framework::ScopeRAII scope(reinterpret_cast<napi_env>(nativeEngine));
979     napi_value nativeValue = nativeEngine->ValueToNapiValue(valueWrapper);
980     GetArkUINodeModifiers()->getImageModifier()->analyzerConfig(nativeNode, nativeValue);
981     return panda::JSValueRef::Undefined(vm);
982 }
983 
SetOnComplete(ArkUIRuntimeCallInfo * runtimeCallInfo)984 ArkUINativeModuleValue ImageBridge::SetOnComplete(ArkUIRuntimeCallInfo *runtimeCallInfo)
985 {
986     EcmaVM *vm = runtimeCallInfo->GetVM();
987     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
988     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
989     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
990     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
991     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
992     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
993     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
994         GetArkUINodeModifiers()->getImageModifier()->setOnComplete(nativeNode, nullptr);
995         return panda::JSValueRef::Undefined(vm);
996     }
997     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
998     std::function<void(LoadImageSuccessEvent&)> callback = [vm, frameNode,
999         func = panda::CopyableGlobal(vm, func)](LoadImageSuccessEvent& event) {
1000         panda::LocalScope pandaScope(vm);
1001         panda::TryCatch trycatch(vm);
1002         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1003         const char* keys[] = { "width", "height", "componentWidth", "componentHeight", "loadingStatus", "contentWidth",
1004             "contentHeight", "contentOffsetX", "contentOffsetY" };
1005         Local<JSValueRef> values[] = {
1006             panda::NumberRef::New(vm, event.GetWidth()),
1007             panda::NumberRef::New(vm, event.GetHeight()),
1008             panda::NumberRef::New(vm, event.GetComponentWidth()),
1009             panda::NumberRef::New(vm, event.GetComponentHeight()),
1010             panda::NumberRef::New(vm, event.GetLoadingStatus()),
1011             panda::NumberRef::New(vm, event.GetContentWidth()),
1012             panda::NumberRef::New(vm, event.GetContentHeight()),
1013             panda::NumberRef::New(vm, event.GetContentOffsetX()),
1014             panda::NumberRef::New(vm, event.GetContentOffsetY())
1015         };
1016         auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1017         eventObject->SetNativePointerFieldCount(vm, 1);
1018         eventObject->SetNativePointerField(vm, 0, static_cast<void*>(&event));
1019         panda::Local<panda::JSValueRef> params[1] = { eventObject };
1020         func->Call(vm, func.ToLocal(), params, 1);
1021     };
1022     GetArkUINodeModifiers()->getImageModifier()->setOnComplete(nativeNode, reinterpret_cast<void*>(&callback));
1023     return panda::JSValueRef::Undefined(vm);
1024 }
1025 
ResetOnComplete(ArkUIRuntimeCallInfo * runtimeCallInfo)1026 ArkUINativeModuleValue ImageBridge::ResetOnComplete(ArkUIRuntimeCallInfo* runtimeCallInfo)
1027 {
1028     EcmaVM* vm = runtimeCallInfo->GetVM();
1029     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1030     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1031     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1032     GetArkUINodeModifiers()->getImageModifier()->setOnComplete(nativeNode, nullptr);
1033     return panda::JSValueRef::Undefined(vm);
1034 }
1035 
SetOnError(ArkUIRuntimeCallInfo * runtimeCallInfo)1036 ArkUINativeModuleValue ImageBridge::SetOnError(ArkUIRuntimeCallInfo* runtimeCallInfo)
1037 {
1038     EcmaVM* vm = runtimeCallInfo->GetVM();
1039     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1040     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(INDEX_0);
1041     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
1042     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1043     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1044     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1045     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1046         GetArkUINodeModifiers()->getImageModifier()->resetOnError(nativeNode);
1047         return panda::JSValueRef::Undefined(vm);
1048     }
1049     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1050     std::function<void(LoadImageFailEvent&)> callback = [vm, frameNode,
1051         func = panda::CopyableGlobal(vm, func)](LoadImageFailEvent& event) {
1052         panda::LocalScope pandaScope(vm);
1053         panda::TryCatch trycatch(vm);
1054         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1055         const char* keys[] = { "componentWidth", "componentHeight", "message" };
1056         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, event.GetComponentWidth()),
1057             panda::NumberRef::New(vm, event.GetComponentHeight()),
1058             panda::StringRef::NewFromUtf8(vm, event.GetErrorMessage().c_str()) };
1059         auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1060         eventObject->SetNativePointerFieldCount(vm, 1);
1061         eventObject->SetNativePointerField(vm, 0, static_cast<void*>(&event));
1062         panda::Local<panda::JSValueRef> params[1] = { eventObject };
1063         func->Call(vm, func.ToLocal(), params, 1);
1064     };
1065     GetArkUINodeModifiers()->getImageModifier()->setOnError(
1066         nativeNode, reinterpret_cast<void*>(&callback));
1067     return panda::JSValueRef::Undefined(vm);
1068 }
1069 
ResetOnError(ArkUIRuntimeCallInfo * runtimeCallInfo)1070 ArkUINativeModuleValue ImageBridge::ResetOnError(ArkUIRuntimeCallInfo* runtimeCallInfo)
1071 {
1072     EcmaVM* vm = runtimeCallInfo->GetVM();
1073     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1074     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(INDEX_0);
1075     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1076     GetArkUINodeModifiers()->getImageModifier()->resetOnError(nativeNode);
1077     return panda::JSValueRef::Undefined(vm);
1078 }
1079 
SetOnFinish(ArkUIRuntimeCallInfo * runtimeCallInfo)1080 ArkUINativeModuleValue ImageBridge::SetOnFinish(ArkUIRuntimeCallInfo* runtimeCallInfo)
1081 {
1082     EcmaVM *vm = runtimeCallInfo->GetVM();
1083     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1084     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1085     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
1086     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1087     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1088         GetArkUINodeModifiers()->getImageModifier()->resetImageOnFinish(nativeNode);
1089         return panda::JSValueRef::Undefined(vm);
1090     }
1091     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1092     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
1093     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1094     std::function<void(void)> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)]() {
1095         panda::LocalScope pandaScope(vm);
1096         panda::TryCatch trycatch(vm);
1097         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1098         func->Call(vm, func.ToLocal(), nullptr, 0);
1099     };
1100     GetArkUINodeModifiers()->getImageModifier()->setImageOnFinish(nativeNode, reinterpret_cast<void*>(&callback));
1101     return panda::JSValueRef::Undefined(vm);
1102 }
1103 
ResetOnFinish(ArkUIRuntimeCallInfo * runtimeCallInfo)1104 ArkUINativeModuleValue ImageBridge::ResetOnFinish(ArkUIRuntimeCallInfo* runtimeCallInfo)
1105 {
1106     EcmaVM* vm = runtimeCallInfo->GetVM();
1107     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1108     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1109     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1110     GetArkUINodeModifiers()->getImageModifier()->resetImageOnFinish(nativeNode);
1111     return panda::JSValueRef::Undefined(vm);
1112 }
1113 
SetOrientation(ArkUIRuntimeCallInfo * runtimeCallInfo)1114 ArkUINativeModuleValue ImageBridge::SetOrientation(ArkUIRuntimeCallInfo* runtimeCallInfo)
1115 {
1116     EcmaVM* vm = runtimeCallInfo->GetVM();
1117     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1118     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1119     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
1120     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1121     if (secondArg->IsNumber()) {
1122         int32_t value = secondArg->Int32Value(vm);
1123         GetArkUINodeModifiers()->getImageModifier()->setImageRotateOrientation(nativeNode, value);
1124     } else {
1125         GetArkUINodeModifiers()->getImageModifier()->resetImageRotateOrientation(nativeNode);
1126     }
1127     return panda::JSValueRef::Undefined(vm);
1128 }
1129 
ResetOrientation(ArkUIRuntimeCallInfo * runtimeCallInfo)1130 ArkUINativeModuleValue ImageBridge::ResetOrientation(ArkUIRuntimeCallInfo* runtimeCallInfo)
1131 {
1132     EcmaVM* vm = runtimeCallInfo->GetVM();
1133     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1134     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1135     auto* nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1136     GetArkUINodeModifiers()->getImageModifier()->resetImageRotateOrientation(nativeNode);
1137     return panda::JSValueRef::Undefined(vm);
1138 }
1139 } // namespace OHOS::Ace::NG