cross-image 0.2.0 → 0.2.2

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.
Files changed (62) hide show
  1. package/README.md +41 -28
  2. package/esm/mod.d.ts +4 -1
  3. package/esm/mod.js +4 -1
  4. package/esm/src/formats/apng.d.ts +50 -0
  5. package/esm/src/formats/apng.js +364 -0
  6. package/esm/src/formats/bmp.d.ts +0 -6
  7. package/esm/src/formats/bmp.js +24 -47
  8. package/esm/src/formats/dng.js +4 -4
  9. package/esm/src/formats/gif.d.ts +0 -2
  10. package/esm/src/formats/gif.js +10 -16
  11. package/esm/src/formats/ico.d.ts +41 -0
  12. package/esm/src/formats/ico.js +214 -0
  13. package/esm/src/formats/pcx.js +1 -1
  14. package/esm/src/formats/png.d.ts +2 -21
  15. package/esm/src/formats/png.js +5 -429
  16. package/esm/src/formats/png_base.d.ts +108 -0
  17. package/esm/src/formats/png_base.js +487 -0
  18. package/esm/src/formats/ppm.d.ts +50 -0
  19. package/esm/src/formats/ppm.js +242 -0
  20. package/esm/src/formats/tiff.d.ts +4 -0
  21. package/esm/src/formats/tiff.js +163 -44
  22. package/esm/src/formats/webp.d.ts +0 -1
  23. package/esm/src/formats/webp.js +4 -7
  24. package/esm/src/image.d.ts +30 -0
  25. package/esm/src/image.js +62 -1
  26. package/esm/src/utils/byte_utils.d.ts +30 -0
  27. package/esm/src/utils/byte_utils.js +50 -0
  28. package/esm/src/utils/gif_encoder.d.ts +3 -2
  29. package/esm/src/utils/gif_encoder.js +115 -48
  30. package/esm/src/utils/image_processing.d.ts +43 -0
  31. package/esm/src/utils/image_processing.js +230 -0
  32. package/package.json +1 -1
  33. package/script/mod.d.ts +4 -1
  34. package/script/mod.js +8 -2
  35. package/script/src/formats/apng.d.ts +50 -0
  36. package/script/src/formats/apng.js +368 -0
  37. package/script/src/formats/bmp.d.ts +0 -6
  38. package/script/src/formats/bmp.js +24 -47
  39. package/script/src/formats/dng.js +4 -4
  40. package/script/src/formats/gif.d.ts +0 -2
  41. package/script/src/formats/gif.js +10 -16
  42. package/script/src/formats/ico.d.ts +41 -0
  43. package/script/src/formats/ico.js +218 -0
  44. package/script/src/formats/pcx.js +1 -1
  45. package/script/src/formats/png.d.ts +2 -21
  46. package/script/src/formats/png.js +5 -429
  47. package/script/src/formats/png_base.d.ts +108 -0
  48. package/script/src/formats/png_base.js +491 -0
  49. package/script/src/formats/ppm.d.ts +50 -0
  50. package/script/src/formats/ppm.js +246 -0
  51. package/script/src/formats/tiff.d.ts +4 -0
  52. package/script/src/formats/tiff.js +163 -44
  53. package/script/src/formats/webp.d.ts +0 -1
  54. package/script/src/formats/webp.js +4 -7
  55. package/script/src/image.d.ts +30 -0
  56. package/script/src/image.js +61 -0
  57. package/script/src/utils/byte_utils.d.ts +30 -0
  58. package/script/src/utils/byte_utils.js +58 -0
  59. package/script/src/utils/gif_encoder.d.ts +3 -2
  60. package/script/src/utils/gif_encoder.js +115 -48
  61. package/script/src/utils/image_processing.d.ts +43 -0
  62. package/script/src/utils/image_processing.js +235 -0
