@pixzle/browser 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -21
- package/dist/block.js +13 -3
- package/dist/block.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,27 +10,6 @@ npm i @pixzle/browser
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
### Restore multiple images
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import pixzle from '@pixzle/browser';
|
|
17
|
-
|
|
18
|
-
const restoredBitmaps = await pixzle.restore({
|
|
19
|
-
images: ['https://example.com/fragment1.png', 'https://example.com/fragment2.png'],
|
|
20
|
-
manifest: 'https://example.com/manifest.json',
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Draw each restored image to canvas
|
|
24
|
-
restoredBitmaps.forEach((bitmap) => {
|
|
25
|
-
const canvas = document.createElement('canvas');
|
|
26
|
-
canvas.width = bitmap.width;
|
|
27
|
-
canvas.height = bitmap.height;
|
|
28
|
-
const ctx = canvas.getContext('2d');
|
|
29
|
-
ctx.drawImage(bitmap, 0, 0);
|
|
30
|
-
document.body.appendChild(canvas);
|
|
31
|
-
});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
13
|
### Restore a single image
|
|
35
14
|
|
|
36
15
|
```typescript
|
|
@@ -52,3 +31,24 @@ canvas.height = restoredBitmap.height;
|
|
|
52
31
|
const ctx = canvas.getContext('2d');
|
|
53
32
|
ctx.drawImage(restoredBitmap, 0, 0);
|
|
54
33
|
```
|
|
34
|
+
|
|
35
|
+
### Restore multiple images
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import pixzle from '@pixzle/browser';
|
|
39
|
+
|
|
40
|
+
const restoredBitmaps = await pixzle.restore({
|
|
41
|
+
images: ['https://example.com/fragment1.png', 'https://example.com/fragment2.png'],
|
|
42
|
+
manifest: 'https://example.com/manifest.json',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Draw each restored image to canvas
|
|
46
|
+
restoredBitmaps.forEach((bitmap) => {
|
|
47
|
+
const canvas = document.createElement('canvas');
|
|
48
|
+
canvas.width = bitmap.width;
|
|
49
|
+
canvas.height = bitmap.height;
|
|
50
|
+
const ctx = canvas.getContext('2d');
|
|
51
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
52
|
+
document.body.appendChild(canvas);
|
|
53
|
+
});
|
|
54
|
+
```
|
package/dist/block.js
CHANGED
|
@@ -43,14 +43,24 @@ async function blocksToImageBitmap(blocks, width, height, blockSize) {
|
|
|
43
43
|
* @returns Processed blocks
|
|
44
44
|
*/
|
|
45
45
|
function blocksPerImage(allBlocks, fragmentBlocksCount, seed, processFunc) {
|
|
46
|
-
|
|
46
|
+
// Pre-allocate array to avoid resizing and stack overflow issues with push(...processed)
|
|
47
|
+
const processedBlocks = new Array(allBlocks.length);
|
|
48
|
+
let globalOffset = 0;
|
|
47
49
|
let offset = 0;
|
|
48
50
|
for (const blockCount of fragmentBlocksCount) {
|
|
49
51
|
const imageBlocks = allBlocks.slice(offset, offset + blockCount);
|
|
50
52
|
const processed = processFunc(imageBlocks, seed);
|
|
51
|
-
|
|
53
|
+
// Copy processed blocks to the result array one by one to avoid stack overflow
|
|
54
|
+
for (let i = 0; i < processed.length; i++) {
|
|
55
|
+
processedBlocks[globalOffset + i] = processed[i];
|
|
56
|
+
}
|
|
57
|
+
globalOffset += processed.length;
|
|
52
58
|
offset += blockCount;
|
|
53
59
|
}
|
|
54
|
-
return
|
|
60
|
+
// If the total size matches, return as is. Otherwise slice (safety check)
|
|
61
|
+
if (globalOffset === processedBlocks.length) {
|
|
62
|
+
return processedBlocks;
|
|
63
|
+
}
|
|
64
|
+
return processedBlocks.slice(0, globalOffset);
|
|
55
65
|
}
|
|
56
66
|
//# sourceMappingURL=block.js.map
|
package/dist/block.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":";;AAQA,gDA6BC;AAKD,kDAoBC;AAUD,
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":";;AAQA,gDA6BC;AAKD,kDAoBC;AAUD,wCA6BC;AArGD,uCAGsB;AAEtB;;GAEG;AACH,SAAgB,kBAAkB,CAChC,KAAqC,EACrC,SAAiB;IAEjB,MAAM,KAAK,GACT,KAAK,YAAY,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACvE,MAAM,MAAM,GACV,KAAK,YAAY,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;IAEzE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAEtD,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3B,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAExD,0DAA0D;IAC1D,+FAA+F;IAC/F,0BAA0B;IAC1B,6CAA6C;IAC7C,MAAM,MAAM,GAAG,IAAI,UAAU,CAC3B,SAAS,CAAC,IAAI,CAAC,MAAM,EACrB,SAAS,CAAC,IAAI,CAAC,UAAU,EACzB,SAAS,CAAC,IAAI,CAAC,UAAU,CAC1B,CAAC;IAEF,OAAO,IAAA,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AM,IAAI,UAAU,CAAC;IACvB,CAAC;IAED,0EAA0E;IAC1E,IAAI,YAAY,KAAK,eAAe,CAAC,MAAM,EAAE,CAAC;QAC5C,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixzle/browser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Browser implementation of image fragmentation and restoration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@tuki0918/seeded-shuffle": "^1.0.0",
|
|
39
|
-
"@pixzle/core": "0.1.
|
|
39
|
+
"@pixzle/core": "0.1.6"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"happy-dom": "^20.0.11",
|