diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c413edfa984634668c02af9b296158e2e78805ac --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.mslitehumansegmentation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_layered_image", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..79bcfc4de6b5d33657d50e36703fee1a0e86d54c --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MSLiteHumanSegmentation" + } + ] +} diff --git a/AppScope/resources/base/media/app_background.png b/AppScope/resources/base/media/app_background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AppScope/resources/base/media/app_background.png differ diff --git a/AppScope/resources/base/media/app_foreground.png b/AppScope/resources/base/media/app_foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AppScope/resources/base/media/app_foreground.png differ diff --git a/AppScope/resources/base/media/app_layered_image.json b/AppScope/resources/base/media/app_layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..b71c16122943f248ace0f5fa26da38b71dbdbdde --- /dev/null +++ b/AppScope/resources/base/media/app_layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:app_background", + "foreground" : "$media:app_foreground" + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..18795a48d6b12fcdc1aa7bac9a9cb99f83815267 --- /dev/null +++ b/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved. + + 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. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md index 2cf4cc1823644831dfb810e05bda397eecf68353..bbc13e5ec6ba88a60db881f4f10717a37a878d6d 100644 --- a/README.en.md +++ b/README.en.md @@ -1,36 +1,74 @@ -# MSLiteHumanSegmentation +# Implementing On-Device Portrait Image Segmentation Based on MindSpore Lite +## Introduction +This example utilizes the ArkTS API provided by `@ohos.ai.mindSporeLite` to implement an "On-Device Portrait Image Segmentation and Composition" sample application. -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} +## Preview +| Home Page | Album Page | Original Image Preview Page | Portrait Segmentation and Composition Results Page | +|---------------------------------------------------|---------------------------------------------------------|----------------------------------------------------------------|---------------------------------------------------------------------| +| ![Home Page](screenshots/device/screenshot_001.png "Home Page") | ![Album Page](screenshots/device/screenshot_002.png "Album Page") | ![Original Image Preview Page](screenshots/device/screenshot_003.png "Original Image Preview Page") | ![Portrait Segmentation and Composition Results Page](screenshots/device/screenshot_004.png "Portrait Segmentation and Composition Results Page") | -#### Software Architecture -Software architecture description +## Usage Instructions +1. On the image segmentation page, click the "Image Composition" button to enter the album selection interface. +2. In the album interface, select a portrait image and click the "Confirm" button. +3. After selecting the image, the application will navigate to the image composition page, with the "Original" tab selected by default to display the chosen image. +4. Clicking the "Composition" tab will automatically perform portrait segmentation model inference on the first background image and the original image, with the results displayed on the main interface. +5. Under the "Composition" tab, any background from the list can be selected for portrait segmentation inference, and the results will be displayed in real-time on the main interface. -#### Installation +## Project Directory +``` +├──entry/src/main/ets/ +│ ├──common +│ │ └──ImageDataListConstant.ets // Image inference static configuration +│ ├──entryability +│ │ └──EntryAbility.ets // Ability life cycle callback content +│ ├──model +│ │ └──NavigationParam.ets // Navigation parameter transfer class +│ ├──pages +│ │ ├──Index.ets // Home page for fetching album images +│ │ └──ImageGenerate.ets // Original and composite image preview interface +│ └──util +│ ├──Gaussion.ets // Gaussian filtering algorithm utility class +│ └──Predict.ets // Model inference implementation +└──entry/src/main/resources/ + └──rawfile + └──model_float32.ms // Stored model file +``` -1. xxxx -2. xxxx -3. xxxx +## Implementation Details +The terminal image segmentation model used in this sample application is `model_float32.ms`, placed in the `entry\src\main\resources\rawfile` project directory. -#### Instructions +- The home page uses [@ohos.file.photoAccessHelper](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-photoaccesshelper) (image file selection) to open the album, [@ohos.multimedia.image](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-image) (image processing effects), and [@ohos.file.fs](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs) (basic file operations) APIs to fetch and process album images. The complete code can be found in [Index.ets](entry/src/main/ets/pages/Index.ets) and [ImageGenerate.ets](entry/src/main/ets/pages/ImageGenerate.ets). -1. xxxx -2. xxxx -3. xxxx +- The image composition page uses the [@kit.MindSporeLiteKit](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-mindsporelite) (inference capability) API to perform on-device inference. The complete code can be found in [Predict.ets](entry/src/main/ets/utils/Predict.ets). -#### Contribution +- The inference function is called, and the results are processed. The complete code can be found in [ImageGenerate.ets](entry/src/main/ets/pages/ImageGenerate.ets). -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request +## Sequence Diagram +![](./screenshots/Timing_digram.PNG) +## Required Permissions +None. -#### Gitee Feature +## Dependencies +Add the `syscap.json` file in the project's main directory with the following configuration: -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +```json5 +{ + "devices": { + "general": [ + "phone" // Fill in the device type as needed + ] + }, + "development": { + "addedSysCaps": [ + "SystemCapability.AI.MindSporeLite" + ] + } +} +``` + +## Constraints and Limitations +1. This example only runs on standard systems and supports Huawei phones. +2. HarmonyOS version: HarmonyOS 5.1.0 Release or later. +3. DevEco Studio version: DevEco Studio 5.1.0 Release or later. +4. HarmonyOS SDK version: HarmonyOS 5.1.0 Release SDK or later. \ No newline at end of file diff --git a/README.md b/README.md index 96a77400fb8163887c96a35765d8e3cae0b1997b..3eb662bb5bb830a63fa25ed5c8d8a7b725d792a2 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,79 @@ -# MSLiteHumanSegmentation +# 基于 MindSpore Lite 实现端侧人物图像分割 +## 介绍 +本示例基于`@ohos.ai.mindSporeLite`提供的ArkTS API,实现“端侧人物图像分割与合成”示例程序。 -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +## 效果预览 +| 主页 | 相册页 | 原图预览页 | 人物图像分割合成结果页 | +|---------------------------------------------------|---------------------------------------------------------|----------------------------------------------------------------|---------------------------------------------------------------------| +| ![主页](screenshots/device/screenshot_001.png "主页") | ![相册页](screenshots/device/screenshot_002.png "相册页") | ![原图预览页](screenshots/device/screenshot_003.png "原图预览页") | ![人物图像分割合成结果页](screenshots/device/screenshot_004.png "人物图像分割合成结果页") | -#### 软件架构 -软件架构说明 +使用说明 +1. 在图像分割页面,可以点击图像合成按钮,进入相册选择图片界面; +2. 在相册界面,选择`一张人物图像`,点击确定按钮; +3. 图像选择好后,会跳转到图像合成页面,默认选中原图 tab并展示选择后的原图; +4. 点击合成 tab 会默认对第一张背景图和原图进行人物图像分割模型推理,推理的结果会显示在主界面; +5. 在合成 tab 下,可以选择列表中的任意背景,进行人物图像分割推理,并实时在主界面展示推理结果; -#### 安装教程 +## 工程目录 +``` +├──entry/src/main/ets/ +│ ├──common +│ │ └──ImageDataListConstant.ets // 图像推理静态配置 +│ ├──entryability +│ │ └──EntryAbility.ets // Ability的生命周期回调内容 +│ ├──model +│ │ └──NavigationParam.ets // Navigation参数传递类 +│ ├──pages +│ │ ├──Index.ets // 首页,获取相册图片 +│ │ └──ImageGenerate.ets // 原图和合成图预览界面 +│ └──util +│ ├──Gaussion.ets // 高斯滤波算法工具类 +│ └──Predict.ets // 模型推理实现 +└──entry/src/main/resources/ + └──rawfile + └──model_float32.ms // 存放的模型文件:model_float32.ms +``` -1. xxxx -2. xxxx -3. xxxx -#### 使用说明 +## 具体实现 +本示例程序中使用的终端图像分割模型为`model_float32.ms`,放置在`entry\src\main\resources\rawfile`工程目录下。 -1. xxxx -2. xxxx -3. xxxx +- 首页调用[@ohos.file.photoAccessHelper](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-photoaccesshelper) (图片文件选择)拉起相册、[@ohos.multimedia.image](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-image) (图片处理效果)、[@ohos.file.fs](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-file-fs) (基础文件操作) 等API实现相册图片获取及图片处理。完整代码请参见[Index.ets](entry/src/main/ets/pages/Index.ets)、[ImageGenerate.ets](entry/src/main/ets/pages/ImageGenerate.ets) -#### 参与贡献 +- 图像合成页调用[@kit.MindSporeLiteKit](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-mindsporelite) (推理能力) API实现端侧推理。完整代码请参见[Predict.ets](entry/src/main/ets/utils/Predict.ets) -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +- 调用推理函数并处理结果。完整代码请参见[ImageGenerate.ets](entry/src/main/ets/pages/ImageGenerate.ets) +## 时序流程图 +![](./screenshots/Timing_digram.PNG) -#### 特技 +## 相关权限 +无。 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +## 依赖 +在工程 main 目录中,添加 `syscap.json` 文件,添加如下配置 + +```json5 +{ + "devices": { + "general": [ + "phone" // 根据实际需要填写设备类型 + ] + }, + "development": { + "addedSysCaps": [ + "SystemCapability.AI.MindSporeLite" + ] + } +} +``` + +## 约束与限制 +1. 本示例仅支持标准系统上运行,支持设备:华为手机; + +2. HarmonyOS系统:HarmonyOS 5.1.0 Release及以上; + +3. DevEco Studio版本:DevEco Studio 5.1.0 Release及以上; + +4. HarmonyOS SDK版本:HarmonyOS 5.1.0 Release SDK及以上。 \ No newline at end of file diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d9f834241009b9c42fba895485af665f466d3071 --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.1.0(18)", + "compatibleSdkVersion": "5.0.5(17)", + "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/code-linter.json5 b/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..38bdcc9929e2c5bd7f51c4fc96a398ccebd0d6ce --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,39 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0e3a1ab98a91bc918d6404b2413111a5011f14a --- /dev/null +++ b/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/entry/obfuscation-rules.txt b/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/entry/oh-package-lock.json5 b/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2857b556e1b879745efca26121d68bb5d43c38cf --- /dev/null +++ b/entry/oh-package-lock.json5 @@ -0,0 +1,10 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": {}, + "packages": {} +} \ No newline at end of file diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..803b25293388deda7b9a05a21b5aeadeb716b4d5 --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} \ No newline at end of file diff --git a/entry/src/main/ets/common/constants/ImageDataListConstant.ets b/entry/src/main/ets/common/constants/ImageDataListConstant.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d3b729d5f6cacc3b348d81e5012874ffef23b79 --- /dev/null +++ b/entry/src/main/ets/common/constants/ImageDataListConstant.ets @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/** + * Model input height and width constants + */ +export const MODEL_INPUT_HEIGHT = 192; +export const MODEL_INPUT_WIDTH = 192; +export const BLACKGROUND_THEADHOLD = 0.5; +export const MODEL_NAME = "model_float32.ms"; + +/** + * List data constants for all features + */ +export class ListDataConstants { + /** + * Service directory list + */ + static readonly IMG_LIST: Resource[] = [ + $r("app.media.img_001"), + $r("app.media.img_002"), + $r("app.media.img_003"), + $r("app.media.img_004"), + $r("app.media.img_005"), + $r("app.media.img_006"), + $r("app.media.img_007"), + $r("app.media.img_008"), + $r("app.media.img_009"), + ] +} diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3ee54d2beea61d38866762868bd056d3e39e3c9 --- /dev/null +++ b/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/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a97e21bd7a15599af76a806695860ff1eb0ebfe --- /dev/null +++ b/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/entry/src/main/ets/model/NavigationParam.ets b/entry/src/main/ets/model/NavigationParam.ets new file mode 100644 index 0000000000000000000000000000000000000000..8da4494f6ebcd96ecb85b8a70909ff47961b206b --- /dev/null +++ b/entry/src/main/ets/model/NavigationParam.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export default class NavigationParam { + photoUri: string = ''; + constructor(uri: string) { + this.photoUri = uri; + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/ImageGenerate.ets b/entry/src/main/ets/pages/ImageGenerate.ets new file mode 100644 index 0000000000000000000000000000000000000000..c860f21ee5ad81ce50dc6658b0d5115117342d94 --- /dev/null +++ b/entry/src/main/ets/pages/ImageGenerate.ets @@ -0,0 +1,384 @@ +/* + * 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 { image } from "@kit.ImageKit"; +import { resourceManager } from "@kit.LocalizationKit"; +import { fileIo } from "@kit.CoreFileKit"; +import { ItemRestriction, SegmentButton, SegmentButtonOptions, SegmentButtonTextItem } from "@kit.ArkUI"; +import { + BLACKGROUND_THEADHOLD, + ListDataConstants, + MODEL_INPUT_HEIGHT, + MODEL_INPUT_WIDTH, + MODEL_NAME +} from "../common/constants/ImageDataListConstant"; +import NavigationParam from "../model/NavigationParam"; +import modelPredict from "../utils/Predict"; +import { gaussianRun } from "../utils/Gaussion"; + + +@Observed +class BackgroundImageItem { + src: ResourceStr = ''; + content: ResourceStr = ''; + selected: boolean = false; + + constructor(src: ResourceStr, content: ResourceStr, selected: boolean) { + this.src = src; + this.content = content; + this.selected = selected; + } +} + +@Builder +export function ImageGeneratePageBuilder() { + ImageGenerate() +} + +@Component +export struct PreviewImage { + @ObjectLink imgItem: BackgroundImageItem; + + build() { + ListItem() { + RelativeContainer() { + Column() { + } + .height(34) + .width("100%") + .id("id_swiper_image_gradient") + .alignRules({ + top: { anchor: "__container__", align: VerticalAlign.Top }, + left: { anchor: "__container__", align: HorizontalAlign.Start }, + right: { anchor: "__container__", align: HorizontalAlign.End }, + bottom: { anchor: "__container__", align: VerticalAlign.Bottom } + }) + .margin({ top: 34 }) + .linearGradient({ + direction: GradientDirection.Bottom, + repeating: false, + colors: [['rgba(0,0,0,0)', 0], ['rgba(0,0,0,0.45)', 1.0]] + }) + .zIndex(1) + .borderRadius({ + bottomLeft: 8, + bottomRight: 8 + }) + + Text(this.imgItem.content) + .width(52) + .height(16) + .fontSize(12) + .lineHeight(16) + .id("id_swiper_image_type") + .fontColor("#FFF") + .alignRules({ + top: { anchor: "id_swiper_image_gradient", align: VerticalAlign.Top }, + left: { anchor: "id_swiper_image_gradient", align: HorizontalAlign.Start }, + right: { anchor: "id_swiper_image_gradient", align: HorizontalAlign.End }, + bottom: { anchor: "id_swiper_image_gradient", align: VerticalAlign.Bottom } + }) + .margin({ + top: 10, + left: 8, + bottom: 8, + right: 8 + }) + .zIndex(2) + }.borderRadius(8) + } + .backgroundImage(this.imgItem.src) + .backgroundImageSize(ImageSize.Cover) + .width(68) + .height(68) + .border({ + width: this.imgItem.selected ? 1 : 0, + radius: 8, + color: this.imgItem.selected ? "#0A59F7" : Color.Transparent + }) + } +} + +@Component +export struct ImageGenerate { + @State outMergePixMap: image.PixelMap | undefined = undefined; + pathStack: NavPathStack = new NavPathStack(); + private modelName: string = MODEL_NAME; + @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({ + buttons: [{ text: $r("app.string.segment_btn_text_first") }, + { text: $r("app.string.segment_btn_text_second") }] as ItemRestriction, + fontColor: 'rgba(0,0,0,0.9)', + selectedFontColor: 'rgba(0,0,0,0.6)', + fontSize: 14, + selectedFontSize: 14, + buttonPadding: { + top: 10, + bottom: 10, + left: 16, + right: 16 + }, + selectedFontWeight: FontWeight.Medium, + backgroundBlurStyle: BlurStyle.BACKGROUND_THICK + }); + @State currentTab: number = 0; + @State tabSelectedIndexes: number[] = [this.currentTab]; + @State currentPreviewImageIndex: number = 0; + @State previewImageList: BackgroundImageItem[] = [ + new BackgroundImageItem($r("app.media.img_001"), $r("app.string.preview_img_list_001"), true), + new BackgroundImageItem($r("app.media.img_002"), $r("app.string.preview_img_list_002"), false), + new BackgroundImageItem($r("app.media.img_003"), $r("app.string.preview_img_list_003"), false), + new BackgroundImageItem($r("app.media.img_004"), $r("app.string.preview_img_list_004"), false), + new BackgroundImageItem($r("app.media.img_005"), $r("app.string.preview_img_list_005"), false), + new BackgroundImageItem($r("app.media.img_006"), $r("app.string.preview_img_list_006"), false), + new BackgroundImageItem($r("app.media.img_007"), $r("app.string.preview_img_list_007"), false), + new BackgroundImageItem($r("app.media.img_008"), $r("app.string.preview_img_list_008"), false), + new BackgroundImageItem($r("app.media.img_009"), $r("app.string.preview_img_list_009"), false) + ]; + @State photoUri: string = ''; + handleSegmentButtonChange: Callback = (index: number) => { + this.currentTab = index; + // combine image + if (this.currentTab === 1) { + this.handleMergeImage(); + } + } + handleMergeImage = async () => { + let resMgr: resourceManager.ResourceManager = + this.getUIContext().getHostContext()?.getApplicationContext().resourceManager as resourceManager.ResourceManager; + if (!resMgr) { + return + } + const modelBuffer = resMgr.getRawFileContentSync(this.modelName); + // Preprocess image data + try { + // 1. use the `fileIo.openSync` interface to open the file via URI and obtain the file descriptor (fd) + let file = fileIo.openSync(this.photoUri, fileIo.OpenMode.READ_ONLY); + console.log('MS_LITE_LOG: file.fd: ' + file.fd); + + // 2. Read the data within this file using the fileIo.readSync interface through fd + let inputBuffer = new ArrayBuffer(4096000); + let readLen = fileIo.readSync(file.fd, inputBuffer); + console.log('MS_LITE_LOG: readSync data to file succeed and inputBuffer size is: ' + readLen); + + // 3. Preprocessing through PixelMap + let imageSource = image.createImageSource(file.fd); + let pixelMap = imageSource.createPixelMapSync(); + let info = pixelMap.getImageInfoSync(); + console.log(`MS_LITE_LOG: info.size is => ${JSON.stringify(info.size)}`); + + // 4. Obtain the image buffer data readBuffer and process it. + pixelMap.scaleSync(MODEL_INPUT_WIDTH / info.size.width, MODEL_INPUT_HEIGHT / info.size.height); + // The size of the pixel buffer that needs to be created. + let readBuffer = new ArrayBuffer(MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 4); + await pixelMap.readPixelsToBuffer(readBuffer); + console.log('MS_LITE_LOG: Succeeded in reading image pixel data, buffer: ' + readBuffer.byteLength); + pixelMap.release(); + + // Process the read buffer + const imageArr = new Uint8Array( + readBuffer.slice(0, MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 4)); + console.info('MS_LITE_LOG: imageArr length: ' + imageArr.length); + + // Construct Input Tensor (Input Preprocessing); + // === Attention! This step needs to be performed according to the image storage format of the model, as NCHW and NHWC are constructed differently! === + + let float32View = new Float32Array(MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 3); + let means = [0.5, 0.5, 0.5]; + let stds = [0.5, 0.5, 0.5]; + let index = 0; + for (let i = 0; i < imageArr.length; i++) { + if ((i + 1) % 4 === 0) { + float32View[index] = (imageArr[i - 3] / 255.0 - means[0]) / stds[0]; // R + float32View[index + 1] = (imageArr[i - 2] / 255.0 - means[1]) / stds[1]; // B + float32View[index + 2] = (imageArr[i - 1] / 255.0 - means[2]) / stds[2]; // G + index += 3; + } + } + + let inputs: ArrayBuffer[] = [float32View.buffer]; + console.log('inputs length is ' + inputs.length); + // predict + modelPredict(modelBuffer.buffer.slice(0), inputs).then(async outputs => { + console.info("==== MS_LITE_LOG: MS_LITE predict success ===="); + + let output: Float32Array = new Float32Array(outputs[0].getData()); + + let picArr = new Uint8Array(MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 4); + let isHumanArr = new Array(MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH); + for (let i = 0; i < picArr.length; i++) { + if ((i + 1) % 4 === 0) { + let isHuman = output[(i + 1) / 2 - 1] > BLACKGROUND_THEADHOLD; + isHumanArr[(i + 1) / 4] = isHuman; + if (isHuman) { + picArr[i - 1] = imageArr[i - 3]; + picArr[i - 2] = imageArr[i - 2]; + picArr[i - 3] = imageArr[i - 1]; + picArr[i] = 255; + } else { + picArr[i - 1] = 0; + picArr[i - 2] = 0; + picArr[i - 3] = 0; + picArr[i] = 0; + } + } + } + + // Display the extracted character image + let opts: image.InitializationOptions = { + editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, + size: { height: MODEL_INPUT_HEIGHT, width: MODEL_INPUT_WIDTH } + }; + image.createPixelMap(picArr.buffer, opts).then(async (pixelmap) => { + // Image cutout effect + pixelmap.release(); + }); + + // composite image + try { + // Synthesize the next image + let img = this.currentPreviewImageIndex >= 3 ? ListDataConstants.IMG_LIST[this.currentPreviewImageIndex] : + this.previewImageList[this.currentPreviewImageIndex].src as Resource; + resMgr.getMediaContent(img).then(async (img) => { + let imageSourceBg: image.ImageSource = image.createImageSource(img.buffer.slice(0)); + // Create pixelMap + let pixelMapBg: image.PixelMap = imageSourceBg.createPixelMapSync(); + let infoBg = await pixelMapBg.getImageInfo(); + pixelMapBg.scaleSync(MODEL_INPUT_WIDTH / infoBg.size.width, MODEL_INPUT_HEIGHT / infoBg.size.height); + let readBufferBg = new ArrayBuffer(MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 4); + pixelMapBg.readPixelsToBuffer(readBufferBg).then(() => { + let bgArr = new Uint8Array(readBufferBg.slice(0, MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 4)); + let resArr = new Uint8Array(MODEL_INPUT_HEIGHT * MODEL_INPUT_WIDTH * 4); + for (let i = 0; i < resArr.length; ++i) { + if ((i + 1) % 4 === 0) { + if (isHumanArr[(i + 1) / 4 - 1]) { + resArr[i - 1] = picArr[i - 1]; + resArr[i - 2] = picArr[i - 2]; + resArr[i - 3] = picArr[i - 3]; + resArr[i] = 255; + } else { + resArr[i - 1] = bgArr[i - 3]; + resArr[i - 2] = bgArr[i - 2]; + resArr[i - 3] = bgArr[i - 1]; + resArr[i] = 255; + } + } + } + let opts: image.InitializationOptions = { + editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, + size: { height: MODEL_INPUT_HEIGHT, width: MODEL_INPUT_WIDTH } + }; + // Gaussian filtering: This step is not mandatory + // gaussianRun(resArr) + pixelMapBg.release(); + this.outMergePixMap = image.createPixelMapSync(resArr.buffer, opts); + }) + imageSourceBg.release(); + }) + } catch (error) { + console.error("Failed to get media content", JSON.stringify(error)); + } + }) + // 5. close fileIo + fileIo.closeSync(file); + imageSource.release(); + } catch (err) { + console.error("MS_LITE_LOG: uri: open file fd failed." + err); + } + } + + aboutToDisappear(): void { + if (this.outMergePixMap) { + this.outMergePixMap.release(); + } + } + build() { + NavDestination() { + Column() { + SegmentButton({ + options: this.tabOptions, + selectedIndexes: $tabSelectedIndexes, + onItemClicked: this.handleSegmentButtonChange + }) + .margin({ bottom: 16 }) + .width(164).height(40) + + RelativeContainer() { + // Original Image Placeholder + Image(this.currentTab === 0 ? this.photoUri : this.outMergePixMap) + .id("id_display_img") + .alignRules({ + middle: { anchor: "__container__", align: HorizontalAlign.Center }, + center: { anchor: "__container__", align: VerticalAlign.Center } + }) + .padding({ + top: 24, + bottom: 24, + left: 16, + right: 16 + }) + .objectFit(ImageFit.Fill) + } + .width("100%") + .height(480) + .backgroundColor($r("app.color.image_display_are_background")) + + if (this.currentTab === 1) { + Row() { + List({ space: 4 }) { + ForEach(this.previewImageList, (item: BackgroundImageItem, index: number) => { + PreviewImage({ imgItem: item }) + .onClick(() => { + this.previewImageList[index].selected = true; + this.currentPreviewImageIndex = index; + this.handleMergeImage(); + this.previewImageList.forEach((item, idx) => { + if (idx !== index) { + this.previewImageList[idx].selected = false; + } + }) + }) + }, (item: BackgroundImageItem) => JSON.stringify(item)) + } + .margin({ left: 16, top: 12 }) + .height(68) + .listDirection(Axis.Horizontal) + .scrollBar(BarState.Off) + .edgeEffect(EdgeEffect.Spring) + .friction(0.8) + }.width("100%") + + // List End + } + }.width("100%").height("100%").margin({ top: 8 }) + } + .title({ builder: this.navigationTitle($r("app.string.image_page_navbar_title")), height: 56 }) + .backgroundColor($r("app.color.window_background")) + .onReady((context: NavDestinationContext) => { + this.pathStack = context.pathStack; + const ret = this.pathStack.getParamByIndex(0) as NavigationParam; + this.photoUri = ret.photoUri; + }) + } + + @Builder + navigationTitle(content: ResourceStr) { + Text(content) + .fontColor("rgba(0,0,0,0.9)") + .fontSize(20) + .fontWeight(FontWeight.Bold) + .lineHeight(27) + .margin({ top: 14.5, left: 8, bottom: 14.5 }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a15dfca8cc2e97c1889185417d2cda0ce7106a8 --- /dev/null +++ b/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,85 @@ +/* + * 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 { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import NavigationParam from '../model/NavigationParam'; + +@Entry +@Component +struct Index { + pathStack: NavPathStack = new NavPathStack(); + + build() { + Navigation(this.pathStack) { + RelativeContainer() { + Button($r("app.string.home_btn_text")) + .id("id_home_btn") + .alignRules({ + left: { anchor: "__container__", align: HorizontalAlign.Start}, + right: { anchor: "__container__", align: HorizontalAlign.End}, + bottom: { anchor: "__container__", align: VerticalAlign.Bottom}, + }) + .margin({ bottom: 16, left: 16, right: 16}) + .onClick(() => { + // 1. Create Image-Video Type File Selection Option Instance + let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + + // 2. Filter and select media file type as IMAGE + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; + photoSelectOptions.maxSelectNumber = 1;// Maximum number of media files to select + + // 3. Create an instance of the gallery selector and call the select() interface to launch the gallery interface for file selection. upon successful file selection. return the photoSelectResult result ret. + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + photoPicker.select(photoSelectOptions, async (err: BusinessError, photoSelectResult: photoAccessHelper.PhotoSelectResult) => { + if (err) { + console.error('MS_LITE_ERR, photoViewPicker.select failed with err:' + JSON.stringify(err)); + return; + } + console.info('MS_LITE_LOG: PhotoViewPicker.select successfully, ' + `photoSelectResult uri + ${JSON.stringify(photoSelectResult.photoUris)}`); + let param = new NavigationParam(photoSelectResult.photoUris[0]); + if (param && param.photoUri.length > 0) { + this.pathStack.pushPath({ name: 'ImageGenerate', param}); + } + }); + }) + } + .id("id_home_navigation") + .height("100%") + .width("100%") + } + .title({ builder: this.titleBuilder, height: 112}) + .mode(NavigationMode.Stack) + .backgroundColor($r("app.color.window_background")) + } + + @Builder + titleBuilder() { + Column() { + Text($r("app.string.home_navbar_title")) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .lineHeight(40) + .fontColor("rgba(0,0,0,0.9)") + .margin({ + left: 16, + right: 16, + top: 64, + bottom: 8 + }) + } + .height(112) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/utils/Gaussion.ets b/entry/src/main/ets/utils/Gaussion.ets new file mode 100644 index 0000000000000000000000000000000000000000..c8822b8912cc8f8f02ed22e82fb5a071bc2fb099 --- /dev/null +++ b/entry/src/main/ets/utils/Gaussion.ets @@ -0,0 +1,76 @@ +/* + * 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 { MODEL_INPUT_HEIGHT } from '../common/constants/ImageDataListConstant'; + +function gaussianRun(mat: Uint8Array) { + console.log("----- gaussian run -----"); + let rMat = new Array>(); + let gMat = new Array>(); + let bMat = new Array>(); + for (let i = 0; i < MODEL_INPUT_HEIGHT; ++i) { + let rTempArr = new Array(); + let gTempArr = new Array(); + let bTempArr = new Array(); + for (let j = 0; j < MODEL_INPUT_HEIGHT; ++j) { + let index = (i * MODEL_INPUT_HEIGHT + j) * 4; + rTempArr.push(mat[index]); + gTempArr.push(mat[index + 1]); + bTempArr.push(mat[index + 2]); + } + rMat.push(rTempArr); + gMat.push(gTempArr); + bMat.push(bTempArr); + } + calcGaussian(rMat); + calcGaussian(gMat); + calcGaussian(bMat); + for (let i = 0; i < mat.length; ++i) { + if ((i + 1) % 4 === 0) { + let chanelPx: number = Math.floor(i / 4 / MODEL_INPUT_HEIGHT); + let chanelPy: number = Math.floor((i % (4 * MODEL_INPUT_HEIGHT)) / 4); + mat[i - 3] = rMat[chanelPx][chanelPy]; + mat[i - 2] = rMat[chanelPx][chanelPy]; + mat[i - 1] = rMat[chanelPx][chanelPy]; + } + } +} + +function calcGaussian(calcMat: Array>) { + console.log("_...-----calcGaussian run----------") + for (let i = 1; i < calcMat.length - 1; ++i) { + for (let j = 1; j < calcMat[i].length - 1; ++j) { + calcMat[i][j] = getOpValue(calcMat, i, j) + } + } +} + +// Template generated using a Gaussian function with o=0.8 +function getOpValue(mat: Array>, i: number, j: number): number { + return Math.floor( + (mat[i - 1][j - 1] / 16.0) + + (mat[i - 1][j] / 8.0) + + (mat[i - 1][j + 1] / 16.0) + + (mat[i][j - 1] / 8.0) + + (mat[i][j] / 4.0) + + (mat[i][j + 1] / 8.0) + + (mat[i + 1][j - 1] / 16.0) + + (mat[i + 1][j] / 8.0) + + (mat[i + 1][j + 1] / 16.0)) +} + +export { + gaussianRun +} \ No newline at end of file diff --git a/entry/src/main/ets/utils/Predict.ets b/entry/src/main/ets/utils/Predict.ets new file mode 100644 index 0000000000000000000000000000000000000000..5403f06c7d81809195a5c6bf6c5e17fe5bfc4afb --- /dev/null +++ b/entry/src/main/ets/utils/Predict.ets @@ -0,0 +1,46 @@ +/* + * 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 { mindSporeLite } from '@kit.MindSporeLiteKit'; + +export default async function modelPredict + (modelBuffer: ArrayBuffer, inputsBuffer: ArrayBuffer[]): Promise { + // 1. Create Context + let context: mindSporeLite.Context = {}; + context. target = ['cpu']; + context.cpu = {}; + context.cpu.threadNum = 2; + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = 'enforce_fp32'; + console.info("MS_LITE_LOG load model before ...") + // 2. Load Model + let msLiteModel: mindSporeLite.Model = await mindSporeLite.loadModelFromBuffer(modelBuffer, context); + console.info("MS_LITE_LOG load model after...") + // 3. Set input data + let modelInputs: mindSporeLite.MSTensor[] = msLiteModel.getInputs(); + console.info("MS_LITE_L06 msLiteModel.getInputs ...") + // This model does not support resizing other shapes. + for (let i = 0; i < inputsBuffer.length; i++) { + let inputBuffer = inputsBuffer[i]; + if (inputBuffer != null) { + modelInputs[i].setData(inputBuffer as ArrayBuffer); + } + } + // 4. Execute reasoning + console.info('=========MS_LITE_L06: MS_LITE predict start====='); + let modelOutputs: mindSporeLite.MSTensor[] = await msLiteModel.predict(modelInputs) ; + console.info("MS_LITE_LOG predict after ..."); + return modelOutputs; +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d6640d8b2347e21fc761e675816ffc6b52279529 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,51 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "routerMap": "$profile:route_map", + "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": [ + "action.system.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/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..83dcca1e934145d0c96e46ef5f80cc6497d5707c --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,16 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "window_background", + "value": "#F3F3F3" + }, + { + "name": "image_display_are_background", + "value": "#D1D1D6" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..962283f3b0f9216540c8c0bee443db6f25c34e50 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,71 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "图像分割合成" + }, + { + "name": "home_btn_text", + "value": "图像合成" + }, + { + "name": "home_navbar_title", + "value": "图像分割" + }, + { + "name": "image_page_navbar_title", + "value": "图像合成" + }, + { + "name": "segment_btn_text_first", + "value": "原图" + }, + { + "name":"segment_btn_text_second", + "value": "合成" + }, + { + "name": "preview_img_list_001", + "value": "默认" + }, + { + "name": "preview_img_list_002", + "value": "蓝色" + }, + { + "name": "preview_img_list_003", + "value": "红色" + }, + { + "name": "preview_img_list_004", + "value": "背景1" + }, + { + "name": "preview_img_list_005", + "value": "背景2" + }, + { + "name": "preview_img_list_006", + "value": "背景3" + }, + { + "name": "preview_img_list_007", + "value": "背景4" + }, + { + "name": "preview_img_list_008", + "value": "背景5" + }, + { + "name": "preview_img_list_009", + "value": "背景6" + }] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/background.png b/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/entry/src/main/resources/base/media/background.png differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/entry/src/main/resources/base/media/foreground.png differ diff --git a/entry/src/main/resources/base/media/img_001.jpg b/entry/src/main/resources/base/media/img_001.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4b69593e25a1870afbdf0039aa3f13be7debb231 Binary files /dev/null and b/entry/src/main/resources/base/media/img_001.jpg differ diff --git a/entry/src/main/resources/base/media/img_002.jpg b/entry/src/main/resources/base/media/img_002.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1a3d5cc1006a650672cbffd4cb1e839ed2834fc6 Binary files /dev/null and b/entry/src/main/resources/base/media/img_002.jpg differ diff --git a/entry/src/main/resources/base/media/img_003.jpg b/entry/src/main/resources/base/media/img_003.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1d958a0d1f913daf9a570a009908543f45a53ad4 Binary files /dev/null and b/entry/src/main/resources/base/media/img_003.jpg differ diff --git a/entry/src/main/resources/base/media/img_004.png b/entry/src/main/resources/base/media/img_004.png new file mode 100644 index 0000000000000000000000000000000000000000..228eae4061a5396701cabe86e653f8e00184b331 Binary files /dev/null and b/entry/src/main/resources/base/media/img_004.png differ diff --git a/entry/src/main/resources/base/media/img_005.png b/entry/src/main/resources/base/media/img_005.png new file mode 100644 index 0000000000000000000000000000000000000000..eba78b22bc2f381c5e6a820b90ce02ccd8f9989a Binary files /dev/null and b/entry/src/main/resources/base/media/img_005.png differ diff --git a/entry/src/main/resources/base/media/img_006.png b/entry/src/main/resources/base/media/img_006.png new file mode 100644 index 0000000000000000000000000000000000000000..bfeabd2ca03f968e71395ef18af5aa7f3f8a34ee Binary files /dev/null and b/entry/src/main/resources/base/media/img_006.png differ diff --git a/entry/src/main/resources/base/media/img_007.png b/entry/src/main/resources/base/media/img_007.png new file mode 100644 index 0000000000000000000000000000000000000000..c985943180092ccd55c46e249cb3622ba0962c01 Binary files /dev/null and b/entry/src/main/resources/base/media/img_007.png differ diff --git a/entry/src/main/resources/base/media/img_008.png b/entry/src/main/resources/base/media/img_008.png new file mode 100644 index 0000000000000000000000000000000000000000..3d38b16f23e47a5c38b3995d08eb6feb98082f9c Binary files /dev/null and b/entry/src/main/resources/base/media/img_008.png differ diff --git a/entry/src/main/resources/base/media/img_009.png b/entry/src/main/resources/base/media/img_009.png new file mode 100644 index 0000000000000000000000000000000000000000..8e713ab98543f8dfe978020d1a1462351f0190d3 Binary files /dev/null and b/entry/src/main/resources/base/media/img_009.png differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/entry/src/main/resources/base/media/preview_img_004.png b/entry/src/main/resources/base/media/preview_img_004.png new file mode 100644 index 0000000000000000000000000000000000000000..fea3e1d62a961cb925bd2002626d7aa4049e890f Binary files /dev/null and b/entry/src/main/resources/base/media/preview_img_004.png differ diff --git a/entry/src/main/resources/base/media/preview_img_005.png b/entry/src/main/resources/base/media/preview_img_005.png new file mode 100644 index 0000000000000000000000000000000000000000..81393b35277718afdfb6cae59f328dd2af9f91a3 Binary files /dev/null and b/entry/src/main/resources/base/media/preview_img_005.png differ diff --git a/entry/src/main/resources/base/media/preview_img_006.png b/entry/src/main/resources/base/media/preview_img_006.png new file mode 100644 index 0000000000000000000000000000000000000000..9dae857bbc41570c2f2ecf8165ac1c7a425e7f36 Binary files /dev/null and b/entry/src/main/resources/base/media/preview_img_006.png differ diff --git a/entry/src/main/resources/base/media/preview_img_007.png b/entry/src/main/resources/base/media/preview_img_007.png new file mode 100644 index 0000000000000000000000000000000000000000..70ca43e079de03b2f8956605256fd98e5951cee0 Binary files /dev/null and b/entry/src/main/resources/base/media/preview_img_007.png differ diff --git a/entry/src/main/resources/base/media/preview_img_008.png b/entry/src/main/resources/base/media/preview_img_008.png new file mode 100644 index 0000000000000000000000000000000000000000..acd8688bb75d610d5cd7314544669feb539fbd40 Binary files /dev/null and b/entry/src/main/resources/base/media/preview_img_008.png differ diff --git a/entry/src/main/resources/base/media/preview_img_009.png b/entry/src/main/resources/base/media/preview_img_009.png new file mode 100644 index 0000000000000000000000000000000000000000..8d058b59620789d7aa6183471fc128ee089bf93a Binary files /dev/null and b/entry/src/main/resources/base/media/preview_img_009.png differ diff --git a/entry/src/main/resources/base/media/startIcon.png b/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/entry/src/main/resources/base/media/startIcon.png differ diff --git a/entry/src/main/resources/base/profile/backup_config.json b/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/entry/src/main/resources/base/profile/route_map.json b/entry/src/main/resources/base/profile/route_map.json new file mode 100644 index 0000000000000000000000000000000000000000..6ddd14126501349ca275441484c18f30b3177269 --- /dev/null +++ b/entry/src/main/resources/base/profile/route_map.json @@ -0,0 +1,9 @@ +{ + "routerMap": [ + { + "name": "ImageGenerate", + "pageSourceFile": "src/main/ets/pages/ImageGenerate.ets", + "buildFunction": "ImageGeneratePageBuilder" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/dark/element/color.json b/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..837af6c3d1ace58d4a2637a63d6dc6c62f0220e1 --- /dev/null +++ b/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,71 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Image Segmentation and Composition" + }, + { + "name": "home_btn_text", + "value": "Image compositing" + }, + { + "name": "home_navbar_title", + "value": "Image Segmentation" + }, + { + "name": "image_page_navbar_title", + "value": "Image composition" + }, + { + "name": "segment_btn_text_first", + "value": "origin" + }, + { + "name":"segment_btn_text_second", + "value": "generate" + }, + { + "name": "preview_img_list_001", + "value": "default" + }, + { + "name": "preview_img_list_002", + "value": "blue" + }, + { + "name": "preview_img_list_003", + "value": "red" + }, + { + "name": "preview_img_list_004", + "value": "bg1" + }, + { + "name": "preview_img_list_005", + "value": "bg2" + }, + { + "name": "preview_img_list_006", + "value": "bg3" + }, + { + "name": "preview_img_list_007", + "value": "bg4" + }, + { + "name": "preview_img_list_008", + "value": "bg5" + }, + { + "name": "preview_img_list_009", + "value": "bg6" + }] +} \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/model_float32.ms b/entry/src/main/resources/rawfile/model_float32.ms new file mode 100644 index 0000000000000000000000000000000000000000..46bab9d013e28b32d8bddbed5ced71ac11ad8761 Binary files /dev/null and b/entry/src/main/resources/rawfile/model_float32.ms differ diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..962283f3b0f9216540c8c0bee443db6f25c34e50 --- /dev/null +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,71 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "图像分割合成" + }, + { + "name": "home_btn_text", + "value": "图像合成" + }, + { + "name": "home_navbar_title", + "value": "图像分割" + }, + { + "name": "image_page_navbar_title", + "value": "图像合成" + }, + { + "name": "segment_btn_text_first", + "value": "原图" + }, + { + "name":"segment_btn_text_second", + "value": "合成" + }, + { + "name": "preview_img_list_001", + "value": "默认" + }, + { + "name": "preview_img_list_002", + "value": "蓝色" + }, + { + "name": "preview_img_list_003", + "value": "红色" + }, + { + "name": "preview_img_list_004", + "value": "背景1" + }, + { + "name": "preview_img_list_005", + "value": "背景2" + }, + { + "name": "preview_img_list_006", + "value": "背景3" + }, + { + "name": "preview_img_list_007", + "value": "背景4" + }, + { + "name": "preview_img_list_008", + "value": "背景5" + }, + { + "name": "preview_img_list_009", + "value": "背景6" + }] +} \ No newline at end of file diff --git a/entry/src/main/syscap.json b/entry/src/main/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..a06b879c847884ea6d53fcd2f98f87832dc987fa --- /dev/null +++ b/entry/src/main/syscap.json @@ -0,0 +1,12 @@ +{ + "devices": { + "general": [ + "phone" + ] + }, + "development": { + "addedSysCaps": [ + "SystemCapability.Ai.MindSpore" + ] + } +} \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..85e8d4b2175fc4747650344f025e7d145bc3d361 --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.1.0", + "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/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..47113e2e36ecefde41c136272a0bd6ff745cffe4 --- /dev/null +++ b/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/oh-package-lock.json5 b/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a3925056904d5e0d6791438feddebc0014a84db0 --- /dev/null +++ b/oh-package-lock.json5 @@ -0,0 +1,28 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.21": { + "name": "@ohos/hypium", + "version": "1.0.21", + "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.21.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bbe95ba9e19d532fed390c3cc9a0de085c7da773 --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.1.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/screenshots/Timing_digram.PNG b/screenshots/Timing_digram.PNG new file mode 100644 index 0000000000000000000000000000000000000000..addd015d1dcaed7aad869380c6422a1ff272a585 Binary files /dev/null and b/screenshots/Timing_digram.PNG differ diff --git a/screenshots/device/screenshot_001.png b/screenshots/device/screenshot_001.png new file mode 100644 index 0000000000000000000000000000000000000000..135625698226a15a5838e6529551009c4380b463 Binary files /dev/null and b/screenshots/device/screenshot_001.png differ diff --git a/screenshots/device/screenshot_002.png b/screenshots/device/screenshot_002.png new file mode 100644 index 0000000000000000000000000000000000000000..d07a0554e1d13b7a362322911548c1ed0b2b1b36 Binary files /dev/null and b/screenshots/device/screenshot_002.png differ diff --git a/screenshots/device/screenshot_003.png b/screenshots/device/screenshot_003.png new file mode 100644 index 0000000000000000000000000000000000000000..aaf692ea06d20cc4d7cc7d94de0611da89483f6f Binary files /dev/null and b/screenshots/device/screenshot_003.png differ diff --git a/screenshots/device/screenshot_004.png b/screenshots/device/screenshot_004.png new file mode 100644 index 0000000000000000000000000000000000000000..2ce7a3396672efc576170486d314baa2b14a75c0 Binary files /dev/null and b/screenshots/device/screenshot_004.png differ