From 7c63965f75538e73051c2e587a3ce8abcbd4eaf7 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Fri, 31 Oct 2025 14:45:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat=EF=BC=9A=E4=BD=BF=E7=94=A8taskGroup?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=9B=BE=E5=83=8F=E7=BC=96=E8=BE=91=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/view/AdjustContentView.ets | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets index 5ee741cd..c3d58fb9 100644 --- a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets +++ b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets @@ -23,6 +23,8 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { CommonConstants } from '../common/constant/CommonConstants'; +const TAG = `AdjustContentView`; + @Component export default struct AdjustContentView { @State currentAdjustIndex: number = 0; @@ -184,7 +186,6 @@ struct SliderCustom { const needBrightness = this.currentAdjustData[AdjustId.BRIGHTNESS] !== CommonConstants.SLIDER_MAX; const needSaturation = this.currentAdjustData[AdjustId.SATURATION] !== CommonConstants.SLIDER_MAX; - if (needBrightness || needSaturation) { try { if (needBrightness) { @@ -196,7 +197,7 @@ struct SliderCustom { px.writeBufferToPixelsSync(buffer); } catch (err) { let error = err as BusinessError; - hilog.error(0x0000, 'testTag', `${error.code}, ${error.message}`); + hilog.error(0x0000, TAG, `${error.code}, ${error.message}`); } } @@ -206,7 +207,7 @@ struct SliderCustom { px.opacitySync(opacity); } catch (err) { let error = err as BusinessError; - hilog.error(0x0000, 'testTag', `${error.code}, ${error.message}`); + hilog.error(0x0000, TAG, `${error.code}, ${error.message}`); } } @@ -220,13 +221,13 @@ struct SliderCustom { private async execImageProcessing(buffer: ArrayBuffer, type: AdjustId, value: number): Promise { // [Start execImageProcessing] - const processParam: ImageProcessing = { value, buffer, type }; - const task = new taskpool.Task(imageProcessing, processParam); + const buffers = splitArrayBuffer(buffer, 240); + const group = splitTask(buffers, type, value); try { - return await taskpool.execute(task, taskpool.Priority.HIGH) as ArrayBuffer; + return mergeArrayBuffers(await taskpool.execute(group, taskpool.Priority.HIGH) as ArrayBuffer[]); } catch (err) { let error = err as BusinessError; - hilog.error(0x0000, 'AdjustContentView', `${error.code}, ${error.message}`); + hilog.error(0x0000, TAG, `${error.code}, ${error.message}`); return buffer; } // [End execImageProcessing] @@ -245,7 +246,7 @@ struct SliderCustom { this.pixelMap.readPixelsToBuffer(bufferArray) .then(() => { const buffers: ArrayBuffer[] = splitArrayBuffer(bufferArray, 240); - const group = splitTask(buffers, type, sliderValue, value); + const group = splitTask(buffers, type, value); // [StartExclude postProcess_start] // [Start execute_start] taskpool.execute(group, taskpool.Priority.HIGH).catch((err: BusinessError) => { @@ -325,17 +326,16 @@ export struct Dialog { * Each task processes a portion of the pixel data and adds the task to the task group. * */ -function splitTask(buffers: ArrayBuffer[], type: AdjustId, sliderValue: number, value: number): taskpool.TaskGroup { +function splitTask(buffers: ArrayBuffer[], type: AdjustId, value: number): taskpool.TaskGroup { // Creating a Task Group let group: taskpool.TaskGroup = new taskpool.TaskGroup(); for (const buffer of buffers) { try { group.addTask(imageProcessing, { // Add a task to a task group - type, - bufferArray: buffer, - sliderValue, - value + value: value, + buffer: buffer, + type: type }); } catch (err) { hilog.error(0x0000, 'AdjustContentView', 'Failed to add the task: ', JSON.stringify(err) ?? ''); @@ -360,17 +360,17 @@ interface ImageProcessing { // [Start split_buffer1] //Split the picture pixel data ArrayBuffer according to the number of tasks N. -function splitArrayBuffer(buffer: ArrayBuffer, n: number): ArrayBuffer[] { - let num = Math.floor(buffer.byteLength / n); - while (num % 4 !== 0) { - num += 1; - } +function splitArrayBuffer(buffer: ArrayBuffer, taskCount: number): ArrayBuffer[] { + const BYTES_PER_PIXEL = 4; // RGBA + const bytesPerTask = Math.floor(buffer.byteLength / taskCount / BYTES_PER_PIXEL) * BYTES_PER_PIXEL; + let result: ArrayBuffer[] = []; - for (let index = 0; index < n; index++) { - if (index === n - 1) { - result[index] = buffer.slice(index * num); + for (let i = 0; i < taskCount; i++) { + if (i === taskCount - 1) { + // The final block contains all the remaining data + result[i] = buffer.slice(i * bytesPerTask); } else { - result[index] = buffer.slice(index * num, (index + 1) * num); + result[i] = buffer.slice(i * bytesPerTask, (i + 1) * bytesPerTask); } } return result; -- Gitee From 60310343c6607a645999b5c5a3ae77c7c709dc3c Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Mon, 3 Nov 2025 09:37:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat=EF=BC=9AtaskGroup=20=E9=85=8D=E5=A5=97?= =?UTF-8?q?=20docs=20code=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/view/AdjustContentView.ets | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets index c3d58fb9..9d3b628e 100644 --- a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets +++ b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets @@ -172,7 +172,9 @@ struct SliderCustom { } // [Start handleImage] + // ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets async sliderChange(value: number, mode: SliderChangeMode) { + // [StartExclude handleImage] if ((mode === SliderChangeMode.End) && (value !== this.currentAdjustData[this.currentIndex])) { if (this.postState) { this.deviceListDialogController.open(); @@ -184,6 +186,7 @@ struct SliderCustom { let buffer = new ArrayBuffer(px.getPixelBytesNumber()); px.readPixelsToBufferSync(buffer); + // [EndExclude handleImage] const needBrightness = this.currentAdjustData[AdjustId.BRIGHTNESS] !== CommonConstants.SLIDER_MAX; const needSaturation = this.currentAdjustData[AdjustId.SATURATION] !== CommonConstants.SLIDER_MAX; if (needBrightness || needSaturation) { @@ -210,11 +213,13 @@ struct SliderCustom { hilog.error(0x0000, TAG, `${error.code}, ${error.message}`); } } + // [StartExclude handleImage] this.pixelMap = px; this.isPixelMapChange = !this.isPixelMapChange; this.deviceListDialogController.close(); this.postState = true; + // [EndExclude handleImage] } } // [End handleImage] @@ -322,6 +327,7 @@ export struct Dialog { } // [Start postProcess_start] +// [Start execImageProcessing] /** * Each task processes a portion of the pixel data and adds the task to the task group. * @@ -343,7 +349,7 @@ function splitTask(buffers: ArrayBuffer[], type: AdjustId, value: number): taskp } return group; } - +// [End execImageProcessing] // [End postProcess_start] @Concurrent -- Gitee From 8fb34a6546c31164a3c6f56ecfe58ca0e5842057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=8B=E8=83=BD=5FGorit?= Date: Mon, 3 Nov 2025 07:41:56 +0000 Subject: [PATCH 3/3] =?UTF-8?q?feat=EF=BC=9A=E8=B0=83=E6=95=B4=20docs=20co?= =?UTF-8?q?de=20=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 赋能_Gorit --- .../entry/src/main/ets/view/AdjustContentView.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets index 9d3b628e..54866176 100644 --- a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets +++ b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets @@ -224,8 +224,8 @@ struct SliderCustom { } // [End handleImage] + // [Start execImageProcessing] private async execImageProcessing(buffer: ArrayBuffer, type: AdjustId, value: number): Promise { - // [Start execImageProcessing] const buffers = splitArrayBuffer(buffer, 240); const group = splitTask(buffers, type, value); try { @@ -235,8 +235,8 @@ struct SliderCustom { hilog.error(0x0000, TAG, `${error.code}, ${error.message}`); return buffer; } - // [End execImageProcessing] } + // [End execImageProcessing] // [Start postProcess_start] // ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets -- Gitee