@pixzle/core 0.0.28 → 0.0.29
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 +19 -0
- package/dist/block-utils.js +29 -8
- package/dist/block-utils.js.map +1 -1
- package/package.json +1 -1
package/dist/block-utils.d.ts
CHANGED
|
@@ -32,6 +32,14 @@ export declare function calculateBlockRange(blockCounts: number[], targetIndex:
|
|
|
32
32
|
* @returns Array of block counts for each fragment
|
|
33
33
|
*/
|
|
34
34
|
export declare function calculateBlockCountsForCrossImages(totalBlocks: number, fragmentCount: number): number[];
|
|
35
|
+
/**
|
|
36
|
+
* Calculate expected block count for a single image
|
|
37
|
+
* @param width Image width
|
|
38
|
+
* @param height Image height
|
|
39
|
+
* @param blockSize Block size
|
|
40
|
+
* @returns Total block count (blockCountX * blockCountY)
|
|
41
|
+
*/
|
|
42
|
+
export declare function calculateExpectedBlockCount(width: number, height: number, blockSize: number): number;
|
|
35
43
|
/**
|
|
36
44
|
* Calculate block counts for each image
|
|
37
45
|
* @param images Array of ImageInfo objects
|
|
@@ -46,3 +54,14 @@ export declare function calculateBlockCountsPerImage(images: ImageInfo[], blockS
|
|
|
46
54
|
* @returns Total block count
|
|
47
55
|
*/
|
|
48
56
|
export declare function calculateTotalBlocks(images: ImageInfo[], blockSize: number): number;
|
|
57
|
+
/**
|
|
58
|
+
* Extract expected number of blocks from an array of blocks
|
|
59
|
+
* This is useful when restoring images from fragment images that may have
|
|
60
|
+
* extra padding blocks due to their square-ish layout
|
|
61
|
+
* @param blocks Array of blocks from the fragment image
|
|
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
|
|
66
|
+
*/
|
|
67
|
+
export declare function extractExpectedBlocks<T>(blocks: T[], width: number, height: number, blockSize: number): T[];
|
package/dist/block-utils.js
CHANGED
|
@@ -4,8 +4,10 @@ exports.RGBA_CHANNELS = void 0;
|
|
|
4
4
|
exports.calculateBlockCounts = calculateBlockCounts;
|
|
5
5
|
exports.calculateBlockRange = calculateBlockRange;
|
|
6
6
|
exports.calculateBlockCountsForCrossImages = calculateBlockCountsForCrossImages;
|
|
7
|
+
exports.calculateExpectedBlockCount = calculateExpectedBlockCount;
|
|
7
8
|
exports.calculateBlockCountsPerImage = calculateBlockCountsPerImage;
|
|
8
9
|
exports.calculateTotalBlocks = calculateTotalBlocks;
|
|
10
|
+
exports.extractExpectedBlocks = extractExpectedBlocks;
|
|
9
11
|
/**
|
|
10
12
|
* Number of channels in RGBA format
|
|
11
13
|
*/
|
|
@@ -67,6 +69,17 @@ function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
|
67
69
|
}
|
|
68
70
|
return fragmentBlockCounts;
|
|
69
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Calculate expected block count for a single image
|
|
74
|
+
* @param width Image width
|
|
75
|
+
* @param height Image height
|
|
76
|
+
* @param blockSize Block size
|
|
77
|
+
* @returns Total block count (blockCountX * blockCountY)
|
|
78
|
+
*/
|
|
79
|
+
function calculateExpectedBlockCount(width, height, blockSize) {
|
|
80
|
+
const { blockCountX, blockCountY } = calculateBlockCounts(width, height, blockSize);
|
|
81
|
+
return blockCountX * blockCountY;
|
|
82
|
+
}
|
|
70
83
|
/**
|
|
71
84
|
* Calculate block counts for each image
|
|
72
85
|
* @param images Array of ImageInfo objects
|
|
@@ -74,10 +87,7 @@ function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
|
74
87
|
* @returns Array of block counts per image (x * y)
|
|
75
88
|
*/
|
|
76
89
|
function calculateBlockCountsPerImage(images, blockSize) {
|
|
77
|
-
return images.map((info) =>
|
|
78
|
-
const { blockCountX, blockCountY } = calculateBlockCounts(info.w, info.h, blockSize);
|
|
79
|
-
return blockCountX * blockCountY;
|
|
80
|
-
});
|
|
90
|
+
return images.map((info) => calculateExpectedBlockCount(info.w, info.h, blockSize));
|
|
81
91
|
}
|
|
82
92
|
/**
|
|
83
93
|
* Calculate total number of blocks from images
|
|
@@ -86,9 +96,20 @@ function calculateBlockCountsPerImage(images, blockSize) {
|
|
|
86
96
|
* @returns Total block count
|
|
87
97
|
*/
|
|
88
98
|
function calculateTotalBlocks(images, blockSize) {
|
|
89
|
-
return images.reduce((total, image) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
return images.reduce((total, image) => total + calculateExpectedBlockCount(image.w, image.h, blockSize), 0);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Extract expected number of blocks from an array of blocks
|
|
103
|
+
* This is useful when restoring images from fragment images that may have
|
|
104
|
+
* extra padding blocks due to their square-ish layout
|
|
105
|
+
* @param blocks Array of blocks from the fragment image
|
|
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
|
|
110
|
+
*/
|
|
111
|
+
function extractExpectedBlocks(blocks, width, height, blockSize) {
|
|
112
|
+
const expectedCount = calculateExpectedBlockCount(width, height, blockSize);
|
|
113
|
+
return blocks.slice(0, expectedCount);
|
|
93
114
|
}
|
|
94
115
|
//# 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;AAQD,
|
|
1
|
+
{"version":3,"file":"block-utils.js","sourceRoot":"","sources":["../src/block-utils.ts"],"names":[],"mappings":";;;AAmBA,oDASC;AAQD,kDAUC;AAQD,gFAmCC;AASD,kEAWC;AAQD,oEAOC;AAQD,oDASC;AAYD,sDAQC;AA/JD;;GAEG;AACU,QAAA,aAAa,GAAG,CAAC,CAAC;AAO/B;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAClC,KAAa,EAC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