@@ -0,0 +1,491 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PNGBase = void 0;
4
+ // Constants for unit conversions
5
+ const INCHES_PER_METER = 39.3701;
6
+ /**
7
+ * Base class for PNG and APNG format handlers
8
+ * Contains shared utility methods for PNG chunk manipulation and metadata parsing
9
+ */
10
+ class PNGBase {
11
+ /**
12
+ * Read a 32-bit unsigned integer (big-endian)
13
+ */
14
+ readUint32(data, offset) {
15
+ return (data[offset] << 24) | (data[offset + 1] << 16) |
16
+ (data[offset + 2] << 8) | data[offset + 3];
17
+ }
18
+ /**
19
+ * Read a 16-bit unsigned integer (big-endian)
20
+ */
21
+ readUint16(data, offset) {
22
+ return (data[offset] << 8) | data[offset + 1];
23
+ }
24
+ /**
25
+ * Write a 32-bit unsigned integer (big-endian)
26
+ */
27
+ writeUint32(data, offset, value) {
28
+ data[offset] = (value >>> 24) & 0xff;
29
+ data[offset + 1] = (value >>> 16) & 0xff;
30
+ data[offset + 2] = (value >>> 8) & 0xff;
31
+ data[offset + 3] = value & 0xff;
32
+ }
33
+ /**
34
+ * Write a 16-bit unsigned integer (big-endian)
35
+ */
36
+ writeUint16(data, offset, value) {
37
+ data[offset] = (value >>> 8) & 0xff;
38
+ data[offset + 1] = value & 0xff;
39
+ }
40
+ /**
41
+ * Decompress PNG data using deflate
42
+ */
43
+ async inflate(data) {
44
+ const stream = new Response(data).body
45
+ .pipeThrough(new DecompressionStream("deflate"));
46
+ const decompressed = await new Response(stream).arrayBuffer();
47
+ return new Uint8Array(decompressed);
48
+ }
49
+ /**
50
+ * Compress PNG data using deflate
51
+ */
52
+ async deflate(data) {
53
+ const stream = new Response(data).body
54
+ .pipeThrough(new CompressionStream("deflate"));
55
+ const compressed = await new Response(stream).arrayBuffer();
56
+ return new Uint8Array(compressed);
57
+ }
58
+ /**
59
+ * Unfilter PNG scanlines and convert to RGBA
60
+ */
61
+ unfilterAndConvert(data, width, height, bitDepth, colorType) {
62
+ const rgba = new Uint8Array(width * height * 4);
63
+ const bytesPerPixel = this.getBytesPerPixel(colorType, bitDepth);
64
+ const scanlineLength = width * bytesPerPixel;
65
+ let dataPos = 0;
66
+ const scanlines = [];
67
+ for (let y = 0; y < height; y++) {
68
+ const filterType = data[dataPos++];
69
+ const scanline = new Uint8Array(scanlineLength);
70
+ for (let x = 0; x < scanlineLength; x++) {
71
+ scanline[x] = data[dataPos++];
72
+ }
73
+ this.unfilterScanline(scanline, y > 0 ? scanlines[y - 1] : null, filterType, bytesPerPixel);
74
+ scanlines.push(scanline);
75
+ // Convert to RGBA
76
+ for (let x = 0; x < width; x++) {
77
+ const outIdx = (y * width + x) * 4;
78
+ if (colorType === 6) { // RGBA
79
+ rgba[outIdx] = scanline[x * 4];
80
+ rgba[outIdx + 1] = scanline[x * 4 + 1];
81
+ rgba[outIdx + 2] = scanline[x * 4 + 2];
82
+ rgba[outIdx + 3] = scanline[x * 4 + 3];
83
+ }
84
+ else if (colorType === 2) { // RGB
85
+ rgba[outIdx] = scanline[x * 3];
86
+ rgba[outIdx + 1] = scanline[x * 3 + 1];
87
+ rgba[outIdx + 2] = scanline[x * 3 + 2];
88
+ rgba[outIdx + 3] = 255;
89
+ }
90
+ else if (colorType === 0) { // Grayscale
91
+ const gray = scanline[x];
92
+ rgba[outIdx] = gray;
93
+ rgba[outIdx + 1] = gray;
94
+ rgba[outIdx + 2] = gray;
95
+ rgba[outIdx + 3] = 255;
96
+ }
97
+ else {
98
+ throw new Error(`Unsupported PNG color type: ${colorType}`);
99
+ }
100
+ }
101
+ }
102
+ return rgba;
103
+ }
104
+ /**
105
+ * Unfilter a single PNG scanline
106
+ */
107
+ unfilterScanline(scanline, prevLine, filterType, bytesPerPixel) {
108
+ for (let x = 0; x < scanline.length; x++) {
109
+ const left = x >= bytesPerPixel ? scanline[x - bytesPerPixel] : 0;
110
+ const above = prevLine ? prevLine[x] : 0;
111
+ const upperLeft = (x >= bytesPerPixel && prevLine)
112
+ ? prevLine[x - bytesPerPixel]
113
+ : 0;
114
+ switch (filterType) {
115
+ case 0: // None
116
+ break;
117
+ case 1: // Sub
118
+ scanline[x] = (scanline[x] + left) & 0xff;
119
+ break;
120
+ case 2: // Up
121
+ scanline[x] = (scanline[x] + above) & 0xff;
122
+ break;
123
+ case 3: // Average
124
+ scanline[x] = (scanline[x] + Math.floor((left + above) / 2)) & 0xff;
125
+ break;
126
+ case 4: // Paeth
127
+ scanline[x] =
128
+ (scanline[x] + this.paethPredictor(left, above, upperLeft)) & 0xff;
129
+ break;
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ * Paeth predictor for PNG filtering
135
+ */
136
+ paethPredictor(a, b, c) {
137
+ const p = a + b - c;
138
+ const pa = Math.abs(p - a);
139
+ const pb = Math.abs(p - b);
140
+ const pc = Math.abs(p - c);
141
+ if (pa <= pb && pa <= pc)
142
+ return a;
143
+ if (pb <= pc)
144
+ return b;
145
+ return c;
146
+ }
147
+ /**
148
+ * Filter PNG data for encoding (using filter type 0 - None)
149
+ */
150
+ filterData(data, width, height) {
151
+ // Use filter type 0 (None) for simplicity
152
+ const filtered = new Uint8Array(height * (1 + width * 4));
153
+ let pos = 0;
154
+ for (let y = 0; y < height; y++) {
155
+ filtered[pos++] = 0; // Filter type: None
156
+ for (let x = 0; x < width * 4; x++) {
157
+ filtered[pos++] = data[y * width * 4 + x];
158
+ }
159
+ }
160
+ return filtered;
161
+ }
162
+ /**
163
+ * Get bytes per pixel for a given color type and bit depth
164
+ */
165
+ getBytesPerPixel(colorType, bitDepth) {
166
+ const bitsPerPixel = this.getBitsPerPixel(colorType, bitDepth);
167
+ return Math.ceil(bitsPerPixel / 8);
168
+ }
169
+ /**
170
+ * Get bits per pixel for a given color type and bit depth
171
+ */
172
+ getBitsPerPixel(colorType, bitDepth) {
173
+ switch (colorType) {
174
+ case 0: // Grayscale
175
+ return bitDepth;
176
+ case 2: // RGB
177
+ return bitDepth * 3;
178
+ case 3: // Palette
179
+ return bitDepth;
180
+ case 4: // Grayscale + Alpha
181
+ return bitDepth * 2;
182
+ case 6: // RGBA
183
+ return bitDepth * 4;
184
+ default:
185
+ throw new Error(`Unknown color type: ${colorType}`);
186
+ }
187
+ }
188
+ /**
189
+ * Create a PNG chunk with length, type, data, and CRC
190
+ */
191
+ createChunk(type, data) {
192
+ const chunk = new Uint8Array(12 + data.length);
193
+ this.writeUint32(chunk, 0, data.length);
194
+ chunk[4] = type.charCodeAt(0);
195
+ chunk[5] = type.charCodeAt(1);
196
+ chunk[6] = type.charCodeAt(2);
197
+ chunk[7] = type.charCodeAt(3);
198
+ chunk.set(data, 8);
199
+ const crc = this.crc32(chunk.slice(4, 8 + data.length));
200
+ this.writeUint32(chunk, 8 + data.length, crc);
201
+ return chunk;
202
+ }
203
+ /**
204
+ * Calculate CRC32 checksum
205
+ */
206
+ crc32(data) {
207
+ let crc = 0xffffffff;
208
+ for (let i = 0; i < data.length; i++) {
209
+ crc ^= data[i];
210
+ for (let j = 0; j < 8; j++) {
211
+ crc = (crc & 1) ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;
212
+ }
213
+ }
214
+ return (crc ^ 0xffffffff) >>> 0;
215
+ }
216
+ // Metadata parsing methods
217
+ /**
218
+ * Parse pHYs (physical pixel dimensions) chunk
219
+ */
220
+ parsePhysChunk(data, metadata, width, height) {
221
+ if (data.length < 9)
222
+ return;
223
+ const pixelsPerUnitX = this.readUint32(data, 0);
224
+ const pixelsPerUnitY = this.readUint32(data, 4);
225
+ const unit = data[8];
226
+ if (unit === 1 && pixelsPerUnitX > 0 && pixelsPerUnitY > 0) {
227
+ metadata.dpiX = Math.round(pixelsPerUnitX / INCHES_PER_METER);
228
+ metadata.dpiY = Math.round(pixelsPerUnitY / INCHES_PER_METER);
229
+ metadata.physicalWidth = width / metadata.dpiX;
230
+ metadata.physicalHeight = height / metadata.dpiY;
231
+ }
232
+ }
233
+ /**
234
+ * Parse tEXt (text) chunk
235
+ */
236
+ parseTextChunk(data, metadata) {
237
+ const nullIndex = data.indexOf(0);
238
+ if (nullIndex === -1)
239
+ return;
240
+ const keyword = new TextDecoder().decode(data.slice(0, nullIndex));
241
+ const text = new TextDecoder().decode(data.slice(nullIndex + 1));
242
+ switch (keyword.toLowerCase()) {
243
+ case "title":
244
+ metadata.title = text;
245
+ break;
246
+ case "author":
247
+ metadata.author = text;
248
+ break;
249
+ case "description":
250
+ metadata.description = text;
251
+ break;
252
+ case "copyright":
253
+ metadata.copyright = text;
254
+ break;
255
+ default:
256
+ if (!metadata.custom)
257
+ metadata.custom = {};
258
+ metadata.custom[keyword] = text;
259
+ }
260
+ }
261
+ /**
262
+ * Parse iTXt (international text) chunk
263
+ */
264
+ parseITxtChunk(data, metadata) {
265
+ let pos = 0;
266
+ const nullIndex = data.indexOf(0, pos);
267
+ if (nullIndex === -1 || pos >= data.length)
268
+ return;
269
+ const keyword = new TextDecoder().decode(data.slice(pos, nullIndex));
270
+ pos = nullIndex + 1;
271
+ if (pos + 2 > data.length)
272
+ return;
273
+ pos += 2; // Skip compression flag and method
274
+ const languageNullIndex = data.indexOf(0, pos);
275
+ if (languageNullIndex === -1 || pos >= data.length)
276
+ return;
277
+ pos = languageNullIndex + 1;
278
+ const translatedKeywordNullIndex = data.indexOf(0, pos);
279
+ if (translatedKeywordNullIndex === -1 || pos >= data.length)
280
+ return;
281
+ pos = translatedKeywordNullIndex + 1;
282
+ if (pos >= data.length)
283
+ return;
284
+ const text = new TextDecoder("utf-8").decode(data.slice(pos));
285
+ switch (keyword.toLowerCase()) {
286
+ case "title":
287
+ metadata.title = text;
288
+ break;
289
+ case "author":
290
+ metadata.author = text;
291
+ break;
292
+ case "description":
293
+ metadata.description = text;
294
+ break;
295
+ case "copyright":
296
+ metadata.copyright = text;
297
+ break;
298
+ default:
299
+ if (!metadata.custom)
300
+ metadata.custom = {};
301
+ metadata.custom[keyword] = text;
302
+ }
303
+ }
304
+ /**
305
+ * Parse eXIf (EXIF) chunk
306
+ */
307
+ parseExifChunk(data, metadata) {
308
+ if (data.length < 8)
309
+ return;
310
+ try {
311
+ const byteOrder = String.fromCharCode(data[0], data[1]);
312
+ const littleEndian = byteOrder === "II";
313
+ const ifd0Offset = littleEndian
314
+ ? data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24)
315
+ : (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
316
+ if (ifd0Offset + 2 > data.length)
317
+ return;
318
+ const numEntries = littleEndian
319
+ ? data[ifd0Offset] | (data[ifd0Offset + 1] << 8)
320
+ : (data[ifd0Offset] << 8) | data[ifd0Offset + 1];
321
+ for (let i = 0; i < numEntries; i++) {
322
+ const entryOffset = ifd0Offset + 2 + i * 12;
323
+ if (entryOffset + 12 > data.length)
324
+ break;
325
+ const tag = littleEndian
326
+ ? data[entryOffset] | (data[entryOffset + 1] << 8)
327
+ : (data[entryOffset] << 8) | data[entryOffset + 1];
328
+ if (tag === 0x0132) {
329
+ const valueOffset = littleEndian
330
+ ? data[entryOffset + 8] | (data[entryOffset + 9] << 8) |
331
+ (data[entryOffset + 10] << 16) | (data[entryOffset + 11] << 24)
332
+ : (data[entryOffset + 8] << 24) | (data[entryOffset + 9] << 16) |
333
+ (data[entryOffset + 10] << 8) | data[entryOffset + 11];
334
+ if (valueOffset < data.length) {
335
+ const nullIndex = data.indexOf(0, valueOffset);
336
+ if (nullIndex > valueOffset) {
337
+ const dateStr = new TextDecoder().decode(data.slice(valueOffset, nullIndex));
338
+ const match = dateStr.match(/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
339
+ if (match) {
340
+ metadata.creationDate = new Date(parseInt(match[1]), parseInt(match[2]) - 1, parseInt(match[3]), parseInt(match[4]), parseInt(match[5]), parseInt(match[6]));
341
+ }
342
+ }
343
+ }
344
+ }
345
+ }
346
+ }
347
+ catch (_e) {
348
+ // Ignore EXIF parsing errors
349
+ }
350
+ }
351
+ /**
352
+ * Create pHYs (physical pixel dimensions) chunk
353
+ */
354
+ createPhysChunk(metadata) {
355
+ const chunk = new Uint8Array(9);
356
+ const dpiX = metadata.dpiX ?? 72;
357
+ const dpiY = metadata.dpiY ?? 72;
358
+ const pixelsPerMeterX = Math.round(dpiX * INCHES_PER_METER);
359
+ const pixelsPerMeterY = Math.round(dpiY * INCHES_PER_METER);
360
+ this.writeUint32(chunk, 0, pixelsPerMeterX);
361
+ this.writeUint32(chunk, 4, pixelsPerMeterY);
362
+ chunk[8] = 1;
363
+ return chunk;
364
+ }
365
+ /**
366
+ * Create tEXt (text) chunk
367
+ */
368
+ createTextChunk(keyword, text) {
369
+ const keywordBytes = new TextEncoder().encode(keyword);
370
+ const textBytes = new TextEncoder().encode(text);
371
+ const chunk = new Uint8Array(keywordBytes.length + 1 + textBytes.length);
372
+ chunk.set(keywordBytes, 0);
373
+ chunk[keywordBytes.length] = 0;
374
+ chunk.set(textBytes, keywordBytes.length + 1);
375
+ return chunk;
376
+ }
377
+ /**
378
+ * Create eXIf (EXIF) chunk
379
+ */
380
+ createExifChunk(metadata) {
381
+ const entries = [];
382
+ if (metadata.creationDate) {
383
+ const date = metadata.creationDate;
384
+ const dateStr = `${date.getFullYear()}:${String(date.getMonth() + 1).padStart(2, "0")}:${String(date.getDate()).padStart(2, "0")} ${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}:${String(date.getSeconds()).padStart(2, "0")}\0`;
385
+ entries.push({
386
+ tag: 0x0132,
387
+ type: 2,
388
+ value: new TextEncoder().encode(dateStr),
389
+ });
390
+ }
391
+ if (entries.length === 0)
392
+ return null;
393
+ const exif = [];
394
+ exif.push(0x49, 0x49); // "II"
395
+ exif.push(0x2a, 0x00); // 42
396
+ exif.push(0x08, 0x00, 0x00, 0x00);
397
+ exif.push(entries.length & 0xff, (entries.length >> 8) & 0xff);
398
+ let dataOffset = 8 + 2 + entries.length * 12 + 4;
399
+ for (const entry of entries) {
400
+ exif.push(entry.tag & 0xff, (entry.tag >> 8) & 0xff);
401
+ exif.push(entry.type & 0xff, (entry.type >> 8) & 0xff);
402
+ const count = entry.value.length;
403
+ exif.push(count & 0xff, (count >> 8) & 0xff, (count >> 16) & 0xff, (count >> 24) & 0xff);
404
+ if (entry.value.length <= 4) {
405
+ for (let i = 0; i < 4; i++) {
406
+ exif.push(i < entry.value.length ? entry.value[i] : 0);
407
+ }
408
+ }
409
+ else {
410
+ exif.push(dataOffset & 0xff, (dataOffset >> 8) & 0xff, (dataOffset >> 16) & 0xff, (dataOffset >> 24) & 0xff);
411
+ dataOffset += entry.value.length;
412
+ }
413
+ }
414
+ exif.push(0x00, 0x00, 0x00, 0x00);
415
+ for (const entry of entries) {
416
+ if (entry.value.length > 4) {
417
+ for (const byte of entry.value) {
418
+ exif.push(byte);
419
+ }
420
+ }
421
+ }
422
+ return new Uint8Array(exif);
423
+ }
424
+ /**
425
+ * Concatenate multiple byte arrays into a single Uint8Array
426
+ */
427
+ concatenateChunks(chunks) {
428
+ const totalLength = chunks.reduce((sum, chunk) => sum + chunk.data.length, 0);
429
+ const result = new Uint8Array(totalLength);
430
+ let offset = 0;
431
+ for (const chunk of chunks) {
432
+ result.set(chunk.data, offset);
433
+ offset += chunk.data.length;
434
+ }
435
+ return result;
436
+ }
437
+ /**
438
+ * Concatenate multiple Uint8Arrays into a single Uint8Array
439
+ */
440
+ concatenateArrays(arrays) {
441
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
442
+ const result = new Uint8Array(totalLength);
443
+ let offset = 0;
444
+ for (const arr of arrays) {
445
+ result.set(arr, offset);
446
+ offset += arr.length;
447
+ }
448
+ return result;
449
+ }
450
+ /**
451
+ * Add metadata chunks to the chunks array
452
+ * Shared method to avoid duplication between PNG and APNG encoding
453
+ */
454
+ addMetadataChunks(chunks, metadata) {
455
+ if (!metadata)
456
+ return;
457
+ // Add pHYs chunk for DPI information
458
+ if (metadata.dpiX !== undefined || metadata.dpiY !== undefined) {
459
+ const physChunk = this.createPhysChunk(metadata);
460
+ chunks.push(this.createChunk("pHYs", physChunk));
461
+ }
462
+ // Add tEXt chunks for standard metadata
463
+ if (metadata.title !== undefined) {
464
+ chunks.push(this.createChunk("tEXt", this.createTextChunk("Title", metadata.title)));
465
+ }
466
+ if (metadata.author !== undefined) {
467
+ chunks.push(this.createChunk("tEXt", this.createTextChunk("Author", metadata.author)));
468
+ }
469
+ if (metadata.description !== undefined) {
470
+ chunks.push(this.createChunk("tEXt", this.createTextChunk("Description", metadata.description)));
471
+ }
472
+ if (metadata.copyright !== undefined) {
473
+ chunks.push(this.createChunk("tEXt", this.createTextChunk("Copyright", metadata.copyright)));
474
+ }
475
+ // Add custom metadata fields
476
+ if (metadata.custom) {
477
+ for (const [key, value] of Object.entries(metadata.custom)) {
478
+ chunks.push(this.createChunk("tEXt", this.createTextChunk(key, String(value))));
479
+ }
480
+ }
481
+ // Add EXIF chunk for GPS data and creation date
482
+ if (metadata.latitude !== undefined || metadata.longitude !== undefined ||
483
+ metadata.creationDate !== undefined) {
484
+ const exifChunk = this.createExifChunk(metadata);
485
+ if (exifChunk) {
486
+ chunks.push(this.createChunk("eXIf", exifChunk));
487
+ }
488
+ }
489
+ }
490
+ }
491
+ exports.PNGBase = PNGBase;
@@ -0,0 +1,50 @@
1
+ import type { ImageData, ImageFormat } from "../types.js";
2
+ /**
3
+ * PPM format handler
4
+ * Implements the Netpbm PPM (Portable PixMap) format.
5
+ * This is a simple uncompressed RGB format supported by many image tools.
6
+ *
7
+ * Format structure:
8
+ * - P3 (ASCII format):
9
+ * P3
10
+ * <width> <height>
11
+ * <maxval>
12
+ * R G B R G B ... (space-separated decimal values)
13
+ *
14
+ * - P6 (Binary format):
15
+ * P6
16
+ * <width> <height>
17
+ * <maxval>
18
+ * RGB RGB RGB ... (binary byte data)
19
+ */
20
+ export declare class PPMFormat implements ImageFormat {
21
+ /** Format name identifier */
22
+ readonly name = "ppm";
23
+ /** MIME type for PPM images */
24
+ readonly mimeType = "image/x-portable-pixmap";
25
+ /**
26
+ * Check if the given data is a PPM image
27
+ * @param data Raw image data to check
28
+ * @returns true if data has PPM signature (P3 or P6)
29
+ */
30
+ canDecode(data: Uint8Array): boolean;
31
+ /**
32
+ * Decode PPM image data to RGBA
33
+ * Supports both P3 (ASCII) and P6 (binary) formats
34
+ * @param data Raw PPM image data
35
+ * @returns Decoded image data with RGBA pixels
36
+ */
37
+ decode(data: Uint8Array): Promise<ImageData>;
38
+ /**
39
+ * Encode RGBA image data to PPM format (P6 binary)
40
+ * Note: Alpha channel is ignored as PPM doesn't support transparency
41
+ * @param imageData Image data to encode
42
+ * @returns Encoded PPM image bytes
43
+ */
44
+ encode(imageData: ImageData): Promise<Uint8Array>;
45
+ /**
46
+ * Check if a byte is whitespace (space, tab, CR, LF)
47
+ */
48
+ private isWhitespace;
49
+ }
50
+ //# sourceMappingURL=ppm.d.ts.map