@pixzle/core 0.0.29 → 0.0.30
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/dist/block-utils.d.ts +7 -11
- package/dist/block-utils.js +12 -17
- package/dist/block-utils.js.map +1 -1
- package/dist/helpers.d.ts +14 -1
- package/dist/helpers.js +25 -0
- package/dist/helpers.js.map +1 -1
- package/dist/types.d.ts +8 -8
- package/package.json +1 -1
package/dist/block-utils.d.ts
CHANGED
|
@@ -33,13 +33,13 @@ export declare function calculateBlockRange(blockCounts: number[], targetIndex:
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function calculateBlockCountsForCrossImages(totalBlocks: number, fragmentCount: number): number[];
|
|
35
35
|
/**
|
|
36
|
-
* Calculate
|
|
36
|
+
* Calculate block count for a single image
|
|
37
37
|
* @param width Image width
|
|
38
38
|
* @param height Image height
|
|
39
39
|
* @param blockSize Block size
|
|
40
40
|
* @returns Total block count (blockCountX * blockCountY)
|
|
41
41
|
*/
|
|
42
|
-
export declare function
|
|
42
|
+
export declare function calculateBlockCount(width: number, height: number, blockSize: number): number;
|
|
43
43
|
/**
|
|
44
44
|
* Calculate block counts for each image
|
|
45
45
|
* @param images Array of ImageInfo objects
|
|
@@ -55,13 +55,9 @@ export declare function calculateBlockCountsPerImage(images: ImageInfo[], blockS
|
|
|
55
55
|
*/
|
|
56
56
|
export declare function calculateTotalBlocks(images: ImageInfo[], blockSize: number): number;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
* @param width Original image width
|
|
63
|
-
* @param height Original image height
|
|
64
|
-
* @param blockSize Block size
|
|
65
|
-
* @returns Array of blocks with the expected count
|
|
58
|
+
* Take the first n blocks from an array of blocks
|
|
59
|
+
* @param blocks Array of blocks
|
|
60
|
+
* @param count Number of blocks to take
|
|
61
|
+
* @returns Array of blocks with the specified count
|
|
66
62
|
*/
|
|
67
|
-
export declare function
|
|
63
|
+
export declare function takeBlocks<T>(blocks: T[], count: number): T[];
|
package/dist/block-utils.js
CHANGED
|
@@ -4,10 +4,10 @@ exports.RGBA_CHANNELS = void 0;
|
|
|
4
4
|
exports.calculateBlockCounts = calculateBlockCounts;
|
|
5
5
|
exports.calculateBlockRange = calculateBlockRange;
|
|
6
6
|
exports.calculateBlockCountsForCrossImages = calculateBlockCountsForCrossImages;
|
|
7
|
-
exports.
|
|
7
|
+
exports.calculateBlockCount = calculateBlockCount;
|
|
8
8
|
exports.calculateBlockCountsPerImage = calculateBlockCountsPerImage;
|
|
9
9
|
exports.calculateTotalBlocks = calculateTotalBlocks;
|
|
10
|
-
exports.
|
|
10
|
+
exports.takeBlocks = takeBlocks;
|
|
11
11
|
/**
|
|
12
12
|
* Number of channels in RGBA format
|
|
13
13
|
*/
|
|
@@ -70,13 +70,13 @@ function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
|
70
70
|
return fragmentBlockCounts;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
* Calculate
|
|
73
|
+
* Calculate block count for a single image
|
|
74
74
|
* @param width Image width
|
|
75
75
|
* @param height Image height
|
|
76
76
|
* @param blockSize Block size
|
|
77
77
|
* @returns Total block count (blockCountX * blockCountY)
|
|
78
78
|
*/
|
|
79
|
-
function
|
|
79
|
+
function calculateBlockCount(width, height, blockSize) {
|
|
80
80
|
const { blockCountX, blockCountY } = calculateBlockCounts(width, height, blockSize);
|
|
81
81
|
return blockCountX * blockCountY;
|
|
82
82
|
}
|
|
@@ -87,7 +87,7 @@ function calculateExpectedBlockCount(width, height, blockSize) {
|
|
|
87
87
|
* @returns Array of block counts per image (x * y)
|
|
88
88
|
*/
|
|
89
89
|
function calculateBlockCountsPerImage(images, blockSize) {
|
|
90
|
-
return images.map((info) =>
|
|
90
|
+
return images.map((info) => calculateBlockCount(info.w, info.h, blockSize));
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Calculate total number of blocks from images
|
|
@@ -96,20 +96,15 @@ function calculateBlockCountsPerImage(images, blockSize) {
|
|
|
96
96
|
* @returns Total block count
|
|
97
97
|
*/
|
|
98
98
|
function calculateTotalBlocks(images, blockSize) {
|
|
99
|
-
return images.reduce((total, image) => total +
|
|
99
|
+
return images.reduce((total, image) => total + calculateBlockCount(image.w, image.h, blockSize), 0);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
106
|
-
* @param width Original image width
|
|
107
|
-
* @param height Original image height
|
|
108
|
-
* @param blockSize Block size
|
|
109
|
-
* @returns Array of blocks with the expected count
|
|
102
|
+
* Take the first n blocks from an array of blocks
|
|
103
|
+
* @param blocks Array of blocks
|
|
104
|
+
* @param count Number of blocks to take
|
|
105
|
+
* @returns Array of blocks with the specified count
|
|
110
106
|
*/
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
return blocks.slice(0, expectedCount);
|
|
107
|
+
function takeBlocks(blocks, count) {
|
|
108
|
+
return blocks.slice(0, count);
|
|
114
109
|
}
|
|
115
110
|
//# sourceMappingURL=block-utils.js.map
|
package/dist/block-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-utils.js","sourceRoot":"","sources":["../src/block-utils.ts"],"names":[],"mappings":";;;AAmBA,oDASC;AAQD,kDAUC;AAQD,gFAmCC;AASD,
|
|
1
|
+
{"version":3,"file":"block-utils.js","sourceRoot":"","sources":["../src/block-utils.ts"],"names":[],"mappings":";;;AAmBA,oDASC;AAQD,kDAUC;AAQD,gFAmCC;AASD,kDAWC;AAQD,oEAKC;AAQD,oDAQC;AAQD,gCAEC;AAlJD;;GAEG;AACU,QAAA,aAAa,GAAG,CAAC,CAAC;AAO/B;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAClC,KAAa,EACb,MAAc,EACd,SAAiB;IAEjB,OAAO;QACL,WAAW,EAAE,IAAI,CAAC,IAA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import type { ImageInfo, ManifestData } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Create a minimal ManifestData for single image restoration
|
|
4
|
+
* @param options - Options for the manifest
|
|
5
|
+
* @param options.blockSize - Block size used for fragmentation
|
|
6
|
+
* @param options.seed - Seed used for shuffling
|
|
7
|
+
* @param options.imageInfo - Image information (width and height)
|
|
8
|
+
* @returns ManifestData object
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSingleImageManifest(options: {
|
|
11
|
+
blockSize: number;
|
|
12
|
+
seed: number;
|
|
13
|
+
imageInfo: ImageInfo;
|
|
14
|
+
}): ManifestData;
|
|
2
15
|
/**
|
|
3
16
|
* Encode file name to base64 for safe storage (cross-platform)
|
|
4
17
|
* @param name - Original file name
|
package/dist/helpers.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSingleImageManifest = createSingleImageManifest;
|
|
3
4
|
exports.encodeFileName = encodeFileName;
|
|
4
5
|
exports.decodeFileName = decodeFileName;
|
|
5
6
|
exports.generateFileName = generateFileName;
|
|
6
7
|
exports.generateFragmentFileName = generateFragmentFileName;
|
|
7
8
|
exports.generateRestoredFileName = generateRestoredFileName;
|
|
8
9
|
exports.generateRestoredOriginalFileName = generateRestoredOriginalFileName;
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
/**
|
|
12
|
+
* Create a minimal ManifestData for single image restoration
|
|
13
|
+
* @param options - Options for the manifest
|
|
14
|
+
* @param options.blockSize - Block size used for fragmentation
|
|
15
|
+
* @param options.seed - Seed used for shuffling
|
|
16
|
+
* @param options.imageInfo - Image information (width and height)
|
|
17
|
+
* @returns ManifestData object
|
|
18
|
+
*/
|
|
19
|
+
function createSingleImageManifest(options) {
|
|
20
|
+
return {
|
|
21
|
+
id: "manual",
|
|
22
|
+
version: "0.0.0",
|
|
23
|
+
timestamp: new Date().toISOString(),
|
|
24
|
+
config: {
|
|
25
|
+
blockSize: options.blockSize,
|
|
26
|
+
seed: options.seed,
|
|
27
|
+
prefix: constants_1.DEFAULT_FRAGMENTATION_CONFIG.PREFIX,
|
|
28
|
+
preserveName: false,
|
|
29
|
+
crossImageShuffle: false,
|
|
30
|
+
},
|
|
31
|
+
images: [options.imageInfo],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
9
34
|
/**
|
|
10
35
|
* Encode file name to base64 for safe storage (cross-platform)
|
|
11
36
|
* @param name - Original file name
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;AAWA,8DAkBC;AAOD,wCAYC;AAOD,wCAQC;AAUD,4CAiBC;AAQD,4DAOC;AAQD,4DAOC;AAOD,4EAaC;AA5ID,2CAA2D;AAG3D;;;;;;;GAOG;AACH,SAAgB,yBAAyB,CAAC,OAIzC;IACC,OAAO;QACL,EAAE,EAAE,QAAQ;QACZ,OAAO,EAAE,OAAO;QAChB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM,EAAE;YACN,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,wCAA4B,CAAC,MAAM;YAC3C,YAAY,EAAE,KAAK;YACnB,iBAAiB,EAAE,KAAK;SACzB;QACD,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;KAC5B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY;IACzC,6EAA6E;IAC7E,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,2DAA2D;IAC3D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Aa,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,MAAM,QAAQ,GAAG,GAAG,MAAM,IAAI,WAAW,GAAG,cAAc,EAAE,CAAC;IAC7D,OAAO,GAAG,QAAQ,IAAI,SAAS,EAAE,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,QAAsB,EACtB,KAAa;IAEb,OAAO,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE;QACvC,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,QAAsB,EACtB,KAAa;IAEb,OAAO,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE;QACvC,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAgB,gCAAgC,CAC9C,SAAyC;IAEzC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,iFAAiF;QACjF,OAAO,GAAG,SAAS,CAAC,IAAI,MAAM,CAAC;IACjC,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export interface ShuffleOptions {
|
|
2
|
-
/** Image paths (e.g., ["image1.png", "image2.png"]) */
|
|
3
|
-
|
|
2
|
+
/** Image sources - file paths or URLs (e.g., ["image1.png", "https://example.com/image2.png"]) */
|
|
3
|
+
images: string[];
|
|
4
4
|
/** Fragmentation config */
|
|
5
5
|
config?: FragmentationConfig;
|
|
6
6
|
/** Output directory (e.g., "./output/fragments") */
|
|
7
7
|
outputDir: string;
|
|
8
8
|
}
|
|
9
9
|
export interface RestoreOptions {
|
|
10
|
-
/** Image paths (e.g., ["fragment1.png", "fragment2.png"]) */
|
|
11
|
-
|
|
12
|
-
/** Manifest path (e.g., "./
|
|
13
|
-
|
|
14
|
-
/** Manifest data object (alternative to
|
|
10
|
+
/** Image sources - file paths or URLs (e.g., ["fragment1.png", "https://example.com/fragment2.png"]) */
|
|
11
|
+
images: string[];
|
|
12
|
+
/** Manifest source - file path or URL (e.g., "./manifest.json" or "https://example.com/manifest.json") */
|
|
13
|
+
manifest?: string;
|
|
14
|
+
/** Manifest data object (alternative to manifest) */
|
|
15
15
|
manifestData?: ManifestData;
|
|
16
16
|
/** Output directory (e.g., "./output/restored") */
|
|
17
17
|
outputDir: string;
|
|
@@ -25,7 +25,7 @@ export interface FragmentationConfig {
|
|
|
25
25
|
/** Prefix for fragment files (optional, default: "img") */
|
|
26
26
|
prefix?: string;
|
|
27
27
|
/** Random seed (auto-generated if not specified) */
|
|
28
|
-
seed?: number
|
|
28
|
+
seed?: number;
|
|
29
29
|
/** Preserve original file name (optional, default: false) */
|
|
30
30
|
preserveName?: boolean;
|
|
31
31
|
/** Shuffle blocks across all images instead of within each image independently (optional, default: false) */
|