Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Commit f402390

Browse files
committed
encrypt, decrypt を promise
1 parent 4f1be8b commit f402390

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

workspaces/image-encrypt/src/decrypt.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ export async function decrypt({
1818
const rowOffsetPixel = Math.floor((sourceImageInfo.width % COLUMN_SIZE) / 2);
1919
const rowPixel = Math.floor(sourceImageInfo.height / ROW_SIZE);
2020

21-
exportCanvasContext.drawImage(sourceImage, 0, 0);
22-
23-
for (const { from, to } of MAPPING) {
24-
const srcX = columnOffsetPixel + from.column * columnPixel;
25-
const srcY = rowOffsetPixel + from.row * rowPixel;
26-
const destX = columnOffsetPixel + to.column * columnPixel;
27-
const destY = rowOffsetPixel + to.row * rowPixel;
28-
exportCanvasContext.drawImage(sourceImage, srcX, srcY, columnPixel, rowPixel, destX, destY, columnPixel, rowPixel);
29-
}
21+
await Promise.all(
22+
MAPPING.map(async ({ from, to }) => {
23+
await new Promise<void>((resolve) => {
24+
const srcX = columnOffsetPixel + from.column * columnPixel;
25+
const srcY = rowOffsetPixel + from.row * rowPixel;
26+
const destX = columnOffsetPixel + to.column * columnPixel;
27+
const destY = rowOffsetPixel + to.row * rowPixel;
28+
exportCanvasContext.drawImage(
29+
sourceImage,
30+
srcX,
31+
srcY,
32+
columnPixel,
33+
rowPixel,
34+
destX,
35+
destY,
36+
columnPixel,
37+
rowPixel,
38+
);
39+
resolve();
40+
});
41+
}),
42+
);
3043
}

workspaces/image-encrypt/src/encrypt.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ export async function encrypt({
1818
const rowOffsetPixel = Math.floor((sourceImageInfo.width % COLUMN_SIZE) / 2);
1919
const rowPixel = Math.floor(sourceImageInfo.height / ROW_SIZE);
2020

21-
exportCanvasContext.drawImage(sourceImage, 0, 0);
22-
23-
for (const { from, to } of MAPPING) {
24-
const srcX = columnOffsetPixel + to.column * columnPixel;
25-
const srcY = rowOffsetPixel + to.row * rowPixel;
26-
const destX = columnOffsetPixel + from.column * columnPixel;
27-
const destY = rowOffsetPixel + from.row * rowPixel;
28-
exportCanvasContext.drawImage(sourceImage, srcX, srcY, columnPixel, rowPixel, destX, destY, columnPixel, rowPixel);
29-
}
21+
await Promise.all(
22+
MAPPING.map(async ({ from, to }) => {
23+
await new Promise<void>((resolve) => {
24+
const srcX = columnOffsetPixel + to.column * columnPixel;
25+
const srcY = rowOffsetPixel + to.row * rowPixel;
26+
const destX = columnOffsetPixel + from.column * columnPixel;
27+
const destY = rowOffsetPixel + from.row * rowPixel;
28+
exportCanvasContext.drawImage(
29+
sourceImage,
30+
srcX,
31+
srcY,
32+
columnPixel,
33+
rowPixel,
34+
destX,
35+
destY,
36+
columnPixel,
37+
rowPixel,
38+
);
39+
resolve();
40+
});
41+
}),
42+
);
3043
}

0 commit comments

Comments
 (0)