@pixzle/node 0.0.23 → 0.0.25
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/package.json +2 -2
- package/dist/block.cjs +0 -158
- package/dist/block.d.cts +0 -71
- package/dist/block.d.ts.map +0 -1
- package/dist/cjs/block.d.ts +0 -71
- package/dist/cjs/block.d.ts.map +0 -1
- package/dist/cjs/block.js +0 -158
- package/dist/cjs/block.js.map +0 -1
- package/dist/cjs/constants.d.ts +0 -2
- package/dist/cjs/constants.d.ts.map +0 -1
- package/dist/cjs/constants.js +0 -6
- package/dist/cjs/constants.js.map +0 -1
- package/dist/cjs/file.d.ts +0 -33
- package/dist/cjs/file.d.ts.map +0 -1
- package/dist/cjs/file.js +0 -57
- package/dist/cjs/file.js.map +0 -1
- package/dist/cjs/fragmenter.d.ts +0 -14
- package/dist/cjs/fragmenter.d.ts.map +0 -1
- package/dist/cjs/fragmenter.js +0 -95
- package/dist/cjs/fragmenter.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -12
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -59
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/restorer.d.ts +0 -10
- package/dist/cjs/restorer.d.ts.map +0 -1
- package/dist/cjs/restorer.js +0 -54
- package/dist/cjs/restorer.js.map +0 -1
- package/dist/cjs/utils.d.ts +0 -6
- package/dist/cjs/utils.d.ts.map +0 -1
- package/dist/cjs/utils.js +0 -15
- package/dist/cjs/utils.js.map +0 -1
- package/dist/constants.cjs +0 -6
- package/dist/constants.d.cts +0 -2
- package/dist/constants.d.ts.map +0 -1
- package/dist/esm/block.d.ts +0 -71
- package/dist/esm/block.d.ts.map +0 -1
- package/dist/esm/block.js +0 -149
- package/dist/esm/block.js.map +0 -1
- package/dist/esm/constants.d.ts +0 -2
- package/dist/esm/constants.d.ts.map +0 -1
- package/dist/esm/constants.js +0 -3
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/file.d.ts +0 -33
- package/dist/esm/file.d.ts.map +0 -1
- package/dist/esm/file.js +0 -47
- package/dist/esm/file.js.map +0 -1
- package/dist/esm/fragmenter.d.ts +0 -14
- package/dist/esm/fragmenter.d.ts.map +0 -1
- package/dist/esm/fragmenter.js +0 -91
- package/dist/esm/fragmenter.js.map +0 -1
- package/dist/esm/index.d.ts +0 -12
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -55
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/restorer.d.ts +0 -10
- package/dist/esm/restorer.d.ts.map +0 -1
- package/dist/esm/restorer.js +0 -50
- package/dist/esm/restorer.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -6
- package/dist/esm/utils.d.ts.map +0 -1
- package/dist/esm/utils.js +0 -9
- package/dist/esm/utils.js.map +0 -1
- package/dist/file.cjs +0 -57
- package/dist/file.d.cts +0 -33
- package/dist/file.d.ts.map +0 -1
- package/dist/fragmenter.cjs +0 -95
- package/dist/fragmenter.d.cts +0 -14
- package/dist/fragmenter.d.ts.map +0 -1
- package/dist/index.cjs +0 -59
- package/dist/index.d.cts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/restorer.cjs +0 -54
- package/dist/restorer.d.cts +0 -10
- package/dist/restorer.d.ts.map +0 -1
- package/dist/utils.cjs +0 -15
- package/dist/utils.d.cts +0 -6
- package/dist/utils.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixzle/node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "Node.js implementation of image fragmentation and restoration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@tuki0918/seeded-shuffle": "^1.0.0",
|
|
30
30
|
"jimp": "^1.6.0",
|
|
31
|
-
"@pixzle/core": "0.0.
|
|
31
|
+
"@pixzle/core": "0.0.25"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^22.10.2",
|
package/dist/block.cjs
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitImageToBlocks = splitImageToBlocks;
|
|
4
|
-
exports.blocksToImageBuffer = blocksToImageBuffer;
|
|
5
|
-
exports.imageFileToBlocks = imageFileToBlocks;
|
|
6
|
-
exports.blocksToPngImage = blocksToPngImage;
|
|
7
|
-
exports.extractImageBufferFromPng = extractImageBufferFromPng;
|
|
8
|
-
exports.createPngFromImageBuffer = createPngFromImageBuffer;
|
|
9
|
-
exports.blocksPerImage = blocksPerImage;
|
|
10
|
-
const core_1 = require("@pixzle/core");
|
|
11
|
-
const jimp_1 = require("jimp");
|
|
12
|
-
/**
|
|
13
|
-
* Format error message consistently
|
|
14
|
-
* @param operation Description of the operation that failed
|
|
15
|
-
* @param error The error that occurred
|
|
16
|
-
* @returns Formatted error message
|
|
17
|
-
*/
|
|
18
|
-
function formatErrorMessage(operation, error) {
|
|
19
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
20
|
-
return `${operation}: ${errorMessage}`;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a Jimp image from raw RGBA image buffer
|
|
24
|
-
* @param imageBuffer Raw RGBA image buffer
|
|
25
|
-
* @param width Image width in pixels
|
|
26
|
-
* @param height Image height in pixels
|
|
27
|
-
* @returns Jimp image instance
|
|
28
|
-
*/
|
|
29
|
-
function createJimpFromImageBuffer(imageBuffer, width, height) {
|
|
30
|
-
return new jimp_1.Jimp({
|
|
31
|
-
data: imageBuffer,
|
|
32
|
-
width,
|
|
33
|
-
height,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Split an RGBA image buffer into an array of blocks (Node.js Buffer wrapper)
|
|
38
|
-
* @param buffer Source image buffer (RGBA format)
|
|
39
|
-
* @param width Image width in pixels
|
|
40
|
-
* @param height Image height in pixels
|
|
41
|
-
* @param blockSize Block size in pixels
|
|
42
|
-
* @returns Array of block buffers
|
|
43
|
-
*/
|
|
44
|
-
function splitImageToBlocks(buffer, width, height, blockSize) {
|
|
45
|
-
const blocks = (0, core_1.splitImageToBlocks)(buffer, width, height, blockSize);
|
|
46
|
-
return blocks.map((block) => Buffer.from(block));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Reconstruct an RGBA image buffer from an array of blocks (Node.js Buffer wrapper)
|
|
50
|
-
* @param blocks Array of block buffers
|
|
51
|
-
* @param width Target image width in pixels
|
|
52
|
-
* @param height Target image height in pixels
|
|
53
|
-
* @param blockSize Block size in pixels
|
|
54
|
-
* @returns Reconstructed image buffer
|
|
55
|
-
*/
|
|
56
|
-
function blocksToImageBuffer(blocks, width, height, blockSize) {
|
|
57
|
-
const uint8Blocks = blocks.map((block) => new Uint8Array(block));
|
|
58
|
-
const imageBuffer = (0, core_1.blocksToImageBuffer)(uint8Blocks, width, height, blockSize);
|
|
59
|
-
return Buffer.from(imageBuffer);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Load an image from file or buffer and split into blocks
|
|
63
|
-
* @param input Path to the image file or Buffer containing image data
|
|
64
|
-
* @param blockSize Block size in pixels
|
|
65
|
-
* @returns Promise resolving to block data and image metadata
|
|
66
|
-
*/
|
|
67
|
-
async function imageFileToBlocks(input, blockSize) {
|
|
68
|
-
try {
|
|
69
|
-
// Load and process image with Jimp (automatically converts to RGBA)
|
|
70
|
-
const image = await jimp_1.Jimp.read(input);
|
|
71
|
-
const { width, height } = image.bitmap;
|
|
72
|
-
const channels = core_1.RGBA_CHANNELS;
|
|
73
|
-
const imageBuffer = image.bitmap.data;
|
|
74
|
-
// Split image into blocks
|
|
75
|
-
const blocks = splitImageToBlocks(imageBuffer, width, height, blockSize);
|
|
76
|
-
const blockCounts = (0, core_1.calculateBlockCounts)(width, height, blockSize);
|
|
77
|
-
return {
|
|
78
|
-
blocks,
|
|
79
|
-
width,
|
|
80
|
-
height,
|
|
81
|
-
channels,
|
|
82
|
-
blockCountX: blockCounts.blockCountX,
|
|
83
|
-
blockCountY: blockCounts.blockCountY,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
throw new Error(`${formatErrorMessage("Failed to process image file", error)}. The manifest file may not match the image data.`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Reconstruct a PNG image from blocks
|
|
92
|
-
* @param blocks Array of block buffers
|
|
93
|
-
* @param width Target image width in pixels
|
|
94
|
-
* @param height Target image height in pixels
|
|
95
|
-
* @param blockSize Block size in pixels
|
|
96
|
-
* @returns Promise resolving to PNG buffer
|
|
97
|
-
*/
|
|
98
|
-
async function blocksToPngImage(blocks, width, height, blockSize) {
|
|
99
|
-
try {
|
|
100
|
-
const imageBuffer = blocksToImageBuffer(blocks, width, height, blockSize);
|
|
101
|
-
return await createPngFromImageBuffer(imageBuffer, width, height);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
throw new Error(formatErrorMessage("Failed to reconstruct PNG image from blocks", error));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Extract raw RGBA image buffer from a PNG buffer using Jimp
|
|
109
|
-
* @param pngBuffer PNG image buffer
|
|
110
|
-
* @returns Promise resolving to image buffer and image dimensions
|
|
111
|
-
*/
|
|
112
|
-
async function extractImageBufferFromPng(pngBuffer) {
|
|
113
|
-
try {
|
|
114
|
-
const image = await jimp_1.Jimp.read(pngBuffer);
|
|
115
|
-
const { width, height } = image.bitmap;
|
|
116
|
-
const imageBuffer = Buffer.from(image.bitmap.data);
|
|
117
|
-
return { imageBuffer, width, height };
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
throw new Error(formatErrorMessage("Failed to extract image buffer from PNG", error));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Create a PNG buffer from raw RGBA image buffer using Jimp
|
|
125
|
-
* @param imageBuffer Raw RGBA image buffer
|
|
126
|
-
* @param width Image width in pixels
|
|
127
|
-
* @param height Image height in pixels
|
|
128
|
-
* @returns Promise resolving to PNG buffer
|
|
129
|
-
*/
|
|
130
|
-
async function createPngFromImageBuffer(imageBuffer, width, height) {
|
|
131
|
-
try {
|
|
132
|
-
const image = createJimpFromImageBuffer(imageBuffer, width, height);
|
|
133
|
-
return await image.getBuffer(jimp_1.JimpMime.png);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
throw new Error(formatErrorMessage("Failed to create PNG from image buffer", error));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Apply a function to blocks per image
|
|
141
|
-
* @param allBlocks - All blocks to process
|
|
142
|
-
* @param fragmentBlocksCount - Number of blocks per fragment
|
|
143
|
-
* @param seed - Seed for the processing function
|
|
144
|
-
* @param processFunc - Function to apply to blocks (shuffle or unshuffle)
|
|
145
|
-
* @returns Processed blocks
|
|
146
|
-
*/
|
|
147
|
-
function blocksPerImage(allBlocks, fragmentBlocksCount, seed, processFunc) {
|
|
148
|
-
const processedBlocks = [];
|
|
149
|
-
let offset = 0;
|
|
150
|
-
for (const blockCount of fragmentBlocksCount) {
|
|
151
|
-
const imageBlocks = allBlocks.slice(offset, offset + blockCount);
|
|
152
|
-
const processed = processFunc(imageBlocks, seed);
|
|
153
|
-
processedBlocks.push(...processed);
|
|
154
|
-
offset += blockCount;
|
|
155
|
-
}
|
|
156
|
-
return processedBlocks;
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=block.js.map
|
package/dist/block.d.cts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
interface ImageFileToBlocksResult {
|
|
2
|
-
blocks: Buffer[];
|
|
3
|
-
width: number;
|
|
4
|
-
height: number;
|
|
5
|
-
channels: number;
|
|
6
|
-
blockCountX: number;
|
|
7
|
-
blockCountY: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Split an RGBA image buffer into an array of blocks (Node.js Buffer wrapper)
|
|
11
|
-
* @param buffer Source image buffer (RGBA format)
|
|
12
|
-
* @param width Image width in pixels
|
|
13
|
-
* @param height Image height in pixels
|
|
14
|
-
* @param blockSize Block size in pixels
|
|
15
|
-
* @returns Array of block buffers
|
|
16
|
-
*/
|
|
17
|
-
export declare function splitImageToBlocks(buffer: Buffer, width: number, height: number, blockSize: number): Buffer[];
|
|
18
|
-
/**
|
|
19
|
-
* Reconstruct an RGBA image buffer from an array of blocks (Node.js Buffer wrapper)
|
|
20
|
-
* @param blocks Array of block buffers
|
|
21
|
-
* @param width Target image width in pixels
|
|
22
|
-
* @param height Target image height in pixels
|
|
23
|
-
* @param blockSize Block size in pixels
|
|
24
|
-
* @returns Reconstructed image buffer
|
|
25
|
-
*/
|
|
26
|
-
export declare function blocksToImageBuffer(blocks: Buffer[], width: number, height: number, blockSize: number): Buffer;
|
|
27
|
-
/**
|
|
28
|
-
* Load an image from file or buffer and split into blocks
|
|
29
|
-
* @param input Path to the image file or Buffer containing image data
|
|
30
|
-
* @param blockSize Block size in pixels
|
|
31
|
-
* @returns Promise resolving to block data and image metadata
|
|
32
|
-
*/
|
|
33
|
-
export declare function imageFileToBlocks(input: string | Buffer, blockSize: number): Promise<ImageFileToBlocksResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Reconstruct a PNG image from blocks
|
|
36
|
-
* @param blocks Array of block buffers
|
|
37
|
-
* @param width Target image width in pixels
|
|
38
|
-
* @param height Target image height in pixels
|
|
39
|
-
* @param blockSize Block size in pixels
|
|
40
|
-
* @returns Promise resolving to PNG buffer
|
|
41
|
-
*/
|
|
42
|
-
export declare function blocksToPngImage(blocks: Buffer[], width: number, height: number, blockSize: number): Promise<Buffer>;
|
|
43
|
-
/**
|
|
44
|
-
* Extract raw RGBA image buffer from a PNG buffer using Jimp
|
|
45
|
-
* @param pngBuffer PNG image buffer
|
|
46
|
-
* @returns Promise resolving to image buffer and image dimensions
|
|
47
|
-
*/
|
|
48
|
-
export declare function extractImageBufferFromPng(pngBuffer: Buffer): Promise<{
|
|
49
|
-
imageBuffer: Buffer;
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
}>;
|
|
53
|
-
/**
|
|
54
|
-
* Create a PNG buffer from raw RGBA image buffer using Jimp
|
|
55
|
-
* @param imageBuffer Raw RGBA image buffer
|
|
56
|
-
* @param width Image width in pixels
|
|
57
|
-
* @param height Image height in pixels
|
|
58
|
-
* @returns Promise resolving to PNG buffer
|
|
59
|
-
*/
|
|
60
|
-
export declare function createPngFromImageBuffer(imageBuffer: Buffer, width: number, height: number): Promise<Buffer>;
|
|
61
|
-
/**
|
|
62
|
-
* Apply a function to blocks per image
|
|
63
|
-
* @param allBlocks - All blocks to process
|
|
64
|
-
* @param fragmentBlocksCount - Number of blocks per fragment
|
|
65
|
-
* @param seed - Seed for the processing function
|
|
66
|
-
* @param processFunc - Function to apply to blocks (shuffle or unshuffle)
|
|
67
|
-
* @returns Processed blocks
|
|
68
|
-
*/
|
|
69
|
-
export declare function blocksPerImage(allBlocks: Buffer[], fragmentBlocksCount: number[], seed: number | string, processFunc: (blocks: Buffer[], seed: number | string) => Buffer[]): Buffer[];
|
|
70
|
-
export {};
|
|
71
|
-
//# sourceMappingURL=block.d.ts.map
|
package/dist/block.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAQA,UAAU,uBAAuB;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,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I,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,EAAE,GACjE,MAAM,EAAE,CAYV"}
|
package/dist/cjs/block.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
interface ImageFileToBlocksResult {
|
|
2
|
-
blocks: Buffer[];
|
|
3
|
-
width: number;
|
|
4
|
-
height: number;
|
|
5
|
-
channels: number;
|
|
6
|
-
blockCountX: number;
|
|
7
|
-
blockCountY: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Split an RGBA image buffer into an array of blocks (Node.js Buffer wrapper)
|
|
11
|
-
* @param buffer Source image buffer (RGBA format)
|
|
12
|
-
* @param width Image width in pixels
|
|
13
|
-
* @param height Image height in pixels
|
|
14
|
-
* @param blockSize Block size in pixels
|
|
15
|
-
* @returns Array of block buffers
|
|
16
|
-
*/
|
|
17
|
-
export declare function splitImageToBlocks(buffer: Buffer, width: number, height: number, blockSize: number): Buffer[];
|
|
18
|
-
/**
|
|
19
|
-
* Reconstruct an RGBA image buffer from an array of blocks (Node.js Buffer wrapper)
|
|
20
|
-
* @param blocks Array of block buffers
|
|
21
|
-
* @param width Target image width in pixels
|
|
22
|
-
* @param height Target image height in pixels
|
|
23
|
-
* @param blockSize Block size in pixels
|
|
24
|
-
* @returns Reconstructed image buffer
|
|
25
|
-
*/
|
|
26
|
-
export declare function blocksToImageBuffer(blocks: Buffer[], width: number, height: number, blockSize: number): Buffer;
|
|
27
|
-
/**
|
|
28
|
-
* Load an image from file or buffer and split into blocks
|
|
29
|
-
* @param input Path to the image file or Buffer containing image data
|
|
30
|
-
* @param blockSize Block size in pixels
|
|
31
|
-
* @returns Promise resolving to block data and image metadata
|
|
32
|
-
*/
|
|
33
|
-
export declare function imageFileToBlocks(input: string | Buffer, blockSize: number): Promise<ImageFileToBlocksResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Reconstruct a PNG image from blocks
|
|
36
|
-
* @param blocks Array of block buffers
|
|
37
|
-
* @param width Target image width in pixels
|
|
38
|
-
* @param height Target image height in pixels
|
|
39
|
-
* @param blockSize Block size in pixels
|
|
40
|
-
* @returns Promise resolving to PNG buffer
|
|
41
|
-
*/
|
|
42
|
-
export declare function blocksToPngImage(blocks: Buffer[], width: number, height: number, blockSize: number): Promise<Buffer>;
|
|
43
|
-
/**
|
|
44
|
-
* Extract raw RGBA image buffer from a PNG buffer using Jimp
|
|
45
|
-
* @param pngBuffer PNG image buffer
|
|
46
|
-
* @returns Promise resolving to image buffer and image dimensions
|
|
47
|
-
*/
|
|
48
|
-
export declare function extractImageBufferFromPng(pngBuffer: Buffer): Promise<{
|
|
49
|
-
imageBuffer: Buffer;
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
}>;
|
|
53
|
-
/**
|
|
54
|
-
* Create a PNG buffer from raw RGBA image buffer using Jimp
|
|
55
|
-
* @param imageBuffer Raw RGBA image buffer
|
|
56
|
-
* @param width Image width in pixels
|
|
57
|
-
* @param height Image height in pixels
|
|
58
|
-
* @returns Promise resolving to PNG buffer
|
|
59
|
-
*/
|
|
60
|
-
export declare function createPngFromImageBuffer(imageBuffer: Buffer, width: number, height: number): Promise<Buffer>;
|
|
61
|
-
/**
|
|
62
|
-
* Apply a function to blocks per image
|
|
63
|
-
* @param allBlocks - All blocks to process
|
|
64
|
-
* @param fragmentBlocksCount - Number of blocks per fragment
|
|
65
|
-
* @param seed - Seed for the processing function
|
|
66
|
-
* @param processFunc - Function to apply to blocks (shuffle or unshuffle)
|
|
67
|
-
* @returns Processed blocks
|
|
68
|
-
*/
|
|
69
|
-
export declare function blocksPerImage(allBlocks: Buffer[], fragmentBlocksCount: number[], seed: number | string, processFunc: (blocks: Buffer[], seed: number | string) => Buffer[]): Buffer[];
|
|
70
|
-
export {};
|
|
71
|
-
//# sourceMappingURL=block.d.ts.map
|
package/dist/cjs/block.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../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AAc,CAC5B,SAAS,EAAE,MAAM,EAAE,EACnB,mBAAmB,EAAE,MAAM,EAAE,EAC7B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,EAAE,GACjE,MAAM,EAAE,CAYV"}
|
package/dist/cjs/block.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitImageToBlocks = splitImageToBlocks;
|
|
4
|
-
exports.blocksToImageBuffer = blocksToImageBuffer;
|
|
5
|
-
exports.imageFileToBlocks = imageFileToBlocks;
|
|
6
|
-
exports.blocksToPngImage = blocksToPngImage;
|
|
7
|
-
exports.extractImageBufferFromPng = extractImageBufferFromPng;
|
|
8
|
-
exports.createPngFromImageBuffer = createPngFromImageBuffer;
|
|
9
|
-
exports.blocksPerImage = blocksPerImage;
|
|
10
|
-
const core_1 = require("@pixzle/core");
|
|
11
|
-
const jimp_1 = require("jimp");
|
|
12
|
-
/**
|
|
13
|
-
* Format error message consistently
|
|
14
|
-
* @param operation Description of the operation that failed
|
|
15
|
-
* @param error The error that occurred
|
|
16
|
-
* @returns Formatted error message
|
|
17
|
-
*/
|
|
18
|
-
function formatErrorMessage(operation, error) {
|
|
19
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
20
|
-
return `${operation}: ${errorMessage}`;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a Jimp image from raw RGBA image buffer
|
|
24
|
-
* @param imageBuffer Raw RGBA image buffer
|
|
25
|
-
* @param width Image width in pixels
|
|
26
|
-
* @param height Image height in pixels
|
|
27
|
-
* @returns Jimp image instance
|
|
28
|
-
*/
|
|
29
|
-
function createJimpFromImageBuffer(imageBuffer, width, height) {
|
|
30
|
-
return new jimp_1.Jimp({
|
|
31
|
-
data: imageBuffer,
|
|
32
|
-
width,
|
|
33
|
-
height,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Split an RGBA image buffer into an array of blocks (Node.js Buffer wrapper)
|
|
38
|
-
* @param buffer Source image buffer (RGBA format)
|
|
39
|
-
* @param width Image width in pixels
|
|
40
|
-
* @param height Image height in pixels
|
|
41
|
-
* @param blockSize Block size in pixels
|
|
42
|
-
* @returns Array of block buffers
|
|
43
|
-
*/
|
|
44
|
-
function splitImageToBlocks(buffer, width, height, blockSize) {
|
|
45
|
-
const blocks = (0, core_1.splitImageToBlocks)(buffer, width, height, blockSize);
|
|
46
|
-
return blocks.map((block) => Buffer.from(block));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Reconstruct an RGBA image buffer from an array of blocks (Node.js Buffer wrapper)
|
|
50
|
-
* @param blocks Array of block buffers
|
|
51
|
-
* @param width Target image width in pixels
|
|
52
|
-
* @param height Target image height in pixels
|
|
53
|
-
* @param blockSize Block size in pixels
|
|
54
|
-
* @returns Reconstructed image buffer
|
|
55
|
-
*/
|
|
56
|
-
function blocksToImageBuffer(blocks, width, height, blockSize) {
|
|
57
|
-
const uint8Blocks = blocks.map((block) => new Uint8Array(block));
|
|
58
|
-
const imageBuffer = (0, core_1.blocksToImageBuffer)(uint8Blocks, width, height, blockSize);
|
|
59
|
-
return Buffer.from(imageBuffer);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Load an image from file or buffer and split into blocks
|
|
63
|
-
* @param input Path to the image file or Buffer containing image data
|
|
64
|
-
* @param blockSize Block size in pixels
|
|
65
|
-
* @returns Promise resolving to block data and image metadata
|
|
66
|
-
*/
|
|
67
|
-
async function imageFileToBlocks(input, blockSize) {
|
|
68
|
-
try {
|
|
69
|
-
// Load and process image with Jimp (automatically converts to RGBA)
|
|
70
|
-
const image = await jimp_1.Jimp.read(input);
|
|
71
|
-
const { width, height } = image.bitmap;
|
|
72
|
-
const channels = core_1.RGBA_CHANNELS;
|
|
73
|
-
const imageBuffer = image.bitmap.data;
|
|
74
|
-
// Split image into blocks
|
|
75
|
-
const blocks = splitImageToBlocks(imageBuffer, width, height, blockSize);
|
|
76
|
-
const blockCounts = (0, core_1.calculateBlockCounts)(width, height, blockSize);
|
|
77
|
-
return {
|
|
78
|
-
blocks,
|
|
79
|
-
width,
|
|
80
|
-
height,
|
|
81
|
-
channels,
|
|
82
|
-
blockCountX: blockCounts.blockCountX,
|
|
83
|
-
blockCountY: blockCounts.blockCountY,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
throw new Error(`${formatErrorMessage("Failed to process image file", error)}. The manifest file may not match the image data.`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Reconstruct a PNG image from blocks
|
|
92
|
-
* @param blocks Array of block buffers
|
|
93
|
-
* @param width Target image width in pixels
|
|
94
|
-
* @param height Target image height in pixels
|
|
95
|
-
* @param blockSize Block size in pixels
|
|
96
|
-
* @returns Promise resolving to PNG buffer
|
|
97
|
-
*/
|
|
98
|
-
async function blocksToPngImage(blocks, width, height, blockSize) {
|
|
99
|
-
try {
|
|
100
|
-
const imageBuffer = blocksToImageBuffer(blocks, width, height, blockSize);
|
|
101
|
-
return await createPngFromImageBuffer(imageBuffer, width, height);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
throw new Error(formatErrorMessage("Failed to reconstruct PNG image from blocks", error));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Extract raw RGBA image buffer from a PNG buffer using Jimp
|
|
109
|
-
* @param pngBuffer PNG image buffer
|
|
110
|
-
* @returns Promise resolving to image buffer and image dimensions
|
|
111
|
-
*/
|
|
112
|
-
async function extractImageBufferFromPng(pngBuffer) {
|
|
113
|
-
try {
|
|
114
|
-
const image = await jimp_1.Jimp.read(pngBuffer);
|
|
115
|
-
const { width, height } = image.bitmap;
|
|
116
|
-
const imageBuffer = Buffer.from(image.bitmap.data);
|
|
117
|
-
return { imageBuffer, width, height };
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
throw new Error(formatErrorMessage("Failed to extract image buffer from PNG", error));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Create a PNG buffer from raw RGBA image buffer using Jimp
|
|
125
|
-
* @param imageBuffer Raw RGBA image buffer
|
|
126
|
-
* @param width Image width in pixels
|
|
127
|
-
* @param height Image height in pixels
|
|
128
|
-
* @returns Promise resolving to PNG buffer
|
|
129
|
-
*/
|
|
130
|
-
async function createPngFromImageBuffer(imageBuffer, width, height) {
|
|
131
|
-
try {
|
|
132
|
-
const image = createJimpFromImageBuffer(imageBuffer, width, height);
|
|
133
|
-
return await image.getBuffer(jimp_1.JimpMime.png);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
throw new Error(formatErrorMessage("Failed to create PNG from image buffer", error));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Apply a function to blocks per image
|
|
141
|
-
* @param allBlocks - All blocks to process
|
|
142
|
-
* @param fragmentBlocksCount - Number of blocks per fragment
|
|
143
|
-
* @param seed - Seed for the processing function
|
|
144
|
-
* @param processFunc - Function to apply to blocks (shuffle or unshuffle)
|
|
145
|
-
* @returns Processed blocks
|
|
146
|
-
*/
|
|
147
|
-
function blocksPerImage(allBlocks, fragmentBlocksCount, seed, processFunc) {
|
|
148
|
-
const processedBlocks = [];
|
|
149
|
-
let offset = 0;
|
|
150
|
-
for (const blockCount of fragmentBlocksCount) {
|
|
151
|
-
const imageBlocks = allBlocks.slice(offset, offset + blockCount);
|
|
152
|
-
const processed = processFunc(imageBlocks, seed);
|
|
153
|
-
processedBlocks.push(...processed);
|
|
154
|
-
offset += blockCount;
|
|
155
|
-
}
|
|
156
|
-
return processedBlocks;
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=block.js.map
|
package/dist/cjs/block.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/block.ts"],"names":[],"mappings":";;AAuDA,gDAQC;AAUD,kDAcC;AAQD,8CA4BC;AAUD,4CAcC;AAOD,8DAcC;AASD,4DAaC;AAUD,wCAiBC;AAzND,uCAKsB;AACtB,+BAAsC;AAWtC;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,SAAiB,EAAE,KAAc;IAC3D,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;IAC9E,OAAO,GAAG,SAAS,KAAK,YAAY,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,yBAAyB,CAChC,WAAmB,EACnB,KAAa,EACb,MAAc;IAEd,OAAO,IAAI,WAAI,CAAC;QACd,IAAI,EAAE,WAAW;QACjB,KAAK;QACL,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,MAAc,EACd,KAAa,EACb,MAAc,EACd,SAAiB;IAEjB,MAAM,MAAM,GAAG,IAAA,yBAAsB,EAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,MAAgB,EAChB,KAAa,EACb,MAAc,EACd,SAAiB;IAEjB,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACjE,MAAM,WAAW,GAAG,IAAA,0BAAuB,EACzC,WAAW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AM,UAAU,IAAI,mBAAmB,EAAE,CAAC;QAC7C,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACjD,eAAe,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;QACnC,MAAM,IAAI,UAAU,CAAC;IACvB,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
package/dist/cjs/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,QAAU,CAAC"}
|
package/dist/cjs/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,oDAA4C;AAE/B,QAAA,OAAO,GAAG,sBAAO,CAAC"}
|
package/dist/cjs/file.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a directory
|
|
3
|
-
* @param dir Directory path
|
|
4
|
-
* @param recursive Create parent directories if they don't exist
|
|
5
|
-
*/
|
|
6
|
-
export declare function createDir(dir: string, recursive?: boolean): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Write a file
|
|
9
|
-
* @param dir Directory path
|
|
10
|
-
* @param filename Filename
|
|
11
|
-
* @param data Data to write
|
|
12
|
-
* @returns Path to the file
|
|
13
|
-
*/
|
|
14
|
-
export declare function writeFile(dir: string, filename: string, data: string | Buffer): Promise<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Read a JSON file and return its content
|
|
17
|
-
* @param filePath Path to the JSON file
|
|
18
|
-
* @returns Content of the JSON file
|
|
19
|
-
*/
|
|
20
|
-
export declare function readJsonFile<T>(filePath: string): Promise<T>;
|
|
21
|
-
/**
|
|
22
|
-
* Read a file and return its content
|
|
23
|
-
* @param filePath Path to the file
|
|
24
|
-
* @returns Content of the file
|
|
25
|
-
*/
|
|
26
|
-
export declare function readFileBuffer(filePath: string): Promise<Buffer>;
|
|
27
|
-
/**
|
|
28
|
-
* Get the filename without the extension
|
|
29
|
-
* @param filePath Path to the file
|
|
30
|
-
* @returns Filename without the extension
|
|
31
|
-
*/
|
|
32
|
-
export declare function fileNameWithoutExtension(filePath: string): string;
|
|
33
|
-
//# sourceMappingURL=file.d.ts.map
|
package/dist/cjs/file.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/file.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,UAAQ,iBAE7D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,MAAM,mBAKtB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAElE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE"}
|
package/dist/cjs/file.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createDir = createDir;
|
|
7
|
-
exports.writeFile = writeFile;
|
|
8
|
-
exports.readJsonFile = readJsonFile;
|
|
9
|
-
exports.readFileBuffer = readFileBuffer;
|
|
10
|
-
exports.fileNameWithoutExtension = fileNameWithoutExtension;
|
|
11
|
-
const node_fs_1 = require("node:fs");
|
|
12
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
-
/**
|
|
14
|
-
* Create a directory
|
|
15
|
-
* @param dir Directory path
|
|
16
|
-
* @param recursive Create parent directories if they don't exist
|
|
17
|
-
*/
|
|
18
|
-
async function createDir(dir, recursive = false) {
|
|
19
|
-
await node_fs_1.promises.mkdir(dir, { recursive });
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Write a file
|
|
23
|
-
* @param dir Directory path
|
|
24
|
-
* @param filename Filename
|
|
25
|
-
* @param data Data to write
|
|
26
|
-
* @returns Path to the file
|
|
27
|
-
*/
|
|
28
|
-
async function writeFile(dir, filename, data) {
|
|
29
|
-
const filePath = node_path_1.default.join(dir, filename);
|
|
30
|
-
await node_fs_1.promises.writeFile(filePath, data);
|
|
31
|
-
return filePath;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Read a JSON file and return its content
|
|
35
|
-
* @param filePath Path to the JSON file
|
|
36
|
-
* @returns Content of the JSON file
|
|
37
|
-
*/
|
|
38
|
-
async function readJsonFile(filePath) {
|
|
39
|
-
return JSON.parse(await node_fs_1.promises.readFile(filePath, "utf8"));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Read a file and return its content
|
|
43
|
-
* @param filePath Path to the file
|
|
44
|
-
* @returns Content of the file
|
|
45
|
-
*/
|
|
46
|
-
async function readFileBuffer(filePath) {
|
|
47
|
-
return await node_fs_1.promises.readFile(filePath);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get the filename without the extension
|
|
51
|
-
* @param filePath Path to the file
|
|
52
|
-
* @returns Filename without the extension
|
|
53
|
-
*/
|
|
54
|
-
function fileNameWithoutExtension(filePath) {
|
|
55
|
-
return node_path_1.default.basename(filePath, node_path_1.default.extname(filePath));
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=file.js.map
|
package/dist/cjs/file.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file.ts"],"names":[],"mappings":";;;;;AAQA,8BAEC;AASD,8BAQC;AAOD,oCAEC;AAOD,wCAEC;AAOD,4DAEC;AAtDD,qCAAyC;AACzC,0DAA6B;AAE7B;;;;GAIG;AACI,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,SAAS,GAAG,KAAK;IAC5D,MAAM,kBAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,SAAS,CAC7B,GAAW,EACX,QAAgB,EAChB,IAAqB;IAErB,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC1C,MAAM,kBAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,YAAY,CAAI,QAAgB;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,kBAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD,OAAO,MAAM,kBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,QAAgB;IACvD,OAAO,mBAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/cjs/fragmenter.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type FragmentationConfig, type FragmentationResult } from "@pixzle/core";
|
|
2
|
-
export declare class ImageFragmenter {
|
|
3
|
-
private config;
|
|
4
|
-
constructor(config: FragmentationConfig);
|
|
5
|
-
private _initializeConfig;
|
|
6
|
-
fragmentImages(paths: string[]): Promise<FragmentationResult>;
|
|
7
|
-
private _createImages;
|
|
8
|
-
private _createManifest;
|
|
9
|
-
private _prepareData;
|
|
10
|
-
private _processImages;
|
|
11
|
-
private _processImage;
|
|
12
|
-
private _createImage;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=fragmenter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fragmenter.d.ts","sourceRoot":"","sources":["../../src/fragmenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EAQzB,MAAM,cAAc,CAAC;AAOtB,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAgC;gBAElC,MAAM,EAAE,mBAAmB;IAIvC,OAAO,CAAC,iBAAiB;IAenB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;YA6BrD,aAAa;IAc3B,OAAO,CAAC,eAAe;YAaT,YAAY;YAyBZ,cAAc;YAcd,aAAa;YAuBb,YAAY;CAW3B"}
|