mirror of
https://github.com/openharmony/multimedia_image_standard.git
synced 2026-07-01 04:19:36 -04:00
Add pixelmap ndk func in image.
Signed-off-by: xiaok <wangxiaokai1@huawei.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import("//build/ohos.gni")
|
||||
group("image_framework") {
|
||||
deps = [
|
||||
"frameworks/innerkitsimpl/utils:image_utils",
|
||||
"frameworks/kits/js/common/pixelmap_ndk:pixelmap_ndk",
|
||||
"interfaces/innerkits:image",
|
||||
"interfaces/innerkits:image_native",
|
||||
]
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "image_pixel_map_napi.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
namespace {
|
||||
@@ -271,8 +272,8 @@ napi_value PixelMapNapi::Init(napi_env env, napi_value exports)
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(
|
||||
napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
|
||||
Constructor, nullptr, IMG_ARRAY_SIZE(props),
|
||||
props, &constructor)),
|
||||
Constructor, nullptr, IMG_ARRAY_SIZE(props),
|
||||
props, &constructor)),
|
||||
nullptr,
|
||||
HiLog::Error(LABEL, "define class fail")
|
||||
);
|
||||
@@ -322,6 +323,24 @@ std::shared_ptr<PixelMap>* PixelMapNapi::GetPixelMap()
|
||||
return &nativePixelMap_;
|
||||
}
|
||||
|
||||
bool PixelMapNapi::IsLockPixelMap()
|
||||
{
|
||||
return (lockCount > 0);
|
||||
}
|
||||
|
||||
bool PixelMapNapi::LockPixelMap()
|
||||
{
|
||||
lockCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void PixelMapNapi::UnlockPixelMap()
|
||||
{
|
||||
if (lockCount > 0) {
|
||||
lockCount--;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void* OHOS_MEDIA_GetPixelMap(napi_env env, napi_value value)
|
||||
{
|
||||
PixelMapNapi *pixmapNapi = nullptr;
|
||||
@@ -333,6 +352,100 @@ extern "C" __attribute__((visibility("default"))) void* OHOS_MEDIA_GetPixelMap(n
|
||||
return reinterpret_cast<void*>(pixmapNapi->GetPixelMap());
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) int32_t OHOS_MEDIA_GetImageInfo(napi_env env, napi_value value,
|
||||
OhosPixelMapInfo *info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "GetImageInfo IN");
|
||||
|
||||
if (info == nullptr) {
|
||||
HiLog::Error(LABEL, "info is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
PixelMapNapi *pixmapNapi = nullptr;
|
||||
napi_unwrap(env, value, reinterpret_cast<void**>(&pixmapNapi));
|
||||
if (pixmapNapi == nullptr) {
|
||||
HiLog::Error(LABEL, "pixmapNapi unwrapped is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
std::shared_ptr<PixelMap> *pixelMap = pixmapNapi->GetPixelMap();
|
||||
if ((pixelMap == nullptr) || ((*pixelMap) == nullptr)) {
|
||||
HiLog::Error(LABEL, "pixelMap is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
ImageInfo imageInfo;
|
||||
(*pixelMap)->GetImageInfo(imageInfo);
|
||||
info->width = imageInfo.size.width;
|
||||
info->height = imageInfo.size.height;
|
||||
info->rowSize = (*pixelMap)->GetRowBytes();
|
||||
info->pixelFormat = static_cast<int32_t>(imageInfo.pixelFormat);
|
||||
|
||||
HiLog::Debug(LABEL, "GetImageInfo, w=%{public}u, h=%{public}u, r=%{public}u, f=%{public}d",
|
||||
info->width, info->height, info->rowSize, info->pixelFormat);
|
||||
|
||||
HiLog::Debug(LABEL, "GetImageInfo OUT");
|
||||
return OHOS_IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) int32_t OHOS_MEDIA_AccessPixels(napi_env env, napi_value value,
|
||||
uint8_t** addrPtr)
|
||||
{
|
||||
HiLog::Debug(LABEL, "AccessPixels IN");
|
||||
|
||||
PixelMapNapi *pixmapNapi = nullptr;
|
||||
napi_unwrap(env, value, reinterpret_cast<void**>(&pixmapNapi));
|
||||
if (pixmapNapi == nullptr) {
|
||||
HiLog::Error(LABEL, "pixmapNapi unwrapped is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
std::shared_ptr<PixelMap> *pixelMap = pixmapNapi->GetPixelMap();
|
||||
if ((pixelMap == nullptr) || ((*pixelMap) == nullptr)) {
|
||||
HiLog::Error(LABEL, "pixelMap is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
const uint8_t *constPixels = (*pixelMap)->GetPixels();
|
||||
if (constPixels == nullptr) {
|
||||
HiLog::Error(LABEL, "const pixels is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
uint8_t *pixels = const_cast<uint8_t*>(constPixels);
|
||||
if (pixels == nullptr) {
|
||||
HiLog::Error(LABEL, "pixels is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
pixmapNapi->LockPixelMap();
|
||||
|
||||
if (addrPtr != nullptr) {
|
||||
*addrPtr = pixels;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "AccessPixels OUT");
|
||||
return OHOS_IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) int32_t OHOS_MEDIA_UnAccessPixels(napi_env env, napi_value value)
|
||||
{
|
||||
HiLog::Debug(LABEL, "UnAccessPixels IN");
|
||||
|
||||
PixelMapNapi *pixmapNapi = nullptr;
|
||||
napi_unwrap(env, value, reinterpret_cast<void**>(&pixmapNapi));
|
||||
if (pixmapNapi == nullptr) {
|
||||
HiLog::Error(LABEL, "pixmapNapi unwrapped is nullptr");
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
pixmapNapi->UnlockPixelMap();
|
||||
|
||||
HiLog::Debug(LABEL, "UnAccessPixels OUT");
|
||||
return OHOS_IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
napi_value PixelMapNapi::Constructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value undefineVar = nullptr;
|
||||
@@ -890,8 +1003,13 @@ napi_value PixelMapNapi::Release(napi_env env, napi_callback_info info)
|
||||
[](napi_env env, void *data)
|
||||
{
|
||||
auto context = static_cast<PixelMapAsyncContext*>(data);
|
||||
context->nConstructor->nativePixelMap_ = nullptr;
|
||||
context->status = SUCCESS;
|
||||
if (context->nConstructor->IsLockPixelMap()) {
|
||||
context->status = ERROR;
|
||||
return;
|
||||
} else {
|
||||
context->nConstructor->nativePixelMap_= nullptr;
|
||||
context->status = SUCCESS;
|
||||
}
|
||||
}, EmptyResultComplete, asyncContext, asyncContext->work);
|
||||
|
||||
IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status),
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
SUBSYSTEM_DIR = "//foundation/multimedia/image_standard"
|
||||
|
||||
ohos_shared_library("pixelmap_ndk") {
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [ "image_pixel_map_napi.cpp" ]
|
||||
|
||||
public_configs =
|
||||
[ "$SUBSYSTEM_DIR/interfaces/innerkits:image_external_config" ]
|
||||
|
||||
deps = [
|
||||
"$SUBSYSTEM_DIR/interfaces/innerkits:image",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "multimedia_image_standard"
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "image_pixel_map_napi.h"
|
||||
|
||||
extern "C" int32_t OHOS_MEDIA_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info);
|
||||
extern "C" int32_t OHOS_MEDIA_AccessPixels(napi_env env, napi_value value, uint8_t** addrPtr);
|
||||
extern "C" int32_t OHOS_MEDIA_UnAccessPixels(napi_env env, napi_value value);
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) int32_t OH_GetImageInfo(napi_env env, napi_value value,
|
||||
OhosPixelMapInfo *info)
|
||||
{
|
||||
int32_t ret = OHOS_MEDIA_GetImageInfo(env, value, info);
|
||||
if (ret != OHOS_IMAGE_RESULT_SUCCESS) {
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
return OHOS_IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) int32_t OH_AccessPixels(napi_env env, napi_value value,
|
||||
void** addrPtr)
|
||||
{
|
||||
int32_t ret = OHOS_MEDIA_AccessPixels(env, value, reinterpret_cast<uint8_t**>(addrPtr));
|
||||
if (ret != OHOS_IMAGE_RESULT_SUCCESS) {
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
return OHOS_IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) int32_t OH_UnAccessPixels(napi_env env, napi_value value)
|
||||
{
|
||||
int32_t ret = OHOS_MEDIA_UnAccessPixels(env, value);
|
||||
if (ret != OHOS_IMAGE_RESULT_SUCCESS) {
|
||||
return OHOS_IMAGE_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
return OHOS_IMAGE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ config("image_external_config") {
|
||||
"//foundation/multimedia/utils/include",
|
||||
"//foundation/multimedia/image_standard/plugins/manager/include",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits/include",
|
||||
"//foundation/multimedia/image_standard/interfaces/kits/native/include",
|
||||
"//utils/jni/jnikit/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/surface",
|
||||
|
||||
@@ -34,6 +34,9 @@ public:
|
||||
static napi_value CreatePixelMap(napi_env env, std::shared_ptr<PixelMap> pixelmap);
|
||||
static std::shared_ptr<PixelMap> GetPixelMap(napi_env env, napi_value pixelmap);
|
||||
std::shared_ptr<PixelMap>* GetPixelMap();
|
||||
bool IsLockPixelMap();
|
||||
bool LockPixelMap();
|
||||
void UnlockPixelMap();
|
||||
|
||||
private:
|
||||
static napi_value Constructor(napi_env env, napi_callback_info info);
|
||||
@@ -63,6 +66,7 @@ private:
|
||||
napi_env env_ = nullptr;
|
||||
napi_ref wrapper_ = nullptr;
|
||||
std::shared_ptr<PixelMap> nativePixelMap_;
|
||||
int32_t lockCount = 0;
|
||||
bool isRelease = false;
|
||||
};
|
||||
} // namespace Media
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@@ -12,14 +12,14 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos/ndk/ndk.gni")
|
||||
|
||||
ohos_ndk_library("libpixelmap_ndk") {
|
||||
output_name = "image_pixelmap"
|
||||
ndk_description_file = "./libpixelmap.ndk.json"
|
||||
ndk_description_file = "./libimage_pixelmap_napi.json"
|
||||
min_compact_version = "1"
|
||||
output_name = "pixelmap_ndk"
|
||||
}
|
||||
|
||||
ohos_ndk_headers("pixelmap_header") {
|
||||
dest_dir = "$ndk_headers_out_dir/multimedia/image"
|
||||
sources = [ "./include/pixel_map_ndk.h" ]
|
||||
ohos_ndk_headers("image_header") {
|
||||
dest_dir = "$ndk_headers_out_dir/multimedia/image_standard"
|
||||
sources = [ "./include/image_pixel_map_napi.h" ]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup image
|
||||
* @{
|
||||
*
|
||||
* @brief Provides access to pixel data and pixel map information.
|
||||
*
|
||||
* @Syscap SystemCapability.Multimedia.Image
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file image_pixel_map_napi.h
|
||||
*
|
||||
* @brief Declares functions for you to lock and access or unlock pixel data, and obtain the width and height of a pixel
|
||||
* map.
|
||||
*
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef IMAGE_PIXEL_MAP_NAPI_H
|
||||
#define IMAGE_PIXEL_MAP_NAPI_H
|
||||
#include <stdint.h>
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enumerates the result codes that may be returned by a function.
|
||||
*
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
enum {
|
||||
/** Success result */
|
||||
OHOS_IMAGE_RESULT_SUCCESS = 0,
|
||||
/** Invalid parameters */
|
||||
OHOS_IMAGE_RESULT_BAD_PARAMETER = -1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumerates pixel formats.
|
||||
*
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
enum {
|
||||
/**
|
||||
* Unknown format
|
||||
*/
|
||||
OHOS_PIXEL_MAP_FORMAT_NONE = 0,
|
||||
/**
|
||||
* 32-bit RGBA. Components R, G, B, and A each occupies 8 bits
|
||||
* and are stored from the higher-order to the lower-order bits.
|
||||
*/
|
||||
OHOS_PIXEL_MAP_FORMAT_RGBA_8888 = 3,
|
||||
/**
|
||||
* 16-bit RGB. Only the R, G, and B components are encoded
|
||||
* from the higher-order to the lower-order bits: red is stored with 5 bits of precision,
|
||||
* green is stored with 6 bits of precision, and blue is stored with 5 bits of precision.
|
||||
*/
|
||||
OHOS_PIXEL_MAP_FORMAT_RGB_565 = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines pixel map information.
|
||||
*
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
struct OhosPixelMapInfo {
|
||||
/** Image width, in pixels. */
|
||||
uint32_t width;
|
||||
/** Image height, in pixels. */
|
||||
uint32_t height;
|
||||
/** Number of bytes in each row of a pixel map */
|
||||
uint32_t rowSize;
|
||||
/** Pixel format */
|
||||
int32_t pixelFormat;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains information about a given <b>PixelMap</b> and stores the information in a {@link OhosPixelMapInfo}
|
||||
* structure.
|
||||
*
|
||||
* @param env Indicates the pointer to the JNI environment.
|
||||
* @param pixelMapObject Indicates the Java <b>PixelMap</b> object.
|
||||
* @param info Indicates the pointer to the pixel map information to obtain. For details, see {@link
|
||||
* OhosPixelMapInfo}.
|
||||
* @return Returns <b>0</b> if the information is obtained and stored in the structure; returns result codes if the
|
||||
* operation fails.
|
||||
* @see OhosPixelMapInfo
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info);
|
||||
|
||||
/**
|
||||
* @brief Obtains the memory address of a given <b>PixelMap</b> object and locks the memory.
|
||||
*
|
||||
* If this function call is successful, <b>*addrPtr</b> is set to the memory address. After accessing the pixel data,
|
||||
* you must use {@link UnAccessPixels} to unlock the memory. Otherwise, resources cannot be released.
|
||||
* After the memory is unlocked, it can be invalid and should not be accessed.
|
||||
*
|
||||
* @param env Indicates the pointer to the JNI environment.
|
||||
* @param pixelMapObject Indicates the Java <b>PixelMap</b> object.
|
||||
* @param addrPtr Indicates the double pointer to the memory address.
|
||||
* @see UnAccessPixels
|
||||
* @return Returns {@link OHOS_IMAGE_RESULT_SUCCESS} if the operation is successful; returns other result codes if
|
||||
* the operation fails.
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_AccessPixels(napi_env env, napi_value value, void** addrPtr);
|
||||
|
||||
/**
|
||||
* @brief Unlocks the memory storing the pixel data of a given <b>PixelMap</b> to balance a successful call to {@link
|
||||
* AccessPixels}.
|
||||
*
|
||||
* @param env Indicates the pointer to the JNI environment.
|
||||
* @param pixelMapObject Indicates the Java <b>PixelMap</b> object.
|
||||
* @return Returns {@link OHOS_IMAGE_RESULT_SUCCESS} if the operation is successful; returns other result codes if
|
||||
* the operation fails.
|
||||
* @see AccessPixels
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_UnAccessPixels(napi_env env, napi_value value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif // IMAGE_PIXEL_MAP_NAPI_H
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file pixel_map_ndk.h
|
||||
*
|
||||
* @brief Declares functions for you to lock and access or unlock pixel data,
|
||||
* and obtain the width and height of a pixel map.
|
||||
*
|
||||
* @since 8
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef PIXEL_MAP_NDK_H
|
||||
#define PIXEL_MAP_NDK_H
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct OhosPixelMapInfo {
|
||||
/** Image width, in pixels. */
|
||||
uint32_t width;
|
||||
|
||||
/** Image height, in pixels. */
|
||||
uint32_t height;
|
||||
|
||||
/** Number of bytes in each row of a pixel map */
|
||||
uint32_t rowSize;
|
||||
|
||||
/** Pixel format */
|
||||
int32_t pixelFormat;
|
||||
};
|
||||
|
||||
int32_t OH_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info);
|
||||
|
||||
int32_t OH_AccessPixels(napi_env env, napi_value value, void** addrPtr);
|
||||
|
||||
int32_t OH_UnAccessPixels(napi_env env, napi_value value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PIXEL_MAP_NDK_H
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"first_introduced": "1",
|
||||
"name": "OH_GetImageInfo"
|
||||
},
|
||||
{
|
||||
"name": "OH_AccessPixels"
|
||||
},
|
||||
{
|
||||
"name": "OH_UnAccessPixels"
|
||||
}
|
||||
]
|
||||
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"name": "OH_GetImageInfo"
|
||||
},
|
||||
{
|
||||
"name": "OH_AccessPixels"
|
||||
},
|
||||
{
|
||||
"name": "OH_UnAccessPixels"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import image from '@ohos.multimedia.image'
|
||||
|
||||
declare namespace mypixelmap {
|
||||
function testGetImageInfo(PixelMap pixelMap): void;
|
||||
function testAccessPixels(PixelMap pixelMap): void;
|
||||
function testUnAccessPixels(PixelMap pixelMap): void;
|
||||
}
|
||||
|
||||
export default mypixelmap;
|
||||
@@ -0,0 +1,53 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
############################################################################
|
||||
# Debug Used : mypixelmap
|
||||
############################################################################
|
||||
|
||||
js_declaration("mypixelmap_js") {
|
||||
part_name = "multimedia_image"
|
||||
sources = [ "//foundation/multimedia/image_standard/interfaces/kits/native/ndk_test_example/@ohos.xtstest.mypixelmap.d.ts" ]
|
||||
}
|
||||
|
||||
ohos_copy("mypixelmap_declaration") {
|
||||
sources = [ "//foundation/multimedia/image_standard/interfaces/kits/native/ndk_test_example/@ohos.xtstest.mypixelmap.d.ts" ]
|
||||
outputs = [ target_out_dir + "/$target_name/" ]
|
||||
module_source_dir = target_out_dir + "/$target_name"
|
||||
module_install_name = ""
|
||||
}
|
||||
|
||||
ohos_shared_library("mypixelmap") {
|
||||
install_enable = true
|
||||
|
||||
sources = [ "my_pixel_map.cpp" ]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//foundation/multimedia/image_standard/interfaces/kits/native/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/multimedia/image_standard/frameworks/kits/js/common/pixelmap_ndk:pixelmap_ndk",
|
||||
]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
|
||||
relative_install_dir = "module"
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "multimedia_image"
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "my_pixel_map.h"
|
||||
#include "media_errors.h"
|
||||
#include "hilog/log.h"
|
||||
#include "image_napi_utils.h"
|
||||
#include "image_pixel_map_napi.h"
|
||||
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "MyPixelMapNapiTest"};
|
||||
constexpr uint32_t TEST_ARG_SUM = 1;
|
||||
}
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
static const std::string CLASS_NAME = "MyPixelMap";
|
||||
napi_ref MyPixelMap::sConstructor_ = nullptr;
|
||||
MyPixelMap::MyPixelMap()
|
||||
:env_(nullptr), wrapper_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
MyPixelMap::~MyPixelMap()
|
||||
{
|
||||
if (wrapper_ != nullptr) {
|
||||
napi_delete_reference(env_, wrapper_);
|
||||
}
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor props[] = {
|
||||
};
|
||||
|
||||
napi_property_descriptor static_prop[] = {
|
||||
DECLARE_NAPI_STATIC_FUNCTION("testGetImageInfo", TestGetImageInfo),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("testAccessPixels", TestAccessPixels),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("testUnAccessPixels", TestUnAccessPixels),
|
||||
};
|
||||
|
||||
napi_value constructor = nullptr;
|
||||
|
||||
if (napi_define_class(env, CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr, IMG_ARRAY_SIZE(props),
|
||||
props, &constructor) != napi_ok) {
|
||||
HiLog::Error(LABEL, "define class fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_create_reference(env, constructor, 1, &sConstructor_) != napi_ok) {
|
||||
HiLog::Error(LABEL, "create reference fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_set_named_property(env, exports, CLASS_NAME.c_str(), constructor) != napi_ok) {
|
||||
HiLog::Error(LABEL, "set named property fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_define_properties(env, exports, IMG_ARRAY_SIZE(static_prop), static_prop) != napi_ok) {
|
||||
HiLog::Error(LABEL, "define properties fail");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "Init success");
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::Constructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "Constructor IN");
|
||||
napi_value undefineVar = nullptr;
|
||||
napi_get_undefined(env, &undefineVar);
|
||||
|
||||
napi_status status;
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_undefined(env, &thisVar);
|
||||
|
||||
status = napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
|
||||
|
||||
HiLog::Debug(LABEL, "Constructor OUT");
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::TestGetImageInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "TestGetImageInfo IN");
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
|
||||
napi_status status;
|
||||
napi_value thisVar = nullptr;
|
||||
napi_value argValue[TEST_ARG_SUM] = {0};
|
||||
size_t argCount = TEST_ARG_SUM;
|
||||
|
||||
status = napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "napi_get_cb_info fail");
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "OH_GetImageInfo Test|Begin");
|
||||
OhosPixelMapInfo pixelMapInfo;
|
||||
int32_t res = OH_GetImageInfo(env, argValue[0], &pixelMapInfo);
|
||||
HiLog::Debug(LABEL, "OH_GetImageInfo Test|End, res=%{public}d", res);
|
||||
HiLog::Debug(LABEL, "OH_GetImageInfo, w=%{public}u, h=%{public}u, r=%{public}u, f=%{public}d",
|
||||
pixelMapInfo.width, pixelMapInfo.height, pixelMapInfo.rowSize, pixelMapInfo.pixelFormat);
|
||||
|
||||
HiLog::Debug(LABEL, "TestGetImageInfo OUT");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::TestAccessPixels(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "TestAccessPixels IN");
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
|
||||
napi_status status;
|
||||
napi_value thisVar = nullptr;
|
||||
napi_value argValue[TEST_ARG_SUM] = {0};
|
||||
size_t argCount = TEST_ARG_SUM;
|
||||
|
||||
status = napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "napi_get_cb_info fail");
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "OH_AccessPixels Test|Begin");
|
||||
void* addrPtr = nullptr;
|
||||
int32_t res = OH_AccessPixels(env, argValue[0], &addrPtr);
|
||||
HiLog::Debug(LABEL, "OH_AccessPixels Test|End, res=%{public}d, addrPtr=%{public}p", res, addrPtr);
|
||||
|
||||
HiLog::Debug(LABEL, "TestAccessPixels OUT");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value MyPixelMap::TestUnAccessPixels(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HiLog::Debug(LABEL, "TestUnAccessPixels IN");
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
|
||||
napi_status status;
|
||||
napi_value thisVar = nullptr;
|
||||
napi_value argValue[TEST_ARG_SUM] = {0};
|
||||
size_t argCount = TEST_ARG_SUM;
|
||||
|
||||
status = napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "napi_get_cb_info fail");
|
||||
}
|
||||
|
||||
HiLog::Debug(LABEL, "OH_UnAccessPixels Test|Begin");
|
||||
int32_t res = OH_UnAccessPixels(env, argValue[0]);
|
||||
HiLog::Debug(LABEL, "OH_UnAccessPixels Test|End, res=%{public}d", res);
|
||||
|
||||
HiLog::Debug(LABEL, "TestUnAccessPixels OUT");
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function registering all props and functions of ohos.medialibrary module
|
||||
*/
|
||||
static napi_value Export(napi_env env, napi_value exports)
|
||||
{
|
||||
HiLog::Error(LABEL, "MyPixelMap CALL");
|
||||
MyPixelMap::Init(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
||||
/*
|
||||
* module define
|
||||
*/
|
||||
static napi_module g_module = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Export,
|
||||
.nm_modname = "xtstest.mypixelmap",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = {0}
|
||||
};
|
||||
|
||||
/*
|
||||
* module register
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void MyPixelMapRegisterModule(void)
|
||||
{
|
||||
napi_module_register(&g_module);
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PIXEL_MAP_NAPI_TEST_H_
|
||||
#define PIXEL_MAP_NAPI_TEST_H_
|
||||
|
||||
#include "pixel_map.h"
|
||||
#include "image_type.h"
|
||||
#include "image_source.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class MyPixelMap {
|
||||
public:
|
||||
MyPixelMap();
|
||||
~MyPixelMap();
|
||||
|
||||
static napi_value Init(napi_env env, napi_value exports);
|
||||
|
||||
static napi_value TestGetImageInfo(napi_env env, napi_callback_info info);
|
||||
static napi_value TestAccessPixels(napi_env env, napi_callback_info info);
|
||||
static napi_value TestUnAccessPixels(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
static napi_value Constructor(napi_env env, napi_callback_info info);
|
||||
|
||||
static napi_ref sConstructor_;
|
||||
|
||||
napi_env env_ = nullptr;
|
||||
napi_ref wrapper_ = nullptr;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif /* PIXEL_MAP_NAPI_TEST_H_ */
|
||||
Reference in New Issue
Block a user