@pixzle/core 0.0.18 → 0.0.20
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-operations.cjs +146 -0
- package/dist/block-operations.d.cts +56 -0
- package/dist/block-operations.d.ts.map +1 -0
- package/dist/block-operations.js +20 -14
- package/dist/block-operations.js.map +1 -1
- package/dist/block-utils.cjs +86 -0
- package/dist/block-utils.d.cts +47 -0
- package/dist/block-utils.d.ts.map +1 -0
- package/dist/block-utils.js +14 -6
- package/dist/block-utils.js.map +1 -1
- package/dist/cjs/block-operations.d.ts +56 -0
- package/dist/cjs/block-operations.d.ts.map +1 -0
- package/dist/cjs/block-operations.js +146 -0
- package/dist/cjs/block-operations.js.map +1 -0
- package/dist/cjs/block-utils.d.ts +47 -0
- package/dist/cjs/block-utils.d.ts.map +1 -0
- package/dist/cjs/block-utils.js +86 -0
- package/dist/cjs/block-utils.js.map +1 -0
- package/dist/cjs/constants.d.ts +8 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +11 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/helpers.d.ts +45 -0
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +101 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +65 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/validators.d.ts +16 -0
- package/dist/cjs/validators.d.ts.map +1 -0
- package/dist/cjs/validators.js +48 -0
- package/dist/cjs/validators.js.map +1 -0
- package/dist/constants.cjs +11 -0
- package/dist/constants.d.cts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -2
- package/dist/constants.js.map +1 -1
- package/dist/esm/block-operations.d.ts +56 -0
- package/dist/esm/block-operations.d.ts.map +1 -0
- package/dist/esm/block-operations.js +140 -0
- package/dist/esm/block-operations.js.map +1 -0
- package/dist/esm/block-utils.d.ts +47 -0
- package/dist/esm/block-utils.d.ts.map +1 -0
- package/dist/esm/block-utils.js +78 -0
- package/dist/esm/block-utils.js.map +1 -0
- package/dist/esm/constants.d.ts +8 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +8 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/helpers.d.ts +45 -0
- package/dist/esm/helpers.d.ts.map +1 -0
- package/dist/esm/helpers.js +93 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +65 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validators.d.ts +16 -0
- package/dist/esm/validators.d.ts.map +1 -0
- package/dist/esm/validators.js +44 -0
- package/dist/esm/validators.js.map +1 -0
- package/dist/helpers.cjs +101 -0
- package/dist/helpers.d.cts +45 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +14 -6
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -1
- package/dist/validators.cjs +48 -0
- package/dist/validators.d.cts +16 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +8 -4
- package/dist/validators.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractBlock = extractBlock;
|
|
4
|
+
exports.placeBlock = placeBlock;
|
|
5
|
+
exports.splitImageToBlocks = splitImageToBlocks;
|
|
6
|
+
exports.blocksToImageBuffer = blocksToImageBuffer;
|
|
7
|
+
const block_utils_1 = require("./block-utils");
|
|
8
|
+
/**
|
|
9
|
+
* Extract a block from an image buffer
|
|
10
|
+
* @param buffer Source image buffer (RGBA format)
|
|
11
|
+
* @param imageWidth Image width in pixels
|
|
12
|
+
* @param imageHeight Image height in pixels (optional, defaults to calculated height)
|
|
13
|
+
* @param startX Block top-left X coordinate
|
|
14
|
+
* @param startY Block top-left Y coordinate
|
|
15
|
+
* @param blockSize Maximum block size
|
|
16
|
+
* @returns Block buffer containing pixel data
|
|
17
|
+
*/
|
|
18
|
+
function extractBlock(buffer, imageWidth, imageHeight, startX, startY, blockSize) {
|
|
19
|
+
// Calculate actual block dimensions considering image boundaries
|
|
20
|
+
const blockWidth = Math.min(blockSize, imageWidth - startX);
|
|
21
|
+
const blockHeight = imageHeight !== undefined
|
|
22
|
+
? Math.min(blockSize, imageHeight - startY)
|
|
23
|
+
: blockSize;
|
|
24
|
+
const blockData = [];
|
|
25
|
+
// Extract pixel data row by row
|
|
26
|
+
for (let y = 0; y < blockHeight; y++) {
|
|
27
|
+
for (let x = 0; x < blockWidth; x++) {
|
|
28
|
+
const pixelX = startX + x;
|
|
29
|
+
const pixelY = startY + y;
|
|
30
|
+
const pixelIndex = (pixelY * imageWidth + pixelX) * block_utils_1.RGBA_CHANNELS;
|
|
31
|
+
// Copy RGBA channels
|
|
32
|
+
for (let channel = 0; channel < block_utils_1.RGBA_CHANNELS; channel++) {
|
|
33
|
+
blockData.push(buffer[pixelIndex + channel] || 0);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return new Uint8Array(blockData);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Place block data at the specified position in the target image buffer
|
|
41
|
+
* @param targetBuffer Target image buffer to place the block into
|
|
42
|
+
* @param blockData Block data to place
|
|
43
|
+
* @param targetWidth Target image width in pixels
|
|
44
|
+
* @param destX Destination X coordinate
|
|
45
|
+
* @param destY Destination Y coordinate
|
|
46
|
+
* @param blockSize Standard block size
|
|
47
|
+
* @param blockWidth Actual block width (optional, defaults to blockSize)
|
|
48
|
+
* @param blockHeight Actual block height (optional, defaults to blockSize)
|
|
49
|
+
*/
|
|
50
|
+
function placeBlock(targetBuffer, blockData, targetWidth, destX, destY, blockSize, blockWidth, blockHeight) {
|
|
51
|
+
const actualWidth = blockWidth ?? blockSize;
|
|
52
|
+
const actualHeight = blockHeight ?? blockSize;
|
|
53
|
+
// Place pixels row by row
|
|
54
|
+
for (let y = 0; y < actualHeight; y++) {
|
|
55
|
+
for (let x = 0; x < actualWidth; x++) {
|
|
56
|
+
const sourceIndex = (y * actualWidth + x) * block_utils_1.RGBA_CHANNELS;
|
|
57
|
+
const targetIndex = ((destY + y) * targetWidth + (destX + x)) * block_utils_1.RGBA_CHANNELS;
|
|
58
|
+
// Ensure we don't write beyond buffer bounds
|
|
59
|
+
if (targetIndex + block_utils_1.RGBA_CHANNELS <= targetBuffer.length) {
|
|
60
|
+
// Copy RGBA channels
|
|
61
|
+
for (let channel = 0; channel < block_utils_1.RGBA_CHANNELS; channel++) {
|
|
62
|
+
targetBuffer[targetIndex + channel] =
|
|
63
|
+
blockData[sourceIndex + channel];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculate actual block dimensions at edge positions
|
|
71
|
+
* @param position Block position (x or y)
|
|
72
|
+
* @param blockSize Standard block size
|
|
73
|
+
* @param imageSize Image dimension (width or height)
|
|
74
|
+
* @param blockCount Total block count in that dimension
|
|
75
|
+
* @returns Actual block dimension
|
|
76
|
+
*/
|
|
77
|
+
function calculateActualBlockSize(position, blockSize, imageSize, blockCount) {
|
|
78
|
+
const isEdgeBlock = position === blockCount - 1;
|
|
79
|
+
return isEdgeBlock ? imageSize - position * blockSize : blockSize;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Calculate block dimensions considering edge cases
|
|
83
|
+
* @param position Block position
|
|
84
|
+
* @param blockSize Standard block size
|
|
85
|
+
* @param imageWidth Image width
|
|
86
|
+
* @param imageHeight Image height
|
|
87
|
+
* @param blockCounts Block counts
|
|
88
|
+
* @returns Block dimensions
|
|
89
|
+
*/
|
|
90
|
+
function calculateBlockDimensions(position, blockSize, imageWidth, imageHeight, blockCounts) {
|
|
91
|
+
return {
|
|
92
|
+
width: calculateActualBlockSize(position.x, blockSize, imageWidth, blockCounts.blockCountX),
|
|
93
|
+
height: calculateActualBlockSize(position.y, blockSize, imageHeight, blockCounts.blockCountY),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Split an RGBA image buffer into an array of blocks
|
|
98
|
+
* @param buffer Source image buffer (RGBA format)
|
|
99
|
+
* @param width Image width in pixels
|
|
100
|
+
* @param height Image height in pixels
|
|
101
|
+
* @param blockSize Block size in pixels
|
|
102
|
+
* @returns Array of block buffers
|
|
103
|
+
*/
|
|
104
|
+
function splitImageToBlocks(buffer, width, height, blockSize) {
|
|
105
|
+
const blocks = [];
|
|
106
|
+
const blockCounts = (0, block_utils_1.calculateBlockCounts)(width, height, blockSize);
|
|
107
|
+
// Process blocks row by row, left to right
|
|
108
|
+
for (let blockY = 0; blockY < blockCounts.blockCountY; blockY++) {
|
|
109
|
+
for (let blockX = 0; blockX < blockCounts.blockCountX; blockX++) {
|
|
110
|
+
const startX = blockX * blockSize;
|
|
111
|
+
const startY = blockY * blockSize;
|
|
112
|
+
const block = extractBlock(buffer, width, height, startX, startY, blockSize);
|
|
113
|
+
blocks.push(block);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return blocks;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reconstruct an RGBA image buffer from an array of blocks
|
|
120
|
+
* @param blocks Array of block buffers
|
|
121
|
+
* @param width Target image width in pixels
|
|
122
|
+
* @param height Target image height in pixels
|
|
123
|
+
* @param blockSize Block size in pixels
|
|
124
|
+
* @returns Reconstructed image buffer
|
|
125
|
+
*/
|
|
126
|
+
function blocksToImageBuffer(blocks, width, height, blockSize) {
|
|
127
|
+
const imageBuffer = new Uint8Array(width * height * block_utils_1.RGBA_CHANNELS);
|
|
128
|
+
const blockCounts = (0, block_utils_1.calculateBlockCounts)(width, height, blockSize);
|
|
129
|
+
let blockIndex = 0;
|
|
130
|
+
// Place blocks row by row, left to right
|
|
131
|
+
for (let blockY = 0; blockY < blockCounts.blockCountY; blockY++) {
|
|
132
|
+
for (let blockX = 0; blockX < blockCounts.blockCountX; blockX++) {
|
|
133
|
+
if (blockIndex >= blocks.length) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
const position = { x: blockX, y: blockY };
|
|
137
|
+
const dimensions = calculateBlockDimensions(position, blockSize, width, height, blockCounts);
|
|
138
|
+
const destX = blockX * blockSize;
|
|
139
|
+
const destY = blockY * blockSize;
|
|
140
|
+
placeBlock(imageBuffer, blocks[blockIndex], width, destX, destY, blockSize, dimensions.width, dimensions.height);
|
|
141
|
+
blockIndex++;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return imageBuffer;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=block-operations.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Position of a block in the image grid
|
|
3
|
+
*/
|
|
4
|
+
export interface BlockPosition {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Dimensions of a block
|
|
10
|
+
*/
|
|
11
|
+
export interface BlockDimensions {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extract a block from an image buffer
|
|
17
|
+
* @param buffer Source image buffer (RGBA format)
|
|
18
|
+
* @param imageWidth Image width in pixels
|
|
19
|
+
* @param imageHeight Image height in pixels (optional, defaults to calculated height)
|
|
20
|
+
* @param startX Block top-left X coordinate
|
|
21
|
+
* @param startY Block top-left Y coordinate
|
|
22
|
+
* @param blockSize Maximum block size
|
|
23
|
+
* @returns Block buffer containing pixel data
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractBlock(buffer: Uint8Array, imageWidth: number, imageHeight: number | undefined, startX: number, startY: number, blockSize: number): Uint8Array;
|
|
26
|
+
/**
|
|
27
|
+
* Place block data at the specified position in the target image buffer
|
|
28
|
+
* @param targetBuffer Target image buffer to place the block into
|
|
29
|
+
* @param blockData Block data to place
|
|
30
|
+
* @param targetWidth Target image width in pixels
|
|
31
|
+
* @param destX Destination X coordinate
|
|
32
|
+
* @param destY Destination Y coordinate
|
|
33
|
+
* @param blockSize Standard block size
|
|
34
|
+
* @param blockWidth Actual block width (optional, defaults to blockSize)
|
|
35
|
+
* @param blockHeight Actual block height (optional, defaults to blockSize)
|
|
36
|
+
*/
|
|
37
|
+
export declare function placeBlock(targetBuffer: Uint8Array, blockData: Uint8Array, targetWidth: number, destX: number, destY: number, blockSize: number, blockWidth?: number, blockHeight?: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* Split an RGBA image buffer into an array of blocks
|
|
40
|
+
* @param buffer Source image buffer (RGBA format)
|
|
41
|
+
* @param width Image width in pixels
|
|
42
|
+
* @param height Image height in pixels
|
|
43
|
+
* @param blockSize Block size in pixels
|
|
44
|
+
* @returns Array of block buffers
|
|
45
|
+
*/
|
|
46
|
+
export declare function splitImageToBlocks(buffer: Uint8Array, width: number, height: number, blockSize: number): Uint8Array[];
|
|
47
|
+
/**
|
|
48
|
+
* Reconstruct an RGBA image buffer from an array of blocks
|
|
49
|
+
* @param blocks Array of block buffers
|
|
50
|
+
* @param width Target image width in pixels
|
|
51
|
+
* @param height Target image height in pixels
|
|
52
|
+
* @param blockSize Block size in pixels
|
|
53
|
+
* @returns Reconstructed image buffer
|
|
54
|
+
*/
|
|
55
|
+
export declare function blocksToImageBuffer(blocks: Uint8Array[], width: number, height: number, blockSize: number): Uint8Array;
|
|
56
|
+
//# sourceMappingURL=block-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-operations.d.ts","sourceRoot":"","sources":["../src/block-operations.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,CAyBZ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,YAAY,EAAE,UAAU,EACxB,SAAS,EAAE,UAAU,EACrB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CAqBN;AAoDD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,EAAE,CAwBd;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAAE,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,CAyCZ"}
|
package/dist/block-operations.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractBlock = extractBlock;
|
|
4
|
+
exports.placeBlock = placeBlock;
|
|
5
|
+
exports.splitImageToBlocks = splitImageToBlocks;
|
|
6
|
+
exports.blocksToImageBuffer = blocksToImageBuffer;
|
|
7
|
+
const block_utils_1 = require("./block-utils");
|
|
2
8
|
/**
|
|
3
9
|
* Extract a block from an image buffer
|
|
4
10
|
* @param buffer Source image buffer (RGBA format)
|
|
@@ -9,7 +15,7 @@ import { RGBA_CHANNELS, calculateBlockCounts, } from "./block-utils";
|
|
|
9
15
|
* @param blockSize Maximum block size
|
|
10
16
|
* @returns Block buffer containing pixel data
|
|
11
17
|
*/
|
|
12
|
-
|
|
18
|
+
function extractBlock(buffer, imageWidth, imageHeight, startX, startY, blockSize) {
|
|
13
19
|
// Calculate actual block dimensions considering image boundaries
|
|
14
20
|
const blockWidth = Math.min(blockSize, imageWidth - startX);
|
|
15
21
|
const blockHeight = imageHeight !== undefined
|
|
@@ -21,9 +27,9 @@ export function extractBlock(buffer, imageWidth, imageHeight, startX, startY, bl
|
|
|
21
27
|
for (let x = 0; x < blockWidth; x++) {
|
|
22
28
|
const pixelX = startX + x;
|
|
23
29
|
const pixelY = startY + y;
|
|
24
|
-
const pixelIndex = (pixelY * imageWidth + pixelX) * RGBA_CHANNELS;
|
|
30
|
+
const pixelIndex = (pixelY * imageWidth + pixelX) * block_utils_1.RGBA_CHANNELS;
|
|
25
31
|
// Copy RGBA channels
|
|
26
|
-
for (let channel = 0; channel < RGBA_CHANNELS; channel++) {
|
|
32
|
+
for (let channel = 0; channel < block_utils_1.RGBA_CHANNELS; channel++) {
|
|
27
33
|
blockData.push(buffer[pixelIndex + channel] || 0);
|
|
28
34
|
}
|
|
29
35
|
}
|
|
@@ -41,18 +47,18 @@ export function extractBlock(buffer, imageWidth, imageHeight, startX, startY, bl
|
|
|
41
47
|
* @param blockWidth Actual block width (optional, defaults to blockSize)
|
|
42
48
|
* @param blockHeight Actual block height (optional, defaults to blockSize)
|
|
43
49
|
*/
|
|
44
|
-
|
|
50
|
+
function placeBlock(targetBuffer, blockData, targetWidth, destX, destY, blockSize, blockWidth, blockHeight) {
|
|
45
51
|
const actualWidth = blockWidth ?? blockSize;
|
|
46
52
|
const actualHeight = blockHeight ?? blockSize;
|
|
47
53
|
// Place pixels row by row
|
|
48
54
|
for (let y = 0; y < actualHeight; y++) {
|
|
49
55
|
for (let x = 0; x < actualWidth; x++) {
|
|
50
|
-
const sourceIndex = (y * actualWidth + x) * RGBA_CHANNELS;
|
|
51
|
-
const targetIndex = ((destY + y) * targetWidth + (destX + x)) * RGBA_CHANNELS;
|
|
56
|
+
const sourceIndex = (y * actualWidth + x) * block_utils_1.RGBA_CHANNELS;
|
|
57
|
+
const targetIndex = ((destY + y) * targetWidth + (destX + x)) * block_utils_1.RGBA_CHANNELS;
|
|
52
58
|
// Ensure we don't write beyond buffer bounds
|
|
53
|
-
if (targetIndex + RGBA_CHANNELS <= targetBuffer.length) {
|
|
59
|
+
if (targetIndex + block_utils_1.RGBA_CHANNELS <= targetBuffer.length) {
|
|
54
60
|
// Copy RGBA channels
|
|
55
|
-
for (let channel = 0; channel < RGBA_CHANNELS; channel++) {
|
|
61
|
+
for (let channel = 0; channel < block_utils_1.RGBA_CHANNELS; channel++) {
|
|
56
62
|
targetBuffer[targetIndex + channel] =
|
|
57
63
|
blockData[sourceIndex + channel];
|
|
58
64
|
}
|
|
@@ -95,9 +101,9 @@ function calculateBlockDimensions(position, blockSize, imageWidth, imageHeight,
|
|
|
95
101
|
* @param blockSize Block size in pixels
|
|
96
102
|
* @returns Array of block buffers
|
|
97
103
|
*/
|
|
98
|
-
|
|
104
|
+
function splitImageToBlocks(buffer, width, height, blockSize) {
|
|
99
105
|
const blocks = [];
|
|
100
|
-
const blockCounts = calculateBlockCounts(width, height, blockSize);
|
|
106
|
+
const blockCounts = (0, block_utils_1.calculateBlockCounts)(width, height, blockSize);
|
|
101
107
|
// Process blocks row by row, left to right
|
|
102
108
|
for (let blockY = 0; blockY < blockCounts.blockCountY; blockY++) {
|
|
103
109
|
for (let blockX = 0; blockX < blockCounts.blockCountX; blockX++) {
|
|
@@ -117,9 +123,9 @@ export function splitImageToBlocks(buffer, width, height, blockSize) {
|
|
|
117
123
|
* @param blockSize Block size in pixels
|
|
118
124
|
* @returns Reconstructed image buffer
|
|
119
125
|
*/
|
|
120
|
-
|
|
121
|
-
const imageBuffer = new Uint8Array(width * height * RGBA_CHANNELS);
|
|
122
|
-
const blockCounts = calculateBlockCounts(width, height, blockSize);
|
|
126
|
+
function blocksToImageBuffer(blocks, width, height, blockSize) {
|
|
127
|
+
const imageBuffer = new Uint8Array(width * height * block_utils_1.RGBA_CHANNELS);
|
|
128
|
+
const blockCounts = (0, block_utils_1.calculateBlockCounts)(width, height, blockSize);
|
|
123
129
|
let blockIndex = 0;
|
|
124
130
|
// Place blocks row by row, left to right
|
|
125
131
|
for (let blockY = 0; blockY < blockCounts.blockCountY; blockY++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-operations.js","sourceRoot":"","sources":["../src/block-operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block-operations.js","sourceRoot":"","sources":["../src/block-operations.ts"],"names":[],"mappings":";;AAgCA,oCAgCC;AAaD,gCA8BC;AA4DD,gDA6BC;AAUD,kDA8CC;AA5PD,+CAIuB;AAkBvB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,MAAkB,EAClB,UAAkB,EAClB,WAA+B,EAC/B,MAAc,EACd,MAAc,EACd,SAAiB;IAEjB,iEAAiE;IACjE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CA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,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;YAChE,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAChC,MAAM;YACR,CAAC;YAED,MAAM,QAAQ,GAAkB,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;YACzD,MAAM,UAAU,GAAG,wBAAwB,CACzC,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,EACN,WAAW,CACZ,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;YACjC,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;YAEjC,UAAU,CACR,WAAW,EACX,MAAM,CAAC,UAAU,CAAC,EAClB,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,UAAU,CAAC,KAAK,EAChB,UAAU,CAAC,MAAM,CAClB,CAAC;YAEF,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGBA_CHANNELS = void 0;
|
|
4
|
+
exports.calculateBlockCounts = calculateBlockCounts;
|
|
5
|
+
exports.calculateBlockRange = calculateBlockRange;
|
|
6
|
+
exports.calculateBlockCountsForCrossImages = calculateBlockCountsForCrossImages;
|
|
7
|
+
exports.calculateBlockCountsPerImage = calculateBlockCountsPerImage;
|
|
8
|
+
exports.calculateTotalBlocks = calculateTotalBlocks;
|
|
9
|
+
/**
|
|
10
|
+
* Number of channels in RGBA format
|
|
11
|
+
*/
|
|
12
|
+
exports.RGBA_CHANNELS = 4;
|
|
13
|
+
/**
|
|
14
|
+
* Calculate block counts for width and height
|
|
15
|
+
* @param width Image width
|
|
16
|
+
* @param height Image height
|
|
17
|
+
* @param blockSize Block size
|
|
18
|
+
* @returns Object with blockCountX and blockCountY
|
|
19
|
+
*/
|
|
20
|
+
function calculateBlockCounts(width, height, blockSize) {
|
|
21
|
+
return {
|
|
22
|
+
blockCountX: Math.ceil(width / blockSize),
|
|
23
|
+
blockCountY: Math.ceil(height / blockSize),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Calculate the range of blocks for a specific image index
|
|
28
|
+
* @param blockCounts Array of block counts per image
|
|
29
|
+
* @param targetIndex Target image index
|
|
30
|
+
* @returns Object with start and end indices
|
|
31
|
+
*/
|
|
32
|
+
function calculateBlockRange(blockCounts, targetIndex) {
|
|
33
|
+
const start = blockCounts
|
|
34
|
+
.slice(0, targetIndex)
|
|
35
|
+
.reduce((sum, count) => sum + count, 0);
|
|
36
|
+
const end = start + blockCounts[targetIndex];
|
|
37
|
+
return { start, end };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Calculate how many blocks each fragment should contain for cross-image shuffling
|
|
41
|
+
* @param totalBlocks Total number of blocks to distribute
|
|
42
|
+
* @param fragmentCount Number of fragments to create
|
|
43
|
+
* @returns Array of block counts for each fragment
|
|
44
|
+
*/
|
|
45
|
+
function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
46
|
+
if (fragmentCount <= 0) {
|
|
47
|
+
throw new Error("Fragment count must be greater than 0");
|
|
48
|
+
}
|
|
49
|
+
if (totalBlocks <= 0) {
|
|
50
|
+
return new Array(fragmentCount).fill(0);
|
|
51
|
+
}
|
|
52
|
+
const baseBlocksPerFragment = Math.ceil(totalBlocks / fragmentCount);
|
|
53
|
+
const fragmentBlockCounts = [];
|
|
54
|
+
let remainingBlocks = totalBlocks;
|
|
55
|
+
// Distribute blocks, ensuring no fragment gets more blocks than available
|
|
56
|
+
for (let i = 0; i < fragmentCount; i++) {
|
|
57
|
+
const blocksForThisFragment = Math.min(baseBlocksPerFragment, remainingBlocks);
|
|
58
|
+
fragmentBlockCounts.push(blocksForThisFragment);
|
|
59
|
+
remainingBlocks -= blocksForThisFragment;
|
|
60
|
+
// If no blocks remain, fill remaining fragments with 0
|
|
61
|
+
if (remainingBlocks <= 0) {
|
|
62
|
+
for (let j = i + 1; j < fragmentCount; j++) {
|
|
63
|
+
fragmentBlockCounts.push(0);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return fragmentBlockCounts;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Calculate block counts for each image
|
|
72
|
+
* @param images Array of ImageInfo objects
|
|
73
|
+
* @returns Array of block counts per image (x * y)
|
|
74
|
+
*/
|
|
75
|
+
function calculateBlockCountsPerImage(images) {
|
|
76
|
+
return images.map((info) => info.x * info.y);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Calculate total number of blocks from images
|
|
80
|
+
* @param images Array of ImageInfo objects
|
|
81
|
+
* @returns Total block count
|
|
82
|
+
*/
|
|
83
|
+
function calculateTotalBlocks(images) {
|
|
84
|
+
return images.reduce((total, image) => total + image.x * image.y, 0);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=block-utils.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ImageInfo } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Number of channels in RGBA format
|
|
4
|
+
*/
|
|
5
|
+
export declare const RGBA_CHANNELS = 4;
|
|
6
|
+
export interface BlockCounts {
|
|
7
|
+
blockCountX: number;
|
|
8
|
+
blockCountY: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Calculate block counts for width and height
|
|
12
|
+
* @param width Image width
|
|
13
|
+
* @param height Image height
|
|
14
|
+
* @param blockSize Block size
|
|
15
|
+
* @returns Object with blockCountX and blockCountY
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculateBlockCounts(width: number, height: number, blockSize: number): BlockCounts;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the range of blocks for a specific image index
|
|
20
|
+
* @param blockCounts Array of block counts per image
|
|
21
|
+
* @param targetIndex Target image index
|
|
22
|
+
* @returns Object with start and end indices
|
|
23
|
+
*/
|
|
24
|
+
export declare function calculateBlockRange(blockCounts: number[], targetIndex: number): {
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Calculate how many blocks each fragment should contain for cross-image shuffling
|
|
30
|
+
* @param totalBlocks Total number of blocks to distribute
|
|
31
|
+
* @param fragmentCount Number of fragments to create
|
|
32
|
+
* @returns Array of block counts for each fragment
|
|
33
|
+
*/
|
|
34
|
+
export declare function calculateBlockCountsForCrossImages(totalBlocks: number, fragmentCount: number): number[];
|
|
35
|
+
/**
|
|
36
|
+
* Calculate block counts for each image
|
|
37
|
+
* @param images Array of ImageInfo objects
|
|
38
|
+
* @returns Array of block counts per image (x * y)
|
|
39
|
+
*/
|
|
40
|
+
export declare function calculateBlockCountsPerImage(images: ImageInfo[]): number[];
|
|
41
|
+
/**
|
|
42
|
+
* Calculate total number of blocks from images
|
|
43
|
+
* @param images Array of ImageInfo objects
|
|
44
|
+
* @returns Total block count
|
|
45
|
+
*/
|
|
46
|
+
export declare function calculateTotalBlocks(images: ImageInfo[]): number;
|
|
47
|
+
//# sourceMappingURL=block-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-utils.d.ts","sourceRoot":"","sources":["../src/block-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,WAAW,CAKb;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EAAE,EACrB,WAAW,EAAE,MAAM,GAClB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAOhC;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,GACpB,MAAM,EAAE,CAgCV;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAEhE"}
|
package/dist/block-utils.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGBA_CHANNELS = void 0;
|
|
4
|
+
exports.calculateBlockCounts = calculateBlockCounts;
|
|
5
|
+
exports.calculateBlockRange = calculateBlockRange;
|
|
6
|
+
exports.calculateBlockCountsForCrossImages = calculateBlockCountsForCrossImages;
|
|
7
|
+
exports.calculateBlockCountsPerImage = calculateBlockCountsPerImage;
|
|
8
|
+
exports.calculateTotalBlocks = calculateTotalBlocks;
|
|
1
9
|
/**
|
|
2
10
|
* Number of channels in RGBA format
|
|
3
11
|
*/
|
|
4
|
-
|
|
12
|
+
exports.RGBA_CHANNELS = 4;
|
|
5
13
|
/**
|
|
6
14
|
* Calculate block counts for width and height
|
|
7
15
|
* @param width Image width
|
|
@@ -9,7 +17,7 @@ export const RGBA_CHANNELS = 4;
|
|
|
9
17
|
* @param blockSize Block size
|
|
10
18
|
* @returns Object with blockCountX and blockCountY
|
|
11
19
|
*/
|
|
12
|
-
|
|
20
|
+
function calculateBlockCounts(width, height, blockSize) {
|
|
13
21
|
return {
|
|
14
22
|
blockCountX: Math.ceil(width / blockSize),
|
|
15
23
|
blockCountY: Math.ceil(height / blockSize),
|
|
@@ -21,7 +29,7 @@ export function calculateBlockCounts(width, height, blockSize) {
|
|
|
21
29
|
* @param targetIndex Target image index
|
|
22
30
|
* @returns Object with start and end indices
|
|
23
31
|
*/
|
|
24
|
-
|
|
32
|
+
function calculateBlockRange(blockCounts, targetIndex) {
|
|
25
33
|
const start = blockCounts
|
|
26
34
|
.slice(0, targetIndex)
|
|
27
35
|
.reduce((sum, count) => sum + count, 0);
|
|
@@ -34,7 +42,7 @@ export function calculateBlockRange(blockCounts, targetIndex) {
|
|
|
34
42
|
* @param fragmentCount Number of fragments to create
|
|
35
43
|
* @returns Array of block counts for each fragment
|
|
36
44
|
*/
|
|
37
|
-
|
|
45
|
+
function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
38
46
|
if (fragmentCount <= 0) {
|
|
39
47
|
throw new Error("Fragment count must be greater than 0");
|
|
40
48
|
}
|
|
@@ -64,7 +72,7 @@ export function calculateBlockCountsForCrossImages(totalBlocks, fragmentCount) {
|
|
|
64
72
|
* @param images Array of ImageInfo objects
|
|
65
73
|
* @returns Array of block counts per image (x * y)
|
|
66
74
|
*/
|
|
67
|
-
|
|
75
|
+
function calculateBlockCountsPerImage(images) {
|
|
68
76
|
return images.map((info) => info.x * info.y);
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
@@ -72,7 +80,7 @@ export function calculateBlockCountsPerImage(images) {
|
|
|
72
80
|
* @param images Array of ImageInfo objects
|
|
73
81
|
* @returns Total block count
|
|
74
82
|
*/
|
|
75
|
-
|
|
83
|
+
function calculateTotalBlocks(images) {
|
|
76
84
|
return images.reduce((total, image) => total + image.x * image.y, 0);
|
|
77
85
|
}
|
|
78
86
|
//# 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":[],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|
+
export interface BlockDimensions {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extract a block from an image buffer
|
|
17
|
+
* @param buffer Source image buffer (RGBA format)
|
|
18
|
+
* @param imageWidth Image width in pixels
|
|
19
|
+
* @param imageHeight Image height in pixels (optional, defaults to calculated height)
|
|
20
|
+
* @param startX Block top-left X coordinate
|
|
21
|
+
* @param startY Block top-left Y coordinate
|
|
22
|
+
* @param blockSize Maximum block size
|
|
23
|
+
* @returns Block buffer containing pixel data
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractBlock(buffer: Uint8Array, imageWidth: number, imageHeight: number | undefined, startX: number, startY: number, blockSize: number): Uint8Array;
|
|
26
|
+
/**
|
|
27
|
+
* Place block data at the specified position in the target image buffer
|
|
28
|
+
* @param targetBuffer Target image buffer to place the block into
|
|
29
|
+
* @param blockData Block data to place
|
|
30
|
+
* @param targetWidth Target image width in pixels
|
|
31
|
+
* @param destX Destination X coordinate
|
|
32
|
+
* @param destY Destination Y coordinate
|
|
33
|
+
* @param blockSize Standard block size
|
|
34
|
+
* @param blockWidth Actual block width (optional, defaults to blockSize)
|
|
35
|
+
* @param blockHeight Actual block height (optional, defaults to blockSize)
|
|
36
|
+
*/
|
|
37
|
+
export declare function placeBlock(targetBuffer: Uint8Array, blockData: Uint8Array, targetWidth: number, destX: number, destY: number, blockSize: number, blockWidth?: number, blockHeight?: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* Split an RGBA image buffer into an array of blocks
|
|
40
|
+
* @param buffer Source image buffer (RGBA format)
|
|
41
|
+
* @param width Image width in pixels
|
|
42
|
+
* @param height Image height in pixels
|
|
43
|
+
* @param blockSize Block size in pixels
|
|
44
|
+
* @returns Array of block buffers
|
|
45
|
+
*/
|
|
46
|
+
export declare function splitImageToBlocks(buffer: Uint8Array, width: number, height: number, blockSize: number): Uint8Array[];
|
|
47
|
+
/**
|
|
48
|
+
* Reconstruct an RGBA image buffer from an array of blocks
|
|
49
|
+
* @param blocks Array of block buffers
|
|
50
|
+
* @param width Target image width in pixels
|
|
51
|
+
* @param height Target image height in pixels
|
|
52
|
+
* @param blockSize Block size in pixels
|
|
53
|
+
* @returns Reconstructed image buffer
|
|
54
|
+
*/
|
|
55
|
+
export declare function blocksToImageBuffer(blocks: Uint8Array[], width: number, height: number, blockSize: number): Uint8Array;
|
|
56
|
+
//# sourceMappingURL=block-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-operations.d.ts","sourceRoot":"","sources":["../../src/block-operations.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,CAyBZ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,YAAY,EAAE,UAAU,EACxB,SAAS,EAAE,UAAU,EACrB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CAqBN;AAoDD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,EAAE,CAwBd;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAAE,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,UAAU,CAyCZ"}
|