diff --git a/DmaMemoryRetrievePixelData/AppScope/app.json5 b/DmaMemoryRetrievePixelData/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ea13826626848873d8a83edea9cf41ef2408b217 --- /dev/null +++ b/DmaMemoryRetrievePixelData/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.dmamemoryretrievepixeldata", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/DmaMemoryRetrievePixelData/AppScope/resources/base/element/string.json b/DmaMemoryRetrievePixelData/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..bfc46978e42f59ec1fbae43610216c3e2665278f --- /dev/null +++ b/DmaMemoryRetrievePixelData/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DmaMemoryRetrievePixelData" + } + ] +} diff --git a/DmaMemoryRetrievePixelData/AppScope/resources/base/media/background.png b/DmaMemoryRetrievePixelData/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/DmaMemoryRetrievePixelData/AppScope/resources/base/media/background.png differ diff --git a/DmaMemoryRetrievePixelData/AppScope/resources/base/media/foreground.png b/DmaMemoryRetrievePixelData/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/DmaMemoryRetrievePixelData/AppScope/resources/base/media/foreground.png differ diff --git a/DmaMemoryRetrievePixelData/AppScope/resources/base/media/layered_image.json b/DmaMemoryRetrievePixelData/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/DmaMemoryRetrievePixelData/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/README.md b/DmaMemoryRetrievePixelData/README.md new file mode 100644 index 0000000000000000000000000000000000000000..05bf8b9f998f20a7b0adb5d2287e7cadb440bfb8 --- /dev/null +++ b/DmaMemoryRetrievePixelData/README.md @@ -0,0 +1,65 @@ +# DMA内存图片读取图像像素数据 + +### 介绍 + +本示例介绍了如何利用Node-API实现跨语言交互开发,在DMA_ALLOC模式下,获取内存中存储的准确图像像素数据,确保后期处理图像像素数据时不会因数据不准确导致图像显示异常。 + +### 使用说明 + +进入应用主页面后,点击页面中央的按钮,在ArkTS侧创建一个PixelMap并传递至Native侧。在Native侧读取并处理PixelMap的图像像素数据。 + +### 工程目录 + +``` +├──entry/src/main/cpp // Native层 +│ ├──types // Native层提供的接口 +│ │ └──libentry +│ │ ├──index.d.ts // Native侧提供的方法声明 +│ │ └──oh-package.json5 +│ ├──CMakeLists.txt // 编译入口 +│ └──napi_init.cpp // NAPI接口实现 +├──ets // ArkTS层 +│ ├──entryability // ArkTS层应用入口 +│ │ └──EntryAbility.ets +│ ├──entrybackupability +│ │ └──EntryBackupAbility.ets +│ └──pages +│ └──Index.ets // ArkTS层应用主页面 +├──resources // 资源文件 +│ ├──base +│ │ ├──element +│ │ ├──media +│ │ └──profile +│ └──rawfile +│ └──test.jpg // 测试图片 +└──module.json5 // 模块配置信息 +``` + +### 具体实现 +#### ArkTS层 +1. 在ArkTS层创建一个RGBA_8888像素格式、DMA_ALLOC内存模式的PixelMap对象,并传至Native侧。 + +#### Native层 +1. 在Native侧判断DMA内存中PixelMap的有效图像像素数据是否连续存储。 + +2. 若非连续(即存在行尾填充数据),必须在对图像数据做二次处理前,剥离每行像素数据末尾的填充部分。 + +3. 处理获取的准确图像像素数据,使用纯白色初始化像素缓冲区,得到处理后的图像像素数据。 + +### 相关权限 + +不涉及 + +### 依赖 + +库:libpixelmap_ndk.so + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS 系统:HarmonyOS 5.1.1 Beta1及以上。 + +3. DevEco Studio 版本:DevEco Studio 5.1.1 Beta1及以上。 + +4. HarmonyOS SDK 版本:HarmonyOS 5.1.1 Beta1 SDK及以上。 \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/build-profile.json5 b/DmaMemoryRetrievePixelData/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..491966a63973c405250fd7d5fa69319d2478c22b --- /dev/null +++ b/DmaMemoryRetrievePixelData/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.1.1(19)", + "compatibleSdkVersion": "5.1.1(19)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/build-profile.json5 b/DmaMemoryRetrievePixelData/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..821131c0b6cbb7de7bc5b6c71e031dce0049049e --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/build-profile.json5 @@ -0,0 +1,43 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/hvigorfile.ts b/DmaMemoryRetrievePixelData/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0e3a1ab98a91bc918d6404b2413111a5011f14a --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/obfuscation-rules.txt b/DmaMemoryRetrievePixelData/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/oh-package.json5 b/DmaMemoryRetrievePixelData/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9c1d4cca76ac664388dd6b1cf96697184c5133b --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/cpp/CMakeLists.txt b/DmaMemoryRetrievePixelData/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ab82d69f655b97968d98c73f0d2dae075a9a6cf --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,34 @@ +# +# Copyright (c) 2025 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. +# + +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(DmaMemoryRetrievePixelData) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +# [Start retrieve_pixel_data_link_libraries] +# Add the shared library named 'entry'. +add_library(entry SHARED napi_init.cpp) +# Link libraries for the shared library 'entry'. +target_link_libraries(entry PUBLIC libace_napi.z.so libpixelmap_ndk.z.so) +# [End retrieve_pixel_data_link_libraries] \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/cpp/napi_init.cpp b/DmaMemoryRetrievePixelData/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b938a224c6ca71ea50bdf0073610ee8223749d20 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start retrieve_pixel_data_native_methods] +#include +#include + +void ProcessPixelData(uint8_t* buffer, uint64_t bufferSize) +{ + // Fills a pixel buffer with opaque white in RGBA_8888 format (0xFFFFFFFF). + const uint8_t MAX_8BIT = 4; + memset(buffer, MAX_8BIT, bufferSize); +} + +static napi_value DmaMemCopy(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_boolean(env, false, &result); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // Initializes the PixelMap object received from ArkTS runtime. + NativePixelMap *nativePixelMap = OH_PixelMap_InitNativePixelMap(env, args[0]); + + struct OhosPixelMapInfos pixelMapInfo; + int32_t res = OH_PixelMap_GetImageInfo(nativePixelMap, &pixelMapInfo); + if (res != IMAGE_RESULT_SUCCESS) { + return result; + } + const uint8_t RGBA_PIXEL_BYTES = 4; // Each pixel consumes 4 bytes in RGBA_8888 format. + uint32_t stride = pixelMapInfo.rowSize; // Retrieves the stride value (in bytes) of the PixelMap. + uint32_t rowByteCount = pixelMapInfo.width * RGBA_PIXEL_BYTES; // Calculates the actual byte count per pixel row. + uint64_t dataSize = rowByteCount * pixelMapInfo.height; // Calculates actual bytes needed for PixelMap's pixel data. + std::unique_ptr data = std::make_unique(dataSize); + + void *pixelMapAddr = nullptr; + // Locks PixelMap memory and returns address. + OH_PixelMap_AccessPixels(nativePixelMap, &pixelMapAddr); + + uint8_t *dataRow = data.get(); + // Verifies whether row padding exists by comparing stride with actual byte count required per pixel row. + if (stride != rowByteCount) { + for (int i = 0; i < pixelMapInfo.height; i++) { // Retrieves valid pixel data row by row (excludes row padding). + memcpy(dataRow, static_cast(pixelMapAddr) + i * stride, rowByteCount); + dataRow += rowByteCount; + } + } else { + // Directly accesses pixel data from memory without row-by-row processing. + memcpy(dataRow, pixelMapAddr, dataSize); + } + + // Unlocks PixelMap memory when done. + OH_PixelMap_UnAccessPixels(nativePixelMap); + + // Processes the retrieved pixel. + ProcessPixelData(data.get(), dataSize); + + napi_get_boolean(env, true, &result); + return result; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + // Maps the ArkTS API to its Native layer implementation. + napi_property_descriptor desc[] = { + { "test_dmaAllocatorType_memcpy", nullptr, DmaMemCopy, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} +// [End retrieve_pixel_data_native_methods] \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/cpp/types/libentry/Index.d.ts b/DmaMemoryRetrievePixelData/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..62a27cf44646c136d7b2df23da0e43f904def8b9 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start retrieve_pixel_data_link_methods] +import { image } from '@kit.ImageKit'; +export const test_dmaAllocatorType_memcpy: (pixelMap: image.PixelMap) => boolean; +// [End retrieve_pixel_data_link_methods] \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/cpp/types/libentry/oh-package.json5 b/DmaMemoryRetrievePixelData/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..56322781032ce5be8c48efc7fe8e4bf5b46baaa9 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/ets/entryability/EntryAbility.ets b/DmaMemoryRetrievePixelData/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..03de9ddeb4315b230a1965f1c50fd9f5e2024ef5 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/DmaMemoryRetrievePixelData/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fca37ecc34e1079aaf6557f1272cd694aa0068c --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/ets/pages/Index.ets b/DmaMemoryRetrievePixelData/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c21a551622d5b13824d0f4e0fb4a83ccdafb9355 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start retrieve_pixel_data_arkts_methods] +// To use Native functions, ArkTS imports the "entry" library from the Native layer. +import testNapi from 'libentry.so'; +import { image } from '@kit.ImageKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; + +@Entry +@Component +struct Index { + + test_dmaAllocatorType_createPixelMap(): image.PixelMap { + const path = "test.png"; // Sample image. + const resourceMgr = this.getUIContext()?.getHostContext()?.resourceManager; + const rawFileDescriptor = resourceMgr?.getRawFdSync(path); + // Creates an ImageSource instance. + const imageSource = image.createImageSource(rawFileDescriptor); + const pixelMap = imageSource.createPixelMapUsingAllocatorSync( + { desiredPixelFormat: image.PixelMapFormat.RGBA_8888 }, // Specifies RGBA_8888 pixel format through image decoding parameters. + image.AllocatorType.DMA, // Specifies DMA memory type through custom allocation parameters. + ); + imageSource?.release(); + resourceMgr?.closeRawFdSync(path); + return pixelMap; + } + + build() { + Row() { + Column() { + Button('click me') + .onClick(() => { + const pixelMap = this.test_dmaAllocatorType_createPixelMap(); + if (!pixelMap) { + hilog.error(DOMAIN, 'Sample', 'test_dmaAllocatorType_createPixelMap failed.'); + return; + } + // Validates the success status of pixel data reading operations in the Native layer. + const result = testNapi.test_dmaAllocatorType_memcpy(pixelMap); + if (result) { + hilog.info(DOMAIN, 'Sample', 'test_dmaAllocatorType_memcpy succeed.'); + } else { + hilog.error(DOMAIN, 'Sample', 'test_dmaAllocatorType_memcpy failed.'); + } + pixelMap.release(); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End retrieve_pixel_data_arkts_methods] \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/module.json5 b/DmaMemoryRetrievePixelData/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5aa1f1236dd8ccc74a8e8671bebca557c2edaa1d --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/module.json5 @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/color.json b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/float.json b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/string.json b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/background.png b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/background.png differ diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/foreground.png b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/foreground.png differ diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/layered_image.json b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/startIcon.png b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/media/startIcon.png differ diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/profile/backup_config.json b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/base/profile/main_pages.json b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/DmaMemoryRetrievePixelData/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/DmaMemoryRetrievePixelData/entry/src/main/resources/rawfile/test.png b/DmaMemoryRetrievePixelData/entry/src/main/resources/rawfile/test.png new file mode 100644 index 0000000000000000000000000000000000000000..7e25b15fad9b907caa1e2e2fa9c585377697fa66 Binary files /dev/null and b/DmaMemoryRetrievePixelData/entry/src/main/resources/rawfile/test.png differ diff --git a/DmaMemoryRetrievePixelData/hvigor/hvigor-config.json5 b/DmaMemoryRetrievePixelData/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0cffdffcc7b142d94cdc988c0f2101bd67b4669c --- /dev/null +++ b/DmaMemoryRetrievePixelData/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.1.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/DmaMemoryRetrievePixelData/hvigorfile.ts b/DmaMemoryRetrievePixelData/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..47113e2e36ecefde41c136272a0bd6ff745cffe4 --- /dev/null +++ b/DmaMemoryRetrievePixelData/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/DmaMemoryRetrievePixelData/oh-package.json5 b/DmaMemoryRetrievePixelData/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d88836f94dd0e8e4cb6ebdba38c3bb056780471 --- /dev/null +++ b/DmaMemoryRetrievePixelData/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.1.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +}