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 "pixel_map_taihe_ani.h"
17 #include "pixel_map_taihe.h"
18
19 // This file is for legacy ANI backward compatibility
20
21 namespace OHOS {
22 namespace Media {
23 using namespace ANI::Image;
24
CreateEtsPixelMap(ani_env * env,std::shared_ptr<PixelMap> pixelMap)25 ani_object PixelMapTaiheAni::CreateEtsPixelMap([[maybe_unused]] ani_env* env, std::shared_ptr<PixelMap> pixelMap)
26 {
27 std::unique_ptr<PixelMapTaiheAni> pixelMapAni = std::make_unique<PixelMapTaiheAni>();
28 pixelMapAni->nativePixelMap_ = pixelMap;
29
30 ani_namespace imageNamespace;
31 if (env->FindNamespace("L@ohos/multimedia/image/image;", &imageNamespace) != ANI_OK) {
32 return nullptr;
33 }
34 ani_function createFunc;
35 if (env->Namespace_FindFunction(imageNamespace, "createPixelMapByPtr", nullptr, &createFunc) != ANI_OK) {
36 return nullptr;
37 }
38 ani_ref pixelMapObj;
39 if (env->Function_Call_Ref(createFunc, &pixelMapObj, reinterpret_cast<ani_long>(pixelMapAni.release())) != ANI_OK) {
40 return nullptr;
41 }
42
43 return reinterpret_cast<ani_object>(pixelMapObj);
44 }
45
GetNativePixelMap(ani_env * env,ani_object obj)46 std::shared_ptr<PixelMap> PixelMapTaiheAni::GetNativePixelMap([[maybe_unused]] ani_env* env, ani_object obj)
47 {
48 ani_class pixelMapCls;
49 if (env->FindClass("L@ohos/multimedia/image/image/PixelMap;", &pixelMapCls) != ANI_OK) {
50 return nullptr;
51 }
52 ani_method getMethod;
53 if (env->Class_FindMethod(pixelMapCls, "getImplPtr", ":J", &getMethod) != ANI_OK) {
54 return nullptr;
55 }
56 ani_long implPtr;
57 if (env->Object_CallMethod_Long(obj, getMethod, &implPtr) != ANI_OK) {
58 return nullptr;
59 }
60
61 PixelMapImpl* pixelMapImpl = reinterpret_cast<PixelMapImpl*>(implPtr);
62 if (pixelMapImpl == nullptr) {
63 return nullptr;
64 }
65 return pixelMapImpl->GetNativePtr();
66 }
67
68 } // namespace Media
69 } // namespace OHOS