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 "ani_image_module.h"
17 #include "image_log.h"
18 #include "log_tags.h"
19 #include "media_errors.h"
20
21 #undef LOG_DOMAIN
22 #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
23
24 #undef LOG_TAG
25 #define LOG_TAG "ANI_IMAGE_MODULE"
26
27 ANI_EXPORT
ANI_Constructor(ani_vm * vm,uint32_t * result)28 ani_status ANI_Constructor(ani_vm* vm, uint32_t* result)
29 {
30 ani_env* env;
31 IMAGE_LOGD("ANI_Constructor in");
32 if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
33 IMAGE_LOGE("Unsupported ANI_VERSION_1");
34 return ANI_ERROR;
35 }
36 ani_namespace imageNamespace;
37 if (ANI_OK != env->FindNamespace("L@ohos/multimedia/image/image;", &imageNamespace)) {
38 IMAGE_LOGE("[ANI_Constructor] FindNamespace failed");
39 return ANI_ERROR;
40 }
41 std::array staticMethods = {
42 ani_native_function {"createPixelMapSync", nullptr,
43 reinterpret_cast<void*>(OHOS::Media::PixelMapAni::CreatePixelMapAni)},
44 ani_native_function {"createImagePacker", nullptr,
45 reinterpret_cast<void*>(OHOS::Media::ImagePackerAni::CreateImagePackerAni)},
46 ani_native_function {"nativeCreateImageSourceByUri", nullptr,
47 reinterpret_cast<void*>(OHOS::Media::ImageSourceAni::CreateImageSourceAni)},
48 ani_native_function {"nativeCreateImageSourceByFd", nullptr,
49 reinterpret_cast<void*>(OHOS::Media::ImageSourceAni::CreateImageSourceAni)},
50 ani_native_function {"createPicture", nullptr,
51 reinterpret_cast<void*>(OHOS::Media::PictureAni::CreatePictureAni)},
52 };
53 if (ANI_OK != env->Namespace_BindNativeFunctions(imageNamespace, staticMethods.data(), staticMethods.size())) {
54 IMAGE_LOGE("[ANI_Constructor] Namespace_BindNativeFunctions failed");
55 return ANI_ERROR;
56 };
57 OHOS::Media::PixelMapAni::Init(env);
58 OHOS::Media::ImagePackerAni::Init(env);
59 OHOS::Media::ImageSourceAni::Init(env);
60 OHOS::Media::PictureAni::Init(env);
61 *result = ANI_VERSION_1;
62 return ANI_OK;
63 }