cross-image 0.1.4 → 0.2.0
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 +155 -121
- package/esm/mod.d.ts +32 -8
- package/esm/mod.js +32 -8
- package/esm/src/formats/dng.d.ts +27 -0
- package/esm/src/formats/dng.js +191 -0
- package/esm/src/formats/pam.d.ts +43 -0
- package/esm/src/formats/pam.js +177 -0
- package/esm/src/formats/pcx.d.ts +13 -0
- package/esm/src/formats/pcx.js +204 -0
- package/esm/src/formats/tiff.d.ts +7 -7
- package/esm/src/image.d.ts +133 -1
- package/esm/src/image.js +250 -11
- package/esm/src/utils/image_processing.d.ts +91 -0
- package/esm/src/utils/image_processing.js +231 -0
- package/esm/src/utils/webp_decoder.js +47 -12
- package/esm/src/utils/webp_encoder.js +97 -39
- package/package.json +4 -1
- package/script/mod.d.ts +32 -8
- package/script/mod.js +36 -10
- package/script/src/formats/dng.d.ts +27 -0
- package/script/src/formats/dng.js +195 -0
- package/script/src/formats/pam.d.ts +43 -0
- package/script/src/formats/pam.js +181 -0
- package/script/src/formats/pcx.d.ts +13 -0
- package/script/src/formats/pcx.js +208 -0
- package/script/src/formats/tiff.d.ts +7 -7
- package/script/src/image.d.ts +133 -1
- package/script/src/image.js +250 -11
- package/script/src/utils/image_processing.d.ts +91 -0
- package/script/src/utils/image_processing.js +242 -0
- package/script/src/utils/webp_decoder.js +47 -12
- package/script/src/utils/webp_encoder.js +97 -39
- package/esm/src/formats/raw.d.ts +0 -40
- package/esm/src/formats/raw.js +0 -118
- package/script/src/formats/raw.d.ts +0 -40
- package/script/src/formats/raw.js +0 -122
package/script/src/image.d.ts
CHANGED
|
@@ -72,24 +72,49 @@ export declare class Image {
|
|
|
72
72
|
* Get all registered formats
|
|
73
73
|
*/
|
|
74
74
|
static getFormats(): readonly ImageFormat[];
|
|
75
|
+
/**
|
|
76
|
+
* Decode an image from bytes
|
|
77
|
+
* @param data Raw image data
|
|
78
|
+
* @param format Optional format hint (e.g., "png", "jpeg", "webp")
|
|
79
|
+
* @returns Image instance
|
|
80
|
+
*/
|
|
81
|
+
static decode(data: Uint8Array, format?: string): Promise<Image>;
|
|
75
82
|
/**
|
|
76
83
|
* Read an image from bytes
|
|
84
|
+
* @deprecated Use `decode()` instead. This method will be removed in a future version.
|
|
77
85
|
* @param data Raw image data
|
|
78
86
|
* @param format Optional format hint (e.g., "png", "jpeg", "webp")
|
|
79
87
|
* @returns Image instance
|
|
80
88
|
*/
|
|
81
89
|
static read(data: Uint8Array, format?: string): Promise<Image>;
|
|
90
|
+
/**
|
|
91
|
+
* Decode all frames from a multi-frame image (GIF animation, multi-page TIFF)
|
|
92
|
+
* @param data Raw image data
|
|
93
|
+
* @param format Optional format hint (e.g., "gif", "tiff")
|
|
94
|
+
* @returns MultiFrameImageData with all frames
|
|
95
|
+
*/
|
|
96
|
+
static decodeFrames(data: Uint8Array, format?: string): Promise<MultiFrameImageData>;
|
|
82
97
|
/**
|
|
83
98
|
* Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
|
|
99
|
+
* @deprecated Use `decodeFrames()` instead. This method will be removed in a future version.
|
|
84
100
|
* @param data Raw image data
|
|
85
101
|
* @param format Optional format hint (e.g., "gif", "tiff")
|
|
86
102
|
* @returns MultiFrameImageData with all frames
|
|
87
103
|
*/
|
|
88
104
|
static readFrames(data: Uint8Array, format?: string): Promise<MultiFrameImageData>;
|
|
105
|
+
/**
|
|
106
|
+
* Encode multi-frame image data to bytes in the specified format
|
|
107
|
+
* @param format Format name (e.g., "gif", "tiff")
|
|
108
|
+
* @param imageData Multi-frame image data to encode
|
|
109
|
+
* @param options Optional format-specific encoding options
|
|
110
|
+
* @returns Encoded image bytes
|
|
111
|
+
*/
|
|
112
|
+
static encodeFrames(format: string, imageData: MultiFrameImageData, options?: unknown): Promise<Uint8Array>;
|
|
89
113
|
/**
|
|
90
114
|
* Save multi-frame image data to bytes in the specified format
|
|
115
|
+
* @deprecated Use `encodeFrames()` instead. This method will be removed in a future version.
|
|
91
116
|
* @param format Format name (e.g., "gif", "tiff")
|
|
92
|
-
* @param imageData Multi-frame image data to
|
|
117
|
+
* @param imageData Multi-frame image data to encode
|
|
93
118
|
* @param options Optional format-specific encoding options
|
|
94
119
|
* @returns Encoded image bytes
|
|
95
120
|
*/
|
|
@@ -102,14 +127,33 @@ export declare class Image {
|
|
|
102
127
|
* @returns Image instance
|
|
103
128
|
*/
|
|
104
129
|
static fromRGBA(width: number, height: number, data: Uint8Array): Image;
|
|
130
|
+
/**
|
|
131
|
+
* Create a blank image with the specified dimensions and color
|
|
132
|
+
* @param width Image width
|
|
133
|
+
* @param height Image height
|
|
134
|
+
* @param r Red component (0-255, default: 0)
|
|
135
|
+
* @param g Green component (0-255, default: 0)
|
|
136
|
+
* @param b Blue component (0-255, default: 0)
|
|
137
|
+
* @param a Alpha component (0-255, default: 255)
|
|
138
|
+
* @returns Image instance
|
|
139
|
+
*/
|
|
140
|
+
static create(width: number, height: number, r?: number, g?: number, b?: number, a?: number): Image;
|
|
105
141
|
/**
|
|
106
142
|
* Resize the image
|
|
107
143
|
* @param options Resize options
|
|
108
144
|
* @returns This image instance for chaining
|
|
109
145
|
*/
|
|
110
146
|
resize(options: ResizeOptions): this;
|
|
147
|
+
/**
|
|
148
|
+
* Encode the image to bytes in the specified format
|
|
149
|
+
* @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
|
|
150
|
+
* @param options Optional format-specific encoding options
|
|
151
|
+
* @returns Encoded image bytes
|
|
152
|
+
*/
|
|
153
|
+
encode(format: string, options?: unknown): Promise<Uint8Array>;
|
|
111
154
|
/**
|
|
112
155
|
* Save the image to bytes in the specified format
|
|
156
|
+
* @deprecated Use `encode()` instead. This method will be removed in a future version.
|
|
113
157
|
* @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
|
|
114
158
|
* @param options Optional format-specific encoding options
|
|
115
159
|
* @returns Encoded image bytes
|
|
@@ -120,5 +164,93 @@ export declare class Image {
|
|
|
120
164
|
* @returns New image instance with copied data and metadata
|
|
121
165
|
*/
|
|
122
166
|
clone(): Image;
|
|
167
|
+
/**
|
|
168
|
+
* Composite another image on top of this image at the specified position
|
|
169
|
+
* @param overlay Image to place on top
|
|
170
|
+
* @param x X position (can be negative)
|
|
171
|
+
* @param y Y position (can be negative)
|
|
172
|
+
* @param opacity Opacity of overlay (0-1, default: 1)
|
|
173
|
+
* @returns This image instance for chaining
|
|
174
|
+
*/
|
|
175
|
+
composite(overlay: Image, x: number, y: number, opacity?: number): this;
|
|
176
|
+
/**
|
|
177
|
+
* Adjust brightness of the image
|
|
178
|
+
* @param amount Brightness adjustment (-1 to 1, where 0 is no change)
|
|
179
|
+
* @returns This image instance for chaining
|
|
180
|
+
*/
|
|
181
|
+
brightness(amount: number): this;
|
|
182
|
+
/**
|
|
183
|
+
* Adjust contrast of the image
|
|
184
|
+
* @param amount Contrast adjustment (-1 to 1, where 0 is no change)
|
|
185
|
+
* @returns This image instance for chaining
|
|
186
|
+
*/
|
|
187
|
+
contrast(amount: number): this;
|
|
188
|
+
/**
|
|
189
|
+
* Adjust exposure of the image
|
|
190
|
+
* @param amount Exposure adjustment in stops (-3 to 3, where 0 is no change)
|
|
191
|
+
* @returns This image instance for chaining
|
|
192
|
+
*/
|
|
193
|
+
exposure(amount: number): this;
|
|
194
|
+
/**
|
|
195
|
+
* Adjust saturation of the image
|
|
196
|
+
* @param amount Saturation adjustment (-1 to 1, where 0 is no change)
|
|
197
|
+
* @returns This image instance for chaining
|
|
198
|
+
*/
|
|
199
|
+
saturation(amount: number): this;
|
|
200
|
+
/**
|
|
201
|
+
* Invert colors of the image
|
|
202
|
+
* @returns This image instance for chaining
|
|
203
|
+
*/
|
|
204
|
+
invert(): this;
|
|
205
|
+
/**
|
|
206
|
+
* Convert the image to grayscale
|
|
207
|
+
* @returns This image instance for chaining
|
|
208
|
+
*/
|
|
209
|
+
grayscale(): this;
|
|
210
|
+
/**
|
|
211
|
+
* Fill a rectangular region with a color
|
|
212
|
+
* @param x Starting X position
|
|
213
|
+
* @param y Starting Y position
|
|
214
|
+
* @param width Width of the fill region
|
|
215
|
+
* @param height Height of the fill region
|
|
216
|
+
* @param r Red component (0-255)
|
|
217
|
+
* @param g Green component (0-255)
|
|
218
|
+
* @param b Blue component (0-255)
|
|
219
|
+
* @param a Alpha component (0-255, default: 255)
|
|
220
|
+
* @returns This image instance for chaining
|
|
221
|
+
*/
|
|
222
|
+
fillRect(x: number, y: number, width: number, height: number, r: number, g: number, b: number, a?: number): this;
|
|
223
|
+
/**
|
|
224
|
+
* Crop the image to a rectangular region
|
|
225
|
+
* @param x Starting X position
|
|
226
|
+
* @param y Starting Y position
|
|
227
|
+
* @param width Width of the crop region
|
|
228
|
+
* @param height Height of the crop region
|
|
229
|
+
* @returns This image instance for chaining
|
|
230
|
+
*/
|
|
231
|
+
crop(x: number, y: number, width: number, height: number): this;
|
|
232
|
+
/**
|
|
233
|
+
* Get the pixel color at the specified position
|
|
234
|
+
* @param x X position
|
|
235
|
+
* @param y Y position
|
|
236
|
+
* @returns Object with r, g, b, a components (0-255) or undefined if out of bounds
|
|
237
|
+
*/
|
|
238
|
+
getPixel(x: number, y: number): {
|
|
239
|
+
r: number;
|
|
240
|
+
g: number;
|
|
241
|
+
b: number;
|
|
242
|
+
a: number;
|
|
243
|
+
} | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Set the pixel color at the specified position
|
|
246
|
+
* @param x X position
|
|
247
|
+
* @param y Y position
|
|
248
|
+
* @param r Red component (0-255)
|
|
249
|
+
* @param g Green component (0-255)
|
|
250
|
+
* @param b Blue component (0-255)
|
|
251
|
+
* @param a Alpha component (0-255, default: 255)
|
|
252
|
+
* @returns This image instance for chaining
|
|
253
|
+
*/
|
|
254
|
+
setPixel(x: number, y: number, r: number, g: number, b: number, a?: number): this;
|
|
123
255
|
}
|
|
124
256
|
//# sourceMappingURL=image.d.ts.map
|
package/script/src/image.js
CHANGED
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Image = void 0;
|
|
4
4
|
const resize_js_1 = require("./utils/resize.js");
|
|
5
|
+
const image_processing_js_1 = require("./utils/image_processing.js");
|
|
5
6
|
const png_js_1 = require("./formats/png.js");
|
|
6
7
|
const jpeg_js_1 = require("./formats/jpeg.js");
|
|
7
8
|
const webp_js_1 = require("./formats/webp.js");
|
|
8
9
|
const gif_js_1 = require("./formats/gif.js");
|
|
9
10
|
const tiff_js_1 = require("./formats/tiff.js");
|
|
10
11
|
const bmp_js_1 = require("./formats/bmp.js");
|
|
11
|
-
const
|
|
12
|
+
const dng_js_1 = require("./formats/dng.js");
|
|
13
|
+
const pam_js_1 = require("./formats/pam.js");
|
|
14
|
+
const pcx_js_1 = require("./formats/pcx.js");
|
|
12
15
|
const ascii_js_1 = require("./formats/ascii.js");
|
|
13
16
|
const security_js_1 = require("./utils/security.js");
|
|
14
17
|
/**
|
|
@@ -154,12 +157,12 @@ class Image {
|
|
|
154
157
|
return Image.formats;
|
|
155
158
|
}
|
|
156
159
|
/**
|
|
157
|
-
*
|
|
160
|
+
* Decode an image from bytes
|
|
158
161
|
* @param data Raw image data
|
|
159
162
|
* @param format Optional format hint (e.g., "png", "jpeg", "webp")
|
|
160
163
|
* @returns Image instance
|
|
161
164
|
*/
|
|
162
|
-
static async
|
|
165
|
+
static async decode(data, format) {
|
|
163
166
|
const image = new Image();
|
|
164
167
|
// Try specified format first
|
|
165
168
|
if (format) {
|
|
@@ -179,12 +182,22 @@ class Image {
|
|
|
179
182
|
throw new Error("Unsupported or unrecognized image format");
|
|
180
183
|
}
|
|
181
184
|
/**
|
|
182
|
-
* Read
|
|
185
|
+
* Read an image from bytes
|
|
186
|
+
* @deprecated Use `decode()` instead. This method will be removed in a future version.
|
|
187
|
+
* @param data Raw image data
|
|
188
|
+
* @param format Optional format hint (e.g., "png", "jpeg", "webp")
|
|
189
|
+
* @returns Image instance
|
|
190
|
+
*/
|
|
191
|
+
static read(data, format) {
|
|
192
|
+
return Image.decode(data, format);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Decode all frames from a multi-frame image (GIF animation, multi-page TIFF)
|
|
183
196
|
* @param data Raw image data
|
|
184
197
|
* @param format Optional format hint (e.g., "gif", "tiff")
|
|
185
198
|
* @returns MultiFrameImageData with all frames
|
|
186
199
|
*/
|
|
187
|
-
static async
|
|
200
|
+
static async decodeFrames(data, format) {
|
|
188
201
|
// Try specified format first
|
|
189
202
|
if (format) {
|
|
190
203
|
const handler = Image.formats.find((f) => f.name === format);
|
|
@@ -201,13 +214,23 @@ class Image {
|
|
|
201
214
|
throw new Error("Unsupported or unrecognized multi-frame image format");
|
|
202
215
|
}
|
|
203
216
|
/**
|
|
204
|
-
*
|
|
217
|
+
* Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
|
|
218
|
+
* @deprecated Use `decodeFrames()` instead. This method will be removed in a future version.
|
|
219
|
+
* @param data Raw image data
|
|
220
|
+
* @param format Optional format hint (e.g., "gif", "tiff")
|
|
221
|
+
* @returns MultiFrameImageData with all frames
|
|
222
|
+
*/
|
|
223
|
+
static readFrames(data, format) {
|
|
224
|
+
return Image.decodeFrames(data, format);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Encode multi-frame image data to bytes in the specified format
|
|
205
228
|
* @param format Format name (e.g., "gif", "tiff")
|
|
206
|
-
* @param imageData Multi-frame image data to
|
|
229
|
+
* @param imageData Multi-frame image data to encode
|
|
207
230
|
* @param options Optional format-specific encoding options
|
|
208
231
|
* @returns Encoded image bytes
|
|
209
232
|
*/
|
|
210
|
-
static async
|
|
233
|
+
static async encodeFrames(format, imageData, options) {
|
|
211
234
|
const handler = Image.formats.find((f) => f.name === format);
|
|
212
235
|
if (!handler) {
|
|
213
236
|
throw new Error(`Unsupported format: ${format}`);
|
|
@@ -217,6 +240,17 @@ class Image {
|
|
|
217
240
|
}
|
|
218
241
|
return await handler.encodeFrames(imageData, options);
|
|
219
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Save multi-frame image data to bytes in the specified format
|
|
245
|
+
* @deprecated Use `encodeFrames()` instead. This method will be removed in a future version.
|
|
246
|
+
* @param format Format name (e.g., "gif", "tiff")
|
|
247
|
+
* @param imageData Multi-frame image data to encode
|
|
248
|
+
* @param options Optional format-specific encoding options
|
|
249
|
+
* @returns Encoded image bytes
|
|
250
|
+
*/
|
|
251
|
+
static saveFrames(format, imageData, options) {
|
|
252
|
+
return Image.encodeFrames(format, imageData, options);
|
|
253
|
+
}
|
|
220
254
|
/**
|
|
221
255
|
* Create an image from raw RGBA data
|
|
222
256
|
* @param width Image width
|
|
@@ -234,6 +268,31 @@ class Image {
|
|
|
234
268
|
image.imageData = { width, height, data: new Uint8Array(data) };
|
|
235
269
|
return image;
|
|
236
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a blank image with the specified dimensions and color
|
|
273
|
+
* @param width Image width
|
|
274
|
+
* @param height Image height
|
|
275
|
+
* @param r Red component (0-255, default: 0)
|
|
276
|
+
* @param g Green component (0-255, default: 0)
|
|
277
|
+
* @param b Blue component (0-255, default: 0)
|
|
278
|
+
* @param a Alpha component (0-255, default: 255)
|
|
279
|
+
* @returns Image instance
|
|
280
|
+
*/
|
|
281
|
+
static create(width, height, r = 0, g = 0, b = 0, a = 255) {
|
|
282
|
+
// Validate dimensions for security (prevent integer overflow and heap exhaustion)
|
|
283
|
+
(0, security_js_1.validateImageDimensions)(width, height);
|
|
284
|
+
const data = new Uint8Array(width * height * 4);
|
|
285
|
+
// Fill with the specified color
|
|
286
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
287
|
+
data[i] = r;
|
|
288
|
+
data[i + 1] = g;
|
|
289
|
+
data[i + 2] = b;
|
|
290
|
+
data[i + 3] = a;
|
|
291
|
+
}
|
|
292
|
+
const image = new Image();
|
|
293
|
+
image.imageData = { width, height, data };
|
|
294
|
+
return image;
|
|
295
|
+
}
|
|
237
296
|
/**
|
|
238
297
|
* Resize the image
|
|
239
298
|
* @param options Resize options
|
|
@@ -273,12 +332,12 @@ class Image {
|
|
|
273
332
|
return this;
|
|
274
333
|
}
|
|
275
334
|
/**
|
|
276
|
-
*
|
|
335
|
+
* Encode the image to bytes in the specified format
|
|
277
336
|
* @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
|
|
278
337
|
* @param options Optional format-specific encoding options
|
|
279
338
|
* @returns Encoded image bytes
|
|
280
339
|
*/
|
|
281
|
-
async
|
|
340
|
+
async encode(format, options) {
|
|
282
341
|
if (!this.imageData)
|
|
283
342
|
throw new Error("No image loaded");
|
|
284
343
|
const handler = Image.formats.find((f) => f.name === format);
|
|
@@ -287,6 +346,16 @@ class Image {
|
|
|
287
346
|
}
|
|
288
347
|
return await handler.encode(this.imageData, options);
|
|
289
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Save the image to bytes in the specified format
|
|
351
|
+
* @deprecated Use `encode()` instead. This method will be removed in a future version.
|
|
352
|
+
* @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
|
|
353
|
+
* @param options Optional format-specific encoding options
|
|
354
|
+
* @returns Encoded image bytes
|
|
355
|
+
*/
|
|
356
|
+
save(format, options) {
|
|
357
|
+
return this.encode(format, options);
|
|
358
|
+
}
|
|
290
359
|
/**
|
|
291
360
|
* Clone this image
|
|
292
361
|
* @returns New image instance with copied data and metadata
|
|
@@ -310,6 +379,174 @@ class Image {
|
|
|
310
379
|
};
|
|
311
380
|
return image;
|
|
312
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Composite another image on top of this image at the specified position
|
|
384
|
+
* @param overlay Image to place on top
|
|
385
|
+
* @param x X position (can be negative)
|
|
386
|
+
* @param y Y position (can be negative)
|
|
387
|
+
* @param opacity Opacity of overlay (0-1, default: 1)
|
|
388
|
+
* @returns This image instance for chaining
|
|
389
|
+
*/
|
|
390
|
+
composite(overlay, x, y, opacity = 1) {
|
|
391
|
+
if (!this.imageData)
|
|
392
|
+
throw new Error("No image loaded");
|
|
393
|
+
if (!overlay.imageData)
|
|
394
|
+
throw new Error("Overlay has no image loaded");
|
|
395
|
+
this.imageData.data = (0, image_processing_js_1.composite)(this.imageData.data, this.imageData.width, this.imageData.height, overlay.imageData.data, overlay.imageData.width, overlay.imageData.height, x, y, opacity);
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Adjust brightness of the image
|
|
400
|
+
* @param amount Brightness adjustment (-1 to 1, where 0 is no change)
|
|
401
|
+
* @returns This image instance for chaining
|
|
402
|
+
*/
|
|
403
|
+
brightness(amount) {
|
|
404
|
+
if (!this.imageData)
|
|
405
|
+
throw new Error("No image loaded");
|
|
406
|
+
this.imageData.data = (0, image_processing_js_1.adjustBrightness)(this.imageData.data, amount);
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Adjust contrast of the image
|
|
411
|
+
* @param amount Contrast adjustment (-1 to 1, where 0 is no change)
|
|
412
|
+
* @returns This image instance for chaining
|
|
413
|
+
*/
|
|
414
|
+
contrast(amount) {
|
|
415
|
+
if (!this.imageData)
|
|
416
|
+
throw new Error("No image loaded");
|
|
417
|
+
this.imageData.data = (0, image_processing_js_1.adjustContrast)(this.imageData.data, amount);
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Adjust exposure of the image
|
|
422
|
+
* @param amount Exposure adjustment in stops (-3 to 3, where 0 is no change)
|
|
423
|
+
* @returns This image instance for chaining
|
|
424
|
+
*/
|
|
425
|
+
exposure(amount) {
|
|
426
|
+
if (!this.imageData)
|
|
427
|
+
throw new Error("No image loaded");
|
|
428
|
+
this.imageData.data = (0, image_processing_js_1.adjustExposure)(this.imageData.data, amount);
|
|
429
|
+
return this;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Adjust saturation of the image
|
|
433
|
+
* @param amount Saturation adjustment (-1 to 1, where 0 is no change)
|
|
434
|
+
* @returns This image instance for chaining
|
|
435
|
+
*/
|
|
436
|
+
saturation(amount) {
|
|
437
|
+
if (!this.imageData)
|
|
438
|
+
throw new Error("No image loaded");
|
|
439
|
+
this.imageData.data = (0, image_processing_js_1.adjustSaturation)(this.imageData.data, amount);
|
|
440
|
+
return this;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Invert colors of the image
|
|
444
|
+
* @returns This image instance for chaining
|
|
445
|
+
*/
|
|
446
|
+
invert() {
|
|
447
|
+
if (!this.imageData)
|
|
448
|
+
throw new Error("No image loaded");
|
|
449
|
+
this.imageData.data = (0, image_processing_js_1.invert)(this.imageData.data);
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Convert the image to grayscale
|
|
454
|
+
* @returns This image instance for chaining
|
|
455
|
+
*/
|
|
456
|
+
grayscale() {
|
|
457
|
+
if (!this.imageData)
|
|
458
|
+
throw new Error("No image loaded");
|
|
459
|
+
this.imageData.data = (0, image_processing_js_1.grayscale)(this.imageData.data);
|
|
460
|
+
return this;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Fill a rectangular region with a color
|
|
464
|
+
* @param x Starting X position
|
|
465
|
+
* @param y Starting Y position
|
|
466
|
+
* @param width Width of the fill region
|
|
467
|
+
* @param height Height of the fill region
|
|
468
|
+
* @param r Red component (0-255)
|
|
469
|
+
* @param g Green component (0-255)
|
|
470
|
+
* @param b Blue component (0-255)
|
|
471
|
+
* @param a Alpha component (0-255, default: 255)
|
|
472
|
+
* @returns This image instance for chaining
|
|
473
|
+
*/
|
|
474
|
+
fillRect(x, y, width, height, r, g, b, a = 255) {
|
|
475
|
+
if (!this.imageData)
|
|
476
|
+
throw new Error("No image loaded");
|
|
477
|
+
this.imageData.data = (0, image_processing_js_1.fillRect)(this.imageData.data, this.imageData.width, this.imageData.height, x, y, width, height, r, g, b, a);
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Crop the image to a rectangular region
|
|
482
|
+
* @param x Starting X position
|
|
483
|
+
* @param y Starting Y position
|
|
484
|
+
* @param width Width of the crop region
|
|
485
|
+
* @param height Height of the crop region
|
|
486
|
+
* @returns This image instance for chaining
|
|
487
|
+
*/
|
|
488
|
+
crop(x, y, width, height) {
|
|
489
|
+
if (!this.imageData)
|
|
490
|
+
throw new Error("No image loaded");
|
|
491
|
+
const result = (0, image_processing_js_1.crop)(this.imageData.data, this.imageData.width, this.imageData.height, x, y, width, height);
|
|
492
|
+
this.imageData.width = result.width;
|
|
493
|
+
this.imageData.height = result.height;
|
|
494
|
+
this.imageData.data = result.data;
|
|
495
|
+
// Update physical dimensions if DPI is set
|
|
496
|
+
if (this.imageData.metadata) {
|
|
497
|
+
const metadata = this.imageData.metadata;
|
|
498
|
+
if (metadata.dpiX) {
|
|
499
|
+
this.imageData.metadata.physicalWidth = result.width / metadata.dpiX;
|
|
500
|
+
}
|
|
501
|
+
if (metadata.dpiY) {
|
|
502
|
+
this.imageData.metadata.physicalHeight = result.height / metadata.dpiY;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Get the pixel color at the specified position
|
|
509
|
+
* @param x X position
|
|
510
|
+
* @param y Y position
|
|
511
|
+
* @returns Object with r, g, b, a components (0-255) or undefined if out of bounds
|
|
512
|
+
*/
|
|
513
|
+
getPixel(x, y) {
|
|
514
|
+
if (!this.imageData)
|
|
515
|
+
throw new Error("No image loaded");
|
|
516
|
+
if (x < 0 || x >= this.imageData.width || y < 0 || y >= this.imageData.height) {
|
|
517
|
+
return undefined;
|
|
518
|
+
}
|
|
519
|
+
const idx = (y * this.imageData.width + x) * 4;
|
|
520
|
+
return {
|
|
521
|
+
r: this.imageData.data[idx],
|
|
522
|
+
g: this.imageData.data[idx + 1],
|
|
523
|
+
b: this.imageData.data[idx + 2],
|
|
524
|
+
a: this.imageData.data[idx + 3],
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Set the pixel color at the specified position
|
|
529
|
+
* @param x X position
|
|
530
|
+
* @param y Y position
|
|
531
|
+
* @param r Red component (0-255)
|
|
532
|
+
* @param g Green component (0-255)
|
|
533
|
+
* @param b Blue component (0-255)
|
|
534
|
+
* @param a Alpha component (0-255, default: 255)
|
|
535
|
+
* @returns This image instance for chaining
|
|
536
|
+
*/
|
|
537
|
+
setPixel(x, y, r, g, b, a = 255) {
|
|
538
|
+
if (!this.imageData)
|
|
539
|
+
throw new Error("No image loaded");
|
|
540
|
+
if (x < 0 || x >= this.imageData.width || y < 0 || y >= this.imageData.height) {
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
543
|
+
const idx = (y * this.imageData.width + x) * 4;
|
|
544
|
+
this.imageData.data[idx] = r;
|
|
545
|
+
this.imageData.data[idx + 1] = g;
|
|
546
|
+
this.imageData.data[idx + 2] = b;
|
|
547
|
+
this.imageData.data[idx + 3] = a;
|
|
548
|
+
return this;
|
|
549
|
+
}
|
|
313
550
|
}
|
|
314
551
|
exports.Image = Image;
|
|
315
552
|
Object.defineProperty(Image, "formats", {
|
|
@@ -323,7 +560,9 @@ Object.defineProperty(Image, "formats", {
|
|
|
323
560
|
new gif_js_1.GIFFormat(),
|
|
324
561
|
new tiff_js_1.TIFFFormat(),
|
|
325
562
|
new bmp_js_1.BMPFormat(),
|
|
326
|
-
new
|
|
563
|
+
new dng_js_1.DNGFormat(),
|
|
564
|
+
new pam_js_1.PAMFormat(),
|
|
565
|
+
new pcx_js_1.PCXFormat(),
|
|
327
566
|
new ascii_js_1.ASCIIFormat(),
|
|
328
567
|
]
|
|
329
568
|
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image processing utilities for common operations like compositing,
|
|
3
|
+
* level adjustments, and color manipulations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Composite one image on top of another at a specified position
|
|
7
|
+
* @param base Base image data (RGBA)
|
|
8
|
+
* @param baseWidth Base image width
|
|
9
|
+
* @param baseHeight Base image height
|
|
10
|
+
* @param overlay Overlay image data (RGBA)
|
|
11
|
+
* @param overlayWidth Overlay image width
|
|
12
|
+
* @param overlayHeight Overlay image height
|
|
13
|
+
* @param x X position to place overlay (can be negative)
|
|
14
|
+
* @param y Y position to place overlay (can be negative)
|
|
15
|
+
* @param opacity Opacity of overlay (0-1, default: 1)
|
|
16
|
+
* @returns New image data with overlay composited on base
|
|
17
|
+
*/
|
|
18
|
+
export declare function composite(base: Uint8Array, baseWidth: number, baseHeight: number, overlay: Uint8Array, overlayWidth: number, overlayHeight: number, x: number, y: number, opacity?: number): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Adjust brightness of an image
|
|
21
|
+
* @param data Image data (RGBA)
|
|
22
|
+
* @param amount Brightness adjustment (-1 to 1, where 0 is no change)
|
|
23
|
+
* @returns New image data with adjusted brightness
|
|
24
|
+
*/
|
|
25
|
+
export declare function adjustBrightness(data: Uint8Array, amount: number): Uint8Array;
|
|
26
|
+
/**
|
|
27
|
+
* Adjust contrast of an image
|
|
28
|
+
* @param data Image data (RGBA)
|
|
29
|
+
* @param amount Contrast adjustment (-1 to 1, where 0 is no change)
|
|
30
|
+
* @returns New image data with adjusted contrast
|
|
31
|
+
*/
|
|
32
|
+
export declare function adjustContrast(data: Uint8Array, amount: number): Uint8Array;
|
|
33
|
+
/**
|
|
34
|
+
* Adjust exposure of an image
|
|
35
|
+
* @param data Image data (RGBA)
|
|
36
|
+
* @param amount Exposure adjustment in stops (-3 to 3, where 0 is no change)
|
|
37
|
+
* @returns New image data with adjusted exposure
|
|
38
|
+
*/
|
|
39
|
+
export declare function adjustExposure(data: Uint8Array, amount: number): Uint8Array;
|
|
40
|
+
/**
|
|
41
|
+
* Adjust saturation of an image
|
|
42
|
+
* @param data Image data (RGBA)
|
|
43
|
+
* @param amount Saturation adjustment (-1 to 1, where 0 is no change)
|
|
44
|
+
* @returns New image data with adjusted saturation
|
|
45
|
+
*/
|
|
46
|
+
export declare function adjustSaturation(data: Uint8Array, amount: number): Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* Invert colors of an image
|
|
49
|
+
* @param data Image data (RGBA)
|
|
50
|
+
* @returns New image data with inverted colors
|
|
51
|
+
*/
|
|
52
|
+
export declare function invert(data: Uint8Array): Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* Convert image to grayscale
|
|
55
|
+
* @param data Image data (RGBA)
|
|
56
|
+
* @returns New image data in grayscale
|
|
57
|
+
*/
|
|
58
|
+
export declare function grayscale(data: Uint8Array): Uint8Array;
|
|
59
|
+
/**
|
|
60
|
+
* Fill a rectangular region with a color
|
|
61
|
+
* @param data Image data (RGBA)
|
|
62
|
+
* @param width Image width
|
|
63
|
+
* @param height Image height
|
|
64
|
+
* @param x Starting X position
|
|
65
|
+
* @param y Starting Y position
|
|
66
|
+
* @param fillWidth Width of the fill region
|
|
67
|
+
* @param fillHeight Height of the fill region
|
|
68
|
+
* @param r Red component (0-255)
|
|
69
|
+
* @param g Green component (0-255)
|
|
70
|
+
* @param b Blue component (0-255)
|
|
71
|
+
* @param a Alpha component (0-255)
|
|
72
|
+
* @returns Modified image data
|
|
73
|
+
*/
|
|
74
|
+
export declare function fillRect(data: Uint8Array, width: number, height: number, x: number, y: number, fillWidth: number, fillHeight: number, r: number, g: number, b: number, a: number): Uint8Array;
|
|
75
|
+
/**
|
|
76
|
+
* Crop an image to a rectangular region
|
|
77
|
+
* @param data Image data (RGBA)
|
|
78
|
+
* @param width Image width
|
|
79
|
+
* @param height Image height
|
|
80
|
+
* @param x Starting X position
|
|
81
|
+
* @param y Starting Y position
|
|
82
|
+
* @param cropWidth Width of the crop region
|
|
83
|
+
* @param cropHeight Height of the crop region
|
|
84
|
+
* @returns Cropped image data and dimensions
|
|
85
|
+
*/
|
|
86
|
+
export declare function crop(data: Uint8Array, width: number, height: number, x: number, y: number, cropWidth: number, cropHeight: number): {
|
|
87
|
+
data: Uint8Array;
|
|
88
|
+
width: number;
|
|
89
|
+
height: number;
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=image_processing.d.ts.map
|