1 /*
2 * Copyright (C) 2022 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_pixel_map_napi.h"
17 #include "napi/native_node_api.h"
18
19 namespace OHOS {
20 namespace Media {
21 extern "C" int32_t OHOS_MEDIA_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info);
22 extern "C" int32_t OHOS_MEDIA_AccessPixels(napi_env env, napi_value value, uint8_t** addrPtr);
23 extern "C" int32_t OHOS_MEDIA_UnAccessPixels(napi_env env, napi_value value);
24
OH_GetImageInfo(napi_env env,napi_value value,OhosPixelMapInfo * info)25 extern "C" __attribute__((visibility("default"))) int32_t OH_GetImageInfo(napi_env env, napi_value value,
26 OhosPixelMapInfo *info)
27 {
28 int32_t ret = OHOS_MEDIA_GetImageInfo(env, value, info);
29 if (ret != OHOS_IMAGE_RESULT_SUCCESS) {
30 return OHOS_IMAGE_RESULT_BAD_PARAMETER;
31 }
32
33 return OHOS_IMAGE_RESULT_SUCCESS;
34 }
35
OH_AccessPixels(napi_env env,napi_value value,void ** addrPtr)36 extern "C" __attribute__((visibility("default"))) int32_t OH_AccessPixels(napi_env env, napi_value value,
37 void** addrPtr)
38 {
39 int32_t ret = OHOS_MEDIA_AccessPixels(env, value, reinterpret_cast<uint8_t**>(addrPtr));
40 if (ret != OHOS_IMAGE_RESULT_SUCCESS) {
41 return OHOS_IMAGE_RESULT_BAD_PARAMETER;
42 }
43
44 return OHOS_IMAGE_RESULT_SUCCESS;
45 }
46
OH_UnAccessPixels(napi_env env,napi_value value)47 extern "C" __attribute__((visibility("default"))) int32_t OH_UnAccessPixels(napi_env env, napi_value value)
48 {
49 int32_t ret = OHOS_MEDIA_UnAccessPixels(env, value);
50 if (ret != OHOS_IMAGE_RESULT_SUCCESS) {
51 return OHOS_IMAGE_RESULT_BAD_PARAMETER;
52 }
53
54 return OHOS_IMAGE_RESULT_SUCCESS;
55 }
56 } // namespace Media
57 } // namespace OHOS
58