Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.6.1 save image data #12503

Merged
merged 14 commits into from
Aug 24, 2022
Merged

V3.6.1 save image data #12503

merged 14 commits into from
Aug 24, 2022

Conversation

timlyeee
Copy link
Contributor

@timlyeee timlyeee commented Aug 22, 2022

Re: #https://github.com/cocos/3d-tasks/issues/9274

Changelog

  • Add interface on native to save raw image data as png or jpeg

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@github-actions
Copy link

github-actions bot commented Aug 22, 2022

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -30053,8 +30053,41 @@
          * @en Trigger garbage collection of ScriptEngine @zh 触发 ScriptEngine 的 GC
          */
         function garbageCollect(): void;
         /**
+         * @en Save the image to the path indicated.
+         * @zh 保存图片到指定路径。
+         * @param data : @en the image data, should be raw data array with uint8 @zh 图片数据, 应为原始数据数组,uint8 格式。
+         * @param path : @en the path to save @zh 保存路径
+         * @param width : @en the width of the image @zh 图片宽度
+         * @param height : @en the height of the image @zh 图片高度
+         * @param filePath : @en the file path of the image @zh 图片文件路径
+         * @param callback : @en the callback function @zh 回调函数
+         * @example
+         * ```ts
+                    let renderTexture = new RenderTexture();
+                    let renderWindowInfo = {
+                    width: this._width,
+                    height: this._height
+                    };
+                    renderTexture.reset(renderWindowInfo);
+                    cameras.forEach((camera: any) => {
+                    camera.targetTexture = renderTexture;
+                    });
+                    await this.waitForNextFrame();
+                    cameras.forEach((camera: any) => {
+                        camera.targetTexture = null;
+                    });
+                    let pixelData = renderTexture.readPixels();
+                    jsb.saveImageData(pixelData, path, width, height, filePath, (isSuccess) => {
+                        if (isSuccess) {
+                            console.log('save image success');
+                        } else {
+                            console.log('save image failed');
+                    }));
+         */
+        function saveImageData(data: Uint8Array, width: number, height: number, filePath: string): Promise<void>;
+        /**
          * @en DownloaderTask @zh 下载任务对象
          * @param requestURL @en Request download resource URL  @zh 请求下载资源的URL
          * @param storagePath @en Storage path for downloaded file @zh 下载文件存储路径
          * @param identifier  @en identifier @zh 标识符

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
ios_release PASS PASS PASS NA
Mac_debug PASS PASS PASS NA
WebMobile_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

native/cocos/bindings/manual/jsb_global.cpp Outdated Show resolved Hide resolved
native/cocos/bindings/manual/jsb_global.cpp Outdated Show resolved Hide resolved
native/cocos/bindings/manual/jsb_global.cpp Outdated Show resolved Hide resolved
native/cocos/bindings/manual/jsb_global.cpp Outdated Show resolved Hide resolved
native/cocos/bindings/manual/jsb_global.cpp Outdated Show resolved Hide resolved
native/cocos/platform/Image.cpp Outdated Show resolved Hide resolved
native/cocos/platform/Image.cpp Outdated Show resolved Hide resolved
native/cocos/platform/win32/modules/System.cpp Outdated Show resolved Hide resolved
@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
ios_release PASS PASS PASS NA
Mac_debug PASS PASS PASS NA
WebMobile_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

@timlyeee
Copy link
Contributor Author

timlyeee commented Aug 23, 2022

Right now I find there's a problem for the final API, the original API looks like below:

function saveImageData(data: Uint8Array, width: number, height: number, filePath: string, callback: (isSuccess: boolean) => void): void

But it cannot make sure that the data is unchanged while the developer might try to edit the buffer for other usage.

For that reason, I change the API return a promise to tell the developer that the data should keep the same.

function saveImageData(data: Uint8Array, width: number, height: number, filePath: string, callback: (isSuccess: boolean) => void): Promise<void>

Now the callback seems useless because the promise can be await or not depends on need.

Should I make the API like below?

function saveImageData(data: Uint8Array, width: number, height: number, filePath: string): Promise<void>

@dumganhar @PatriceJiang @minggo

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
ios_release PASS PASS PASS NA
Mac_debug PASS PASS PASS NA
WebMobile_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

@timlyeee timlyeee requested a review from minggo August 23, 2022 10:53
@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
ios_release PASS PASS PASS NA
Mac_debug PASS PASS PASS NA
WebMobile_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

@minggo
Copy link
Contributor

minggo commented Aug 24, 2022

For that reason, I change the API return a promise to tell the developer that the data should keep the same.

Why promise can make sure that the data is not changed?

@timlyeee
Copy link
Contributor Author

For that reason, I change the API return a promise to tell the developer that the data should keep the same.

Why promise can make sure that the data is not changed?

@minggo The rule to code is mean to keep the data unchanged when using Promise. Also, I'll add in documentation

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
ios_release PASS PASS PASS NA
Mac_debug PASS PASS PASS NA
WebMobile_debug PASS FAIL NA NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
ios_release PASS PASS PASS NA
Mac_debug PASS PASS PASS NA
WebMobile_debug PASS PASS PASS NA

@github-actions
Copy link

@timlyeee, Please check the result of run test cases:

Task Details

Platform build runned result crashScene FailScene
WebDesktop_release PASS PASS PASS NA
WebMobile_release PASS PASS PASS NA
Win32_release PASS PASS PASS NA
Android_debug PASS PASS PASS NA

@minggo minggo merged commit 2bd6235 into cocos:v3.6.1 Aug 24, 2022
Copy link

@seyitmakas seyitmakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seyitali

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants