cross-image 0.1.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 (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +606 -0
  3. package/esm/mod.d.ts +33 -0
  4. package/esm/mod.d.ts.map +1 -0
  5. package/esm/mod.js +31 -0
  6. package/esm/package.json +3 -0
  7. package/esm/src/formats/ascii.d.ts +27 -0
  8. package/esm/src/formats/ascii.d.ts.map +1 -0
  9. package/esm/src/formats/ascii.js +172 -0
  10. package/esm/src/formats/bmp.d.ts +19 -0
  11. package/esm/src/formats/bmp.d.ts.map +1 -0
  12. package/esm/src/formats/bmp.js +174 -0
  13. package/esm/src/formats/gif.d.ts +40 -0
  14. package/esm/src/formats/gif.d.ts.map +1 -0
  15. package/esm/src/formats/gif.js +385 -0
  16. package/esm/src/formats/jpeg.d.ts +18 -0
  17. package/esm/src/formats/jpeg.d.ts.map +1 -0
  18. package/esm/src/formats/jpeg.js +414 -0
  19. package/esm/src/formats/png.d.ts +33 -0
  20. package/esm/src/formats/png.d.ts.map +1 -0
  21. package/esm/src/formats/png.js +544 -0
  22. package/esm/src/formats/raw.d.ts +23 -0
  23. package/esm/src/formats/raw.d.ts.map +1 -0
  24. package/esm/src/formats/raw.js +98 -0
  25. package/esm/src/formats/tiff.d.ts +58 -0
  26. package/esm/src/formats/tiff.d.ts.map +1 -0
  27. package/esm/src/formats/tiff.js +791 -0
  28. package/esm/src/formats/webp.d.ts +22 -0
  29. package/esm/src/formats/webp.d.ts.map +1 -0
  30. package/esm/src/formats/webp.js +403 -0
  31. package/esm/src/image.d.ts +124 -0
  32. package/esm/src/image.d.ts.map +1 -0
  33. package/esm/src/image.js +320 -0
  34. package/esm/src/types.d.ts +167 -0
  35. package/esm/src/types.d.ts.map +1 -0
  36. package/esm/src/types.js +1 -0
  37. package/esm/src/utils/gif_decoder.d.ts +42 -0
  38. package/esm/src/utils/gif_decoder.d.ts.map +1 -0
  39. package/esm/src/utils/gif_decoder.js +374 -0
  40. package/esm/src/utils/gif_encoder.d.ts +29 -0
  41. package/esm/src/utils/gif_encoder.d.ts.map +1 -0
  42. package/esm/src/utils/gif_encoder.js +226 -0
  43. package/esm/src/utils/jpeg_decoder.d.ts +39 -0
  44. package/esm/src/utils/jpeg_decoder.d.ts.map +1 -0
  45. package/esm/src/utils/jpeg_decoder.js +580 -0
  46. package/esm/src/utils/jpeg_encoder.d.ts +33 -0
  47. package/esm/src/utils/jpeg_encoder.d.ts.map +1 -0
  48. package/esm/src/utils/jpeg_encoder.js +1017 -0
  49. package/esm/src/utils/lzw.d.ts +43 -0
  50. package/esm/src/utils/lzw.d.ts.map +1 -0
  51. package/esm/src/utils/lzw.js +309 -0
  52. package/esm/src/utils/resize.d.ts +9 -0
  53. package/esm/src/utils/resize.d.ts.map +1 -0
  54. package/esm/src/utils/resize.js +52 -0
  55. package/esm/src/utils/tiff_lzw.d.ts +44 -0
  56. package/esm/src/utils/tiff_lzw.d.ts.map +1 -0
  57. package/esm/src/utils/tiff_lzw.js +306 -0
  58. package/esm/src/utils/webp_decoder.d.ts +39 -0
  59. package/esm/src/utils/webp_decoder.d.ts.map +1 -0
  60. package/esm/src/utils/webp_decoder.js +493 -0
  61. package/esm/src/utils/webp_encoder.d.ts +72 -0
  62. package/esm/src/utils/webp_encoder.d.ts.map +1 -0
  63. package/esm/src/utils/webp_encoder.js +627 -0
  64. package/package.json +41 -0
  65. package/script/mod.d.ts +33 -0
  66. package/script/mod.d.ts.map +1 -0
  67. package/script/mod.js +43 -0
  68. package/script/package.json +3 -0
  69. package/script/src/formats/ascii.d.ts +27 -0
  70. package/script/src/formats/ascii.d.ts.map +1 -0
  71. package/script/src/formats/ascii.js +176 -0
  72. package/script/src/formats/bmp.d.ts +19 -0
  73. package/script/src/formats/bmp.d.ts.map +1 -0
  74. package/script/src/formats/bmp.js +178 -0
  75. package/script/src/formats/gif.d.ts +40 -0
  76. package/script/src/formats/gif.d.ts.map +1 -0
  77. package/script/src/formats/gif.js +389 -0
  78. package/script/src/formats/jpeg.d.ts +18 -0
  79. package/script/src/formats/jpeg.d.ts.map +1 -0
  80. package/script/src/formats/jpeg.js +451 -0
  81. package/script/src/formats/png.d.ts +33 -0
  82. package/script/src/formats/png.d.ts.map +1 -0
  83. package/script/src/formats/png.js +548 -0
  84. package/script/src/formats/raw.d.ts +23 -0
  85. package/script/src/formats/raw.d.ts.map +1 -0
  86. package/script/src/formats/raw.js +102 -0
  87. package/script/src/formats/tiff.d.ts +58 -0
  88. package/script/src/formats/tiff.d.ts.map +1 -0
  89. package/script/src/formats/tiff.js +795 -0
  90. package/script/src/formats/webp.d.ts +22 -0
  91. package/script/src/formats/webp.d.ts.map +1 -0
  92. package/script/src/formats/webp.js +440 -0
  93. package/script/src/image.d.ts +124 -0
  94. package/script/src/image.d.ts.map +1 -0
  95. package/script/src/image.js +324 -0
  96. package/script/src/types.d.ts +167 -0
  97. package/script/src/types.d.ts.map +1 -0
  98. package/script/src/types.js +2 -0
  99. package/script/src/utils/gif_decoder.d.ts +42 -0
  100. package/script/src/utils/gif_decoder.d.ts.map +1 -0
  101. package/script/src/utils/gif_decoder.js +378 -0
  102. package/script/src/utils/gif_encoder.d.ts +29 -0
  103. package/script/src/utils/gif_encoder.d.ts.map +1 -0
  104. package/script/src/utils/gif_encoder.js +230 -0
  105. package/script/src/utils/jpeg_decoder.d.ts +39 -0
  106. package/script/src/utils/jpeg_decoder.d.ts.map +1 -0
  107. package/script/src/utils/jpeg_decoder.js +584 -0
  108. package/script/src/utils/jpeg_encoder.d.ts +33 -0
  109. package/script/src/utils/jpeg_encoder.d.ts.map +1 -0
  110. package/script/src/utils/jpeg_encoder.js +1021 -0
  111. package/script/src/utils/lzw.d.ts +43 -0
  112. package/script/src/utils/lzw.d.ts.map +1 -0
  113. package/script/src/utils/lzw.js +314 -0
  114. package/script/src/utils/resize.d.ts +9 -0
  115. package/script/src/utils/resize.d.ts.map +1 -0
  116. package/script/src/utils/resize.js +56 -0
  117. package/script/src/utils/tiff_lzw.d.ts +44 -0
  118. package/script/src/utils/tiff_lzw.d.ts.map +1 -0
  119. package/script/src/utils/tiff_lzw.js +311 -0
  120. package/script/src/utils/webp_decoder.d.ts +39 -0
  121. package/script/src/utils/webp_decoder.d.ts.map +1 -0
  122. package/script/src/utils/webp_decoder.js +497 -0
  123. package/script/src/utils/webp_encoder.d.ts +72 -0
  124. package/script/src/utils/webp_encoder.d.ts.map +1 -0
  125. package/script/src/utils/webp_encoder.js +631 -0
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Image = void 0;
4
+ const resize_js_1 = require("./utils/resize.js");
5
+ const png_js_1 = require("./formats/png.js");
6
+ const jpeg_js_1 = require("./formats/jpeg.js");
7
+ const webp_js_1 = require("./formats/webp.js");
8
+ const gif_js_1 = require("./formats/gif.js");
9
+ const tiff_js_1 = require("./formats/tiff.js");
10
+ const bmp_js_1 = require("./formats/bmp.js");
11
+ const raw_js_1 = require("./formats/raw.js");
12
+ const ascii_js_1 = require("./formats/ascii.js");
13
+ /**
14
+ * Main Image class for reading, manipulating, and saving images
15
+ */
16
+ class Image {
17
+ constructor() {
18
+ Object.defineProperty(this, "imageData", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: null
23
+ });
24
+ }
25
+ /**
26
+ * Get the current image width
27
+ */
28
+ get width() {
29
+ if (!this.imageData)
30
+ throw new Error("No image loaded");
31
+ return this.imageData.width;
32
+ }
33
+ /**
34
+ * Get the current image height
35
+ */
36
+ get height() {
37
+ if (!this.imageData)
38
+ throw new Error("No image loaded");
39
+ return this.imageData.height;
40
+ }
41
+ /**
42
+ * Get the current image data
43
+ */
44
+ get data() {
45
+ if (!this.imageData)
46
+ throw new Error("No image loaded");
47
+ return this.imageData.data;
48
+ }
49
+ /**
50
+ * Get the current image metadata
51
+ */
52
+ get metadata() {
53
+ if (!this.imageData)
54
+ throw new Error("No image loaded");
55
+ return this.imageData.metadata;
56
+ }
57
+ /**
58
+ * Set or update image metadata
59
+ * @param metadata Metadata to set or merge
60
+ * @param merge If true, merges with existing metadata. If false, replaces it. Default: true
61
+ */
62
+ setMetadata(metadata, merge = true) {
63
+ if (!this.imageData)
64
+ throw new Error("No image loaded");
65
+ if (merge && this.imageData.metadata) {
66
+ this.imageData.metadata = {
67
+ ...this.imageData.metadata,
68
+ ...metadata,
69
+ custom: {
70
+ ...(this.imageData.metadata.custom || {}),
71
+ ...(metadata.custom || {}),
72
+ },
73
+ };
74
+ }
75
+ else {
76
+ this.imageData.metadata = { ...metadata };
77
+ }
78
+ return this;
79
+ }
80
+ /**
81
+ * Get a specific metadata field
82
+ * @param key The metadata field to retrieve
83
+ * @returns The metadata value or undefined
84
+ */
85
+ getMetadataField(key) {
86
+ if (!this.imageData)
87
+ throw new Error("No image loaded");
88
+ return this.imageData.metadata?.[key];
89
+ }
90
+ /**
91
+ * Get position (latitude, longitude) from metadata
92
+ * @returns Object with latitude and longitude, or undefined if not available
93
+ */
94
+ getPosition() {
95
+ const latitude = this.getMetadataField("latitude");
96
+ const longitude = this.getMetadataField("longitude");
97
+ if (latitude !== undefined && longitude !== undefined) {
98
+ return { latitude, longitude };
99
+ }
100
+ return undefined;
101
+ }
102
+ /**
103
+ * Set position (latitude, longitude) in metadata
104
+ * @param latitude GPS latitude
105
+ * @param longitude GPS longitude
106
+ */
107
+ setPosition(latitude, longitude) {
108
+ return this.setMetadata({ latitude, longitude });
109
+ }
110
+ /**
111
+ * Get physical dimensions from metadata
112
+ * @returns Object with DPI and physical dimensions, or undefined if not available
113
+ */
114
+ getDimensions() {
115
+ const dpiX = this.getMetadataField("dpiX");
116
+ const dpiY = this.getMetadataField("dpiY");
117
+ const physicalWidth = this.getMetadataField("physicalWidth");
118
+ const physicalHeight = this.getMetadataField("physicalHeight");
119
+ if (dpiX !== undefined || dpiY !== undefined || physicalWidth !== undefined ||
120
+ physicalHeight !== undefined) {
121
+ return { dpiX, dpiY, physicalWidth, physicalHeight };
122
+ }
123
+ return undefined;
124
+ }
125
+ /**
126
+ * Set physical dimensions in metadata
127
+ * @param dpiX Dots per inch (horizontal)
128
+ * @param dpiY Dots per inch (vertical), defaults to dpiX if not provided
129
+ */
130
+ setDPI(dpiX, dpiY) {
131
+ const actualDpiY = dpiY ?? dpiX;
132
+ // Calculate physical dimensions based on pixel dimensions and DPI
133
+ const physicalWidth = this.width / dpiX;
134
+ const physicalHeight = this.height / actualDpiY;
135
+ return this.setMetadata({
136
+ dpiX,
137
+ dpiY: actualDpiY,
138
+ physicalWidth,
139
+ physicalHeight,
140
+ });
141
+ }
142
+ /**
143
+ * Register a custom image format
144
+ * @param format Custom format implementation
145
+ */
146
+ static registerFormat(format) {
147
+ Image.formats.push(format);
148
+ }
149
+ /**
150
+ * Get all registered formats
151
+ */
152
+ static getFormats() {
153
+ return Image.formats;
154
+ }
155
+ /**
156
+ * Read an image from bytes
157
+ * @param data Raw image data
158
+ * @param format Optional format hint (e.g., "png", "jpeg", "webp")
159
+ * @returns Image instance
160
+ */
161
+ static async read(data, format) {
162
+ const image = new Image();
163
+ // Try specified format first
164
+ if (format) {
165
+ const handler = Image.formats.find((f) => f.name === format);
166
+ if (handler && handler.canDecode(data)) {
167
+ image.imageData = await handler.decode(data);
168
+ return image;
169
+ }
170
+ }
171
+ // Auto-detect format
172
+ for (const handler of Image.formats) {
173
+ if (handler.canDecode(data)) {
174
+ image.imageData = await handler.decode(data);
175
+ return image;
176
+ }
177
+ }
178
+ throw new Error("Unsupported or unrecognized image format");
179
+ }
180
+ /**
181
+ * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
182
+ * @param data Raw image data
183
+ * @param format Optional format hint (e.g., "gif", "tiff")
184
+ * @returns MultiFrameImageData with all frames
185
+ */
186
+ static async readFrames(data, format) {
187
+ // Try specified format first
188
+ if (format) {
189
+ const handler = Image.formats.find((f) => f.name === format);
190
+ if (handler && handler.canDecode(data) && handler.decodeFrames) {
191
+ return await handler.decodeFrames(data);
192
+ }
193
+ }
194
+ // Auto-detect format
195
+ for (const handler of Image.formats) {
196
+ if (handler.canDecode(data) && handler.decodeFrames) {
197
+ return await handler.decodeFrames(data);
198
+ }
199
+ }
200
+ throw new Error("Unsupported or unrecognized multi-frame image format");
201
+ }
202
+ /**
203
+ * Save multi-frame image data to bytes in the specified format
204
+ * @param format Format name (e.g., "gif", "tiff")
205
+ * @param imageData Multi-frame image data to save
206
+ * @param options Optional format-specific encoding options
207
+ * @returns Encoded image bytes
208
+ */
209
+ static async saveFrames(format, imageData, options) {
210
+ const handler = Image.formats.find((f) => f.name === format);
211
+ if (!handler) {
212
+ throw new Error(`Unsupported format: ${format}`);
213
+ }
214
+ if (!handler.encodeFrames) {
215
+ throw new Error(`Format ${format} does not support multi-frame encoding`);
216
+ }
217
+ return await handler.encodeFrames(imageData, options);
218
+ }
219
+ /**
220
+ * Create an image from raw RGBA data
221
+ * @param width Image width
222
+ * @param height Image height
223
+ * @param data Raw RGBA pixel data (4 bytes per pixel)
224
+ * @returns Image instance
225
+ */
226
+ static fromRGBA(width, height, data) {
227
+ if (data.length !== width * height * 4) {
228
+ throw new Error(`Data length mismatch: expected ${width * height * 4}, got ${data.length}`);
229
+ }
230
+ const image = new Image();
231
+ image.imageData = { width, height, data: new Uint8Array(data) };
232
+ return image;
233
+ }
234
+ /**
235
+ * Resize the image
236
+ * @param options Resize options
237
+ * @returns This image instance for chaining
238
+ */
239
+ resize(options) {
240
+ if (!this.imageData)
241
+ throw new Error("No image loaded");
242
+ const { width, height, method = "bilinear" } = options;
243
+ const { data: srcData, width: srcWidth, height: srcHeight } = this.imageData;
244
+ let resizedData;
245
+ if (method === "nearest") {
246
+ resizedData = (0, resize_js_1.resizeNearest)(srcData, srcWidth, srcHeight, width, height);
247
+ }
248
+ else {
249
+ resizedData = (0, resize_js_1.resizeBilinear)(srcData, srcWidth, srcHeight, width, height);
250
+ }
251
+ // Preserve metadata when resizing
252
+ const metadata = this.imageData.metadata;
253
+ this.imageData = {
254
+ width,
255
+ height,
256
+ data: resizedData,
257
+ metadata: metadata ? { ...metadata } : undefined,
258
+ };
259
+ // Update physical dimensions if DPI is set
260
+ if (this.imageData.metadata) {
261
+ if (metadata?.dpiX) {
262
+ this.imageData.metadata.physicalWidth = width / metadata.dpiX;
263
+ }
264
+ if (metadata?.dpiY) {
265
+ this.imageData.metadata.physicalHeight = height / metadata.dpiY;
266
+ }
267
+ }
268
+ return this;
269
+ }
270
+ /**
271
+ * Save the image to bytes in the specified format
272
+ * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
273
+ * @param options Optional format-specific encoding options
274
+ * @returns Encoded image bytes
275
+ */
276
+ async save(format, options) {
277
+ if (!this.imageData)
278
+ throw new Error("No image loaded");
279
+ const handler = Image.formats.find((f) => f.name === format);
280
+ if (!handler) {
281
+ throw new Error(`Unsupported format: ${format}`);
282
+ }
283
+ return await handler.encode(this.imageData, options);
284
+ }
285
+ /**
286
+ * Clone this image
287
+ * @returns New image instance with copied data and metadata
288
+ */
289
+ clone() {
290
+ if (!this.imageData)
291
+ throw new Error("No image loaded");
292
+ const image = new Image();
293
+ image.imageData = {
294
+ width: this.imageData.width,
295
+ height: this.imageData.height,
296
+ data: new Uint8Array(this.imageData.data),
297
+ metadata: this.imageData.metadata
298
+ ? {
299
+ ...this.imageData.metadata,
300
+ custom: this.imageData.metadata.custom
301
+ ? { ...this.imageData.metadata.custom }
302
+ : undefined,
303
+ }
304
+ : undefined,
305
+ };
306
+ return image;
307
+ }
308
+ }
309
+ exports.Image = Image;
310
+ Object.defineProperty(Image, "formats", {
311
+ enumerable: true,
312
+ configurable: true,
313
+ writable: true,
314
+ value: [
315
+ new png_js_1.PNGFormat(),
316
+ new jpeg_js_1.JPEGFormat(),
317
+ new webp_js_1.WebPFormat(),
318
+ new gif_js_1.GIFFormat(),
319
+ new tiff_js_1.TIFFFormat(),
320
+ new bmp_js_1.BMPFormat(),
321
+ new raw_js_1.RAWFormat(),
322
+ new ascii_js_1.ASCIIFormat(),
323
+ ]
324
+ });
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Image metadata
3
+ */
4
+ export interface ImageMetadata {
5
+ /** Physical width in inches (derived from DPI if available) */
6
+ physicalWidth?: number;
7
+ /** Physical height in inches (derived from DPI if available) */
8
+ physicalHeight?: number;
9
+ /** Dots per inch (horizontal) */
10
+ dpiX?: number;
11
+ /** Dots per inch (vertical) */
12
+ dpiY?: number;
13
+ /** GPS latitude */
14
+ latitude?: number;
15
+ /** GPS longitude */
16
+ longitude?: number;
17
+ /** Image title */
18
+ title?: string;
19
+ /** Image description */
20
+ description?: string;
21
+ /** Image author */
22
+ author?: string;
23
+ /** Copyright information */
24
+ copyright?: string;
25
+ /** Creation date */
26
+ creationDate?: Date;
27
+ /** Custom metadata fields */
28
+ custom?: Record<string, string | number | boolean>;
29
+ }
30
+ /**
31
+ * Frame-specific metadata for multi-frame images
32
+ */
33
+ export interface FrameMetadata {
34
+ /** Frame delay in milliseconds (for animations) */
35
+ delay?: number;
36
+ /** Frame disposal method: how to treat the frame before rendering the next one */
37
+ disposal?: "none" | "background" | "previous";
38
+ /** X offset of frame within the canvas */
39
+ left?: number;
40
+ /** Y offset of frame within the canvas */
41
+ top?: number;
42
+ }
43
+ /**
44
+ * Image data representation
45
+ */
46
+ export interface ImageData {
47
+ /** Image width in pixels */
48
+ width: number;
49
+ /** Image height in pixels */
50
+ height: number;
51
+ /** Raw pixel data as RGBA (4 bytes per pixel) */
52
+ data: Uint8Array;
53
+ /** Optional metadata */
54
+ metadata?: ImageMetadata;
55
+ }
56
+ /**
57
+ * Single frame in a multi-frame image
58
+ */
59
+ export interface ImageFrame {
60
+ /** Frame width in pixels */
61
+ width: number;
62
+ /** Frame height in pixels */
63
+ height: number;
64
+ /** Raw pixel data as RGBA (4 bytes per pixel) */
65
+ data: Uint8Array;
66
+ /** Optional frame-specific metadata */
67
+ frameMetadata?: FrameMetadata;
68
+ }
69
+ /**
70
+ * Multi-frame image data representation
71
+ */
72
+ export interface MultiFrameImageData {
73
+ /** Canvas width in pixels (for GIF logical screen) */
74
+ width: number;
75
+ /** Canvas height in pixels (for GIF logical screen) */
76
+ height: number;
77
+ /** Array of frames */
78
+ frames: ImageFrame[];
79
+ /** Optional global metadata */
80
+ metadata?: ImageMetadata;
81
+ }
82
+ /**
83
+ * Options for resizing images
84
+ */
85
+ export interface ResizeOptions {
86
+ /** Target width in pixels */
87
+ width: number;
88
+ /** Target height in pixels */
89
+ height: number;
90
+ /** Resize method (default: "bilinear") */
91
+ method?: "nearest" | "bilinear";
92
+ }
93
+ /**
94
+ * Options for ASCII art encoding
95
+ */
96
+ export interface ASCIIOptions {
97
+ /** Target width in characters (default: 80) */
98
+ width?: number;
99
+ /** Character set to use (default: "simple") */
100
+ charset?: "simple" | "extended" | "blocks" | "detailed";
101
+ /** Aspect ratio correction factor for terminal display (default: 0.5) */
102
+ aspectRatio?: number;
103
+ /** Whether to invert brightness (default: false) */
104
+ invert?: boolean;
105
+ }
106
+ /**
107
+ * Options for WebP encoding
108
+ */
109
+ export interface WebPEncodeOptions {
110
+ /**
111
+ * Encoding quality (1-100, default: 90)
112
+ * - 100 = lossless (VP8L)
113
+ * - 1-99 = lossy (VP8 if OffscreenCanvas available, otherwise quantized VP8L)
114
+ */
115
+ quality?: number;
116
+ /**
117
+ * Force lossless encoding even with quality < 100
118
+ * Uses VP8L format with optional color quantization based on quality
119
+ */
120
+ lossless?: boolean;
121
+ }
122
+ /**
123
+ * Image format handler interface
124
+ */
125
+ export interface ImageFormat {
126
+ /** Format name (e.g., "png", "jpeg", "webp") */
127
+ readonly name: string;
128
+ /** MIME type (e.g., "image/png") */
129
+ readonly mimeType: string;
130
+ /**
131
+ * Decode image data from bytes
132
+ * @param data Raw image data
133
+ * @returns Decoded image data
134
+ */
135
+ decode(data: Uint8Array): Promise<ImageData>;
136
+ /**
137
+ * Encode image data to bytes
138
+ * @param imageData Image data to encode
139
+ * @param options Optional format-specific encoding options
140
+ * @returns Encoded image bytes
141
+ */
142
+ encode(imageData: ImageData, options?: unknown): Promise<Uint8Array>;
143
+ /**
144
+ * Check if the given data is in this format
145
+ * @param data Raw data to check
146
+ * @returns true if the data matches this format
147
+ */
148
+ canDecode(data: Uint8Array): boolean;
149
+ /**
150
+ * Decode all frames from multi-frame image (optional)
151
+ * @param data Raw image data
152
+ * @returns Decoded multi-frame image data
153
+ */
154
+ decodeFrames?(data: Uint8Array): Promise<MultiFrameImageData>;
155
+ /**
156
+ * Encode multi-frame image data to bytes (optional)
157
+ * @param imageData Multi-frame image data to encode
158
+ * @param options Optional format-specific encoding options
159
+ * @returns Encoded image bytes
160
+ */
161
+ encodeFrames?(imageData: MultiFrameImageData, options?: unknown): Promise<Uint8Array>;
162
+ /**
163
+ * Check if the format supports multiple frames
164
+ */
165
+ supportsMultipleFrames?(): boolean;
166
+ }
167
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mBAAmB;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,YAAY,CAAC,EAAE,IAAI,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Module", { value: true });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Pure JavaScript GIF decoder implementation
3
+ * Supports GIF87a and GIF89a formats with LZW decompression
4
+ */
5
+ interface GIFImage {
6
+ width: number;
7
+ height: number;
8
+ data: Uint8Array;
9
+ }
10
+ interface GIFFrame {
11
+ width: number;
12
+ height: number;
13
+ left: number;
14
+ top: number;
15
+ data: Uint8Array;
16
+ delay: number;
17
+ disposal: number;
18
+ }
19
+ export declare class GIFDecoder {
20
+ private data;
21
+ private pos;
22
+ constructor(data: Uint8Array);
23
+ private readByte;
24
+ private readUint16LE;
25
+ private readBytes;
26
+ private readColorTable;
27
+ private readDataSubBlocks;
28
+ decode(): GIFImage;
29
+ /**
30
+ * Decode all frames from an animated GIF
31
+ * @returns Object with canvas dimensions and array of frames
32
+ */
33
+ decodeAllFrames(): {
34
+ width: number;
35
+ height: number;
36
+ frames: GIFFrame[];
37
+ };
38
+ private indexedToRGBA;
39
+ private deinterlace;
40
+ }
41
+ export {};
42
+ //# sourceMappingURL=gif_decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gif_decoder.d.ts","sourceRoot":"","sources":["../../../src/src/utils/gif_decoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,GAAG,CAAS;gBAER,IAAI,EAAE,UAAU;IAK5B,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,iBAAiB;IAWzB,MAAM,IAAI,QAAQ;IAwHlB;;;OAGG;IACH,eAAe,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,QAAQ,EAAE,CAAC;KACpB;IA0KD,OAAO,CAAC,aAAa;IAwErB,OAAO,CAAC,WAAW;CA0BpB"}