@wasmedia/wimagemagick 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.
Files changed (70) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/LICENSE +199 -0
  3. package/README.md +75 -0
  4. package/dist/api.d.ts +68 -0
  5. package/dist/api.d.ts.map +1 -0
  6. package/dist/api.js +218 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/cli.d.ts +71 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +273 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/filesystem.d.ts +37 -0
  13. package/dist/filesystem.d.ts.map +1 -0
  14. package/dist/filesystem.js +141 -0
  15. package/dist/filesystem.js.map +1 -0
  16. package/dist/image.d.ts +125 -0
  17. package/dist/image.d.ts.map +1 -0
  18. package/dist/image.js +426 -0
  19. package/dist/image.js.map +1 -0
  20. package/dist/index.d.ts +30 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +34 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/licenses/README.txt +11 -0
  25. package/dist/licenses/aom-LICENSE.txt +28 -0
  26. package/dist/licenses/brotli-LICENSE.txt +21 -0
  27. package/dist/licenses/de265-LICENSE.txt +873 -0
  28. package/dist/licenses/ffi-LICENSE.txt +23 -0
  29. package/dist/licenses/freetype-LICENSE.txt +171 -0
  30. package/dist/licenses/glib-LICENSE.txt +504 -0
  31. package/dist/licenses/heif-LICENSE.txt +873 -0
  32. package/dist/licenses/highway-LICENSE.txt +203 -0
  33. package/dist/licenses/imagemagick-LICENSE.txt +106 -0
  34. package/dist/licenses/imagemagick-NOTICE.txt +240 -0
  35. package/dist/licenses/jpeg-turbo-LICENSE.txt +137 -0
  36. package/dist/licenses/jpeg-xl-LICENSE.txt +29 -0
  37. package/dist/licenses/lcms-LICENSE.txt +24 -0
  38. package/dist/licenses/libraw-COPYRIGHT.txt +27 -0
  39. package/dist/licenses/libraw-LICENSE.CDDL.txt +340 -0
  40. package/dist/licenses/libraw-LICENSE.LGPL.txt +458 -0
  41. package/dist/licenses/lqr-LICENSE.txt +167 -0
  42. package/dist/licenses/openjpeg-LICENSE.txt +41 -0
  43. package/dist/licenses/png-LICENSE.txt +136 -0
  44. package/dist/licenses/tiff-LICENSE.txt +51 -0
  45. package/dist/licenses/webp-LICENSE.txt +31 -0
  46. package/dist/licenses/xml-LICENSE.txt +26 -0
  47. package/dist/licenses/zlib-LICENSE.txt +24 -0
  48. package/dist/loader.d.ts +25 -0
  49. package/dist/loader.d.ts.map +1 -0
  50. package/dist/loader.js +50 -0
  51. package/dist/loader.js.map +1 -0
  52. package/dist/raw.d.ts +39 -0
  53. package/dist/raw.d.ts.map +1 -0
  54. package/dist/raw.js +151 -0
  55. package/dist/raw.js.map +1 -0
  56. package/dist/types.d.ts +164 -0
  57. package/dist/types.d.ts.map +1 -0
  58. package/dist/types.js +94 -0
  59. package/dist/types.js.map +1 -0
  60. package/dist/wimagemagick.js +15 -0
  61. package/dist/wimagemagick.wasm +0 -0
  62. package/dist/worker-handler.d.ts +46 -0
  63. package/dist/worker-handler.d.ts.map +1 -0
  64. package/dist/worker-handler.js +165 -0
  65. package/dist/worker-handler.js.map +1 -0
  66. package/dist/worker.d.ts +14 -0
  67. package/dist/worker.d.ts.map +1 -0
  68. package/dist/worker.js +19 -0
  69. package/dist/worker.js.map +1 -0
  70. package/package.json +51 -0
@@ -0,0 +1,136 @@
1
+ [ png 1.6.56 (2026-03-25) ]
2
+
3
+ COPYRIGHT NOTICE, DISCLAIMER, and LICENSE
4
+ =========================================
5
+
6
+ PNG Reference Library License version 2
7
+ ---------------------------------------
8
+
9
+ * Copyright (c) 1995-2026 The PNG Reference Library Authors.
10
+ * Copyright (c) 2018-2026 Cosmin Truta.
11
+ * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.
12
+ * Copyright (c) 1996-1997 Andreas Dilger.
13
+ * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
14
+
15
+ The software is supplied "as is", without warranty of any kind,
16
+ express or implied, including, without limitation, the warranties
17
+ of merchantability, fitness for a particular purpose, title, and
18
+ non-infringement. In no event shall the Copyright owners, or
19
+ anyone distributing the software, be liable for any damages or
20
+ other liability, whether in contract, tort or otherwise, arising
21
+ from, out of, or in connection with the software, or the use or
22
+ other dealings in the software, even if advised of the possibility
23
+ of such damage.
24
+
25
+ Permission is hereby granted to use, copy, modify, and distribute
26
+ this software, or portions hereof, for any purpose, without fee,
27
+ subject to the following restrictions:
28
+
29
+ 1. The origin of this software must not be misrepresented; you
30
+ must not claim that you wrote the original software. If you
31
+ use this software in a product, an acknowledgment in the product
32
+ documentation would be appreciated, but is not required.
33
+
34
+ 2. Altered source versions must be plainly marked as such, and must
35
+ not be misrepresented as being the original software.
36
+
37
+ 3. This Copyright notice may not be removed or altered from any
38
+ source or altered source distribution.
39
+
40
+
41
+ PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)
42
+ -----------------------------------------------------------------------
43
+
44
+ libpng versions 1.0.7, July 1, 2000, through 1.6.35, July 15, 2018 are
45
+ Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
46
+ derived from libpng-1.0.6, and are distributed according to the same
47
+ disclaimer and license as libpng-1.0.6 with the following individuals
48
+ added to the list of Contributing Authors:
49
+
50
+ Simon-Pierre Cadieux
51
+ Eric S. Raymond
52
+ Mans Rullgard
53
+ Cosmin Truta
54
+ Gilles Vollant
55
+ James Yu
56
+ Mandar Sahastrabuddhe
57
+ Google Inc.
58
+ Vadim Barkov
59
+
60
+ and with the following additions to the disclaimer:
61
+
62
+ There is no warranty against interference with your enjoyment of
63
+ the library or against infringement. There is no warranty that our
64
+ efforts or the library will fulfill any of your particular purposes
65
+ or needs. This library is provided with all faults, and the entire
66
+ risk of satisfactory quality, performance, accuracy, and effort is
67
+ with the user.
68
+
69
+ Some files in the "contrib" directory and some configure-generated
70
+ files that are distributed with libpng have other copyright owners, and
71
+ are released under other open source licenses.
72
+
73
+ libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
74
+ Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
75
+ libpng-0.96, and are distributed according to the same disclaimer and
76
+ license as libpng-0.96, with the following individuals added to the
77
+ list of Contributing Authors:
78
+
79
+ Tom Lane
80
+ Glenn Randers-Pehrson
81
+ Willem van Schaik
82
+
83
+ libpng versions 0.89, June 1996, through 0.96, May 1997, are
84
+ Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
85
+ and are distributed according to the same disclaimer and license as
86
+ libpng-0.88, with the following individuals added to the list of
87
+ Contributing Authors:
88
+
89
+ John Bowler
90
+ Kevin Bracey
91
+ Sam Bushell
92
+ Magnus Holmgren
93
+ Greg Roelofs
94
+ Tom Tanner
95
+
96
+ Some files in the "scripts" directory have other copyright owners,
97
+ but are released under this license.
98
+
99
+ libpng versions 0.5, May 1995, through 0.88, January 1996, are
100
+ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
101
+
102
+ For the purposes of this copyright and license, "Contributing Authors"
103
+ is defined as the following set of individuals:
104
+
105
+ Andreas Dilger
106
+ Dave Martindale
107
+ Guy Eric Schalnat
108
+ Paul Schmidt
109
+ Tim Wegner
110
+
111
+ The PNG Reference Library is supplied "AS IS". The Contributing
112
+ Authors and Group 42, Inc. disclaim all warranties, expressed or
113
+ implied, including, without limitation, the warranties of
114
+ merchantability and of fitness for any purpose. The Contributing
115
+ Authors and Group 42, Inc. assume no liability for direct, indirect,
116
+ incidental, special, exemplary, or consequential damages, which may
117
+ result from the use of the PNG Reference Library, even if advised of
118
+ the possibility of such damage.
119
+
120
+ Permission is hereby granted to use, copy, modify, and distribute this
121
+ source code, or portions hereof, for any purpose, without fee, subject
122
+ to the following restrictions:
123
+
124
+ 1. The origin of this source code must not be misrepresented.
125
+
126
+ 2. Altered versions must be plainly marked as such and must not
127
+ be misrepresented as being the original source.
128
+
129
+ 3. This Copyright notice may not be removed or altered from any
130
+ source or altered source distribution.
131
+
132
+ The Contributing Authors and Group 42, Inc. specifically permit,
133
+ without fee, and encourage the use of this source code as a component
134
+ to supporting the PNG file format in commercial products. If you use
135
+ this source code in a product, acknowledgment is not required but would
136
+ be appreciated.
@@ -0,0 +1,51 @@
1
+ [ tiff 4.7.1 (2025-09-12) ]
2
+
3
+ # LibTIFF license
4
+
5
+ Copyright © 1988-1997 Sam Leffler\
6
+ Copyright © 1991-1997 Silicon Graphics, Inc.
7
+
8
+ Permission to use, copy, modify, distribute, and sell this software and
9
+ its documentation for any purpose is hereby granted without fee, provided
10
+ that (i) the above copyright notices and this permission notice appear in
11
+ all copies of the software and related documentation, and (ii) the names of
12
+ Sam Leffler and Silicon Graphics may not be used in any advertising or
13
+ publicity relating to the software without the specific, prior written
14
+ permission of Sam Leffler and Silicon Graphics.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18
+ WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19
+
20
+ IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
21
+ ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22
+ OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23
+ WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24
+ LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25
+ OF THIS SOFTWARE.
26
+
27
+ # Lempel-Ziv & Welch Compression (tif_lzw.c) license
28
+ The code of tif_lzw.c is derived from the compress program whose code is
29
+ derived from software contributed to Berkeley by James A. Woods,
30
+ derived from original work by Spencer Thomas and Joseph Orost.
31
+
32
+ The original Berkeley copyright notice appears below in its entirety:
33
+
34
+ Copyright (c) 1985, 1986 The Regents of the University of California.
35
+ All rights reserved.
36
+
37
+ This code is derived from software contributed to Berkeley by
38
+ James A. Woods, derived from original work by Spencer Thomas
39
+ and Joseph Orost.
40
+
41
+ Redistribution and use in source and binary forms are permitted
42
+ provided that the above copyright notice and this paragraph are
43
+ duplicated in all such forms and that any documentation,
44
+ advertising materials, and other materials related to such
45
+ distribution and use acknowledge that the software was developed
46
+ by the University of California, Berkeley. The name of the
47
+ University may not be used to endorse or promote products derived
48
+ from this software without specific prior written permission.
49
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
50
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51
+ WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
@@ -0,0 +1,31 @@
1
+ [ webp 1.6.0 (2025-07-09) ]
2
+
3
+ Copyright (c) 2010, Google Inc. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in
14
+ the documentation and/or other materials provided with the
15
+ distribution.
16
+
17
+ * Neither the name of Google nor the names of its contributors may
18
+ be used to endorse or promote products derived from this software
19
+ without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,26 @@
1
+ [ xml 2.15.2 (2026-03-03) ]
2
+
3
+ Except where otherwise noted in the source code (e.g. the files dict.c and
4
+ list.c, which are covered by a similar licence but with different Copyright
5
+ notices) all the files are:
6
+
7
+ Copyright (C) 1998-2012 Daniel Veillard. All Rights Reserved.
8
+ Copyright (C) The Libxml2 Contributors.
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is fur-
15
+ nished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
22
+ NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ [ zlib 1.3.2 (2026-02-17) ]
2
+
3
+ Copyright notice:
4
+
5
+ (C) 1995-2026 Jean-loup Gailly and Mark Adler
6
+
7
+ This software is provided 'as-is', without any express or implied
8
+ warranty. In no event will the authors be held liable for any damages
9
+ arising from the use of this software.
10
+
11
+ Permission is granted to anyone to use this software for any purpose,
12
+ including commercial applications, and to alter it and redistribute it
13
+ freely, subject to the following restrictions:
14
+
15
+ 1. The origin of this software must not be misrepresented; you must not
16
+ claim that you wrote the original software. If you use this software
17
+ in a product, an acknowledgment in the product documentation would be
18
+ appreciated but is not required.
19
+ 2. Altered source versions must be plainly marked as such, and must not be
20
+ misrepresented as being the original software.
21
+ 3. This notice may not be removed or altered from any source distribution.
22
+
23
+ Jean-loup Gailly Mark Adler
24
+ jloup@gzip.org madler@alumni.caltech.edu
@@ -0,0 +1,25 @@
1
+ /**
2
+ * WASM module loader.
3
+ */
4
+ import type { WImageMagickOptions, WImageMagickInstance } from "./types.js";
5
+ /**
6
+ * Initialize wimagemagick.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const wim = await initWImageMagick();
11
+ *
12
+ * // High-level API
13
+ * const img = wim.Image.fromBuffer(pngData);
14
+ * const jpeg = img.resize(800, 600).quality(85).toBuffer('JPEG');
15
+ * img.dispose();
16
+ *
17
+ * // CLI-style
18
+ * const result = wim.execute('input.png -resize 50% output.jpg', inputFiles);
19
+ *
20
+ * // Low-level API
21
+ * const wand = wim.api.NewMagickWand();
22
+ * ```
23
+ */
24
+ export declare function initWImageMagick(options?: WImageMagickOptions): Promise<WImageMagickInstance>;
25
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAEV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAcpB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CAyB/B"}
package/dist/loader.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * WASM module loader.
3
+ */
4
+ import { createBindings } from "./api.js";
5
+ import { WMagickImage, setSharedModule } from "./image.js";
6
+ import { execute, createOutputHooks } from "./cli.js";
7
+ async function loadModule(modulePath) {
8
+ const factory = await import(/* webpackIgnore: true */ modulePath);
9
+ const init = factory.default ?? factory;
10
+ // The output hooks must be handed to the factory: Emscripten reads
11
+ // print/printErr while constructing the module and ignores later changes.
12
+ const module = await init({ ...createOutputHooks() });
13
+ return module;
14
+ }
15
+ /**
16
+ * Initialize wimagemagick.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const wim = await initWImageMagick();
21
+ *
22
+ * // High-level API
23
+ * const img = wim.Image.fromBuffer(pngData);
24
+ * const jpeg = img.resize(800, 600).quality(85).toBuffer('JPEG');
25
+ * img.dispose();
26
+ *
27
+ * // CLI-style
28
+ * const result = wim.execute('input.png -resize 50% output.jpg', inputFiles);
29
+ *
30
+ * // Low-level API
31
+ * const wand = wim.api.NewMagickWand();
32
+ * ```
33
+ */
34
+ export async function initWImageMagick(options) {
35
+ options?.onProgress?.("loading");
36
+ const modulePath = options?.wasmPath
37
+ ?? new URL("../dist/wimagemagick.js", import.meta.url).href;
38
+ const module = await loadModule(modulePath);
39
+ options?.onProgress?.("initializing");
40
+ setSharedModule(module);
41
+ options?.onProgress?.("ready");
42
+ const boundExecute = (command, inputFiles) => execute(module, command, inputFiles);
43
+ return {
44
+ Image: WMagickImage,
45
+ execute: boundExecute,
46
+ api: createBindings(module),
47
+ module,
48
+ };
49
+ }
50
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA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M;KACP,CAAC;AACJ,CAAC"}
package/dist/raw.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Recognise camera raw files from their first bytes.
3
+ *
4
+ * ImageMagick registers its raw coders with `ExplicitFormatType`, so it never
5
+ * picks LibRaw from a file's contents. Most raws are TIFF containers, and
6
+ * without a hint the TIFF coder claims them: a DNG comes back as the
7
+ * undemosaiced sensor mosaic, a NEF as its 160x120 embedded preview, and a CR2
8
+ * fails outright. Detecting the raw here lets the buffer entry points supply
9
+ * the hint themselves.
10
+ *
11
+ * Only signatures that have been checked against real camera files are
12
+ * matched, and the TIFF-based ones require the raw file's structure, not just
13
+ * a camera maker's name, so a TIFF written by a camera or scanner stays a TIFF.
14
+ */
15
+ /**
16
+ * The ImageMagick format name for a camera raw file, or `undefined` if the
17
+ * data is not one this recognises.
18
+ *
19
+ * | Format | Signature |
20
+ * |--------|-----------|
21
+ * | CR3 | ISO media file with brand `crx ` |
22
+ * | CR2 | TIFF with `CR` and major version 2 at byte 8 |
23
+ * | IIQ | TIFF with `IIII` at byte 8 (Phase One) |
24
+ * | DNG | TIFF whose first IFD carries `DNGVersion` |
25
+ * | NEF | TIFF whose first IFD is a thumbnail with sub-IFDs and Make `NIKON…` |
26
+ * | 3FR | the same layout with Make `Hasselblad` |
27
+ * | ARW | the same layout with Make `SONY` |
28
+ * | DCR | the same layout with Make `Kodak` |
29
+ * | SRW | TIFF whose first IFD has no image size, only sub-IFDs, and Make `SAMSUNG` |
30
+ * | KDC | the same with Make `EASTMAN KODAK COMPANY` |
31
+ * | RAF, RW2, ORF, CRW, MRW, RAW | the fixed headers in {@link HEADER_SIGNATURES} |
32
+ *
33
+ * The fixed-header formats would reach LibRaw without the hint, because
34
+ * ImageMagick's own magic table (`coders/dng.h`) lists the same signatures;
35
+ * they are recognised here so that the answer to "is this a raw?" does not
36
+ * depend on which formats ImageMagick happens to sniff.
37
+ */
38
+ export declare function detectRawFormat(data: Uint8Array | ArrayBuffer): string | undefined;
39
+ //# sourceMappingURL=raw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../src/raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgGH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CA2BlF"}
package/dist/raw.js ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Recognise camera raw files from their first bytes.
3
+ *
4
+ * ImageMagick registers its raw coders with `ExplicitFormatType`, so it never
5
+ * picks LibRaw from a file's contents. Most raws are TIFF containers, and
6
+ * without a hint the TIFF coder claims them: a DNG comes back as the
7
+ * undemosaiced sensor mosaic, a NEF as its 160x120 embedded preview, and a CR2
8
+ * fails outright. Detecting the raw here lets the buffer entry points supply
9
+ * the hint themselves.
10
+ *
11
+ * Only signatures that have been checked against real camera files are
12
+ * matched, and the TIFF-based ones require the raw file's structure, not just
13
+ * a camera maker's name, so a TIFF written by a camera or scanner stays a TIFF.
14
+ */
15
+ const TAG_NEW_SUBFILE_TYPE = 254;
16
+ const TAG_IMAGE_WIDTH = 256;
17
+ const TAG_IMAGE_LENGTH = 257;
18
+ const TAG_MAKE = 271;
19
+ const TAG_SUB_IFDS = 330;
20
+ const TAG_DNG_VERSION = 50706;
21
+ const ascii = (data, offset, text) => offset + text.length <= data.length &&
22
+ [...text].every((c, i) => data[offset + i] === c.charCodeAt(0));
23
+ /** Read the few IFD0 tags the raw layouts are told apart by. */
24
+ function readIfd0(data) {
25
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
26
+ const le = data[0] === 0x49;
27
+ const ifd = view.getUint32(4, le);
28
+ if (ifd + 2 > data.length)
29
+ return undefined;
30
+ const result = { isThumbnail: false, hasImageSize: false, hasSubIFDs: false, hasDNGVersion: false, make: "" };
31
+ const count = view.getUint16(ifd, le);
32
+ for (let i = 0; i < count; i++) {
33
+ const entry = ifd + 2 + i * 12;
34
+ if (entry + 12 > data.length)
35
+ break;
36
+ const tag = view.getUint16(entry, le);
37
+ const type = view.getUint16(entry + 2, le);
38
+ const n = view.getUint32(entry + 4, le);
39
+ if (tag === TAG_NEW_SUBFILE_TYPE) {
40
+ // LONG in the files seen; bit 0 marks a reduced-resolution image.
41
+ const value = type === 3 ? view.getUint16(entry + 8, le) : view.getUint32(entry + 8, le);
42
+ result.isThumbnail = (value & 1) === 1;
43
+ }
44
+ else if (tag === TAG_IMAGE_WIDTH || tag === TAG_IMAGE_LENGTH) {
45
+ result.hasImageSize = true;
46
+ }
47
+ else if (tag === TAG_SUB_IFDS) {
48
+ result.hasSubIFDs = n > 0;
49
+ }
50
+ else if (tag === TAG_DNG_VERSION) {
51
+ result.hasDNGVersion = true;
52
+ }
53
+ else if (tag === TAG_MAKE && type === 2) {
54
+ const start = n > 4 ? view.getUint32(entry + 8, le) : entry + 8;
55
+ const end = start + Math.min(n, 64);
56
+ if (end > data.length)
57
+ continue;
58
+ result.make = String.fromCharCode(...data.subarray(start, end)).replace(/\0.*$/s, "");
59
+ }
60
+ }
61
+ return result;
62
+ }
63
+ /**
64
+ * Raw formats with a fixed header, copied from ImageMagick's magic table
65
+ * (`coders/dng.h`). Each was checked against the header of a real camera
66
+ * file, named in its comment; RAF and MRW only against exiftool's test
67
+ * images, whose image data is stripped, so those two were not decoded.
68
+ */
69
+ const HEADER_SIGNATURES = [
70
+ ["RAF", "FUJIFILMCCD-RAW "], // FinePix S5Pro
71
+ ["RW2", "IIU\x00\x18\x00\x00\x00"], // Lumix DMC-FZ70, DMC-LX3
72
+ ["RAW", "IIU\x00\x08\x00\x00\x00"], // older Leica/Panasonic .RAW: Digilux 2
73
+ // E-300. The IIRS and MMOR variants are not in ImageMagick's table and no
74
+ // sample was available, so they are left out.
75
+ ["ORF", "IIRO\x08\x00\x00\x00"],
76
+ ["CRW", "II\x1a\x00\x00\x00HEAPCCDR"], // EOS D60, Digital Rebel
77
+ ["MRW", "\x00MRM"], // DiMAGE A2
78
+ ];
79
+ /**
80
+ * Makes whose raw files share the NEF layout: IFD0 is a reduced-resolution
81
+ * preview, and the sensor data hangs off its SubIFDs.
82
+ */
83
+ const THUMBNAIL_LAYOUT_MAKES = [
84
+ ["NIKON", "NEF"],
85
+ ["Hasselblad", "3FR"],
86
+ ["SONY", "ARW"],
87
+ ["Kodak", "DCR"],
88
+ ];
89
+ /**
90
+ * Makes whose raw files have an IFD0 with no image at all — no ImageWidth or
91
+ * ImageLength — and the sensor data in its SubIFDs. libtiff cannot read such
92
+ * a file, so claiming it costs nothing even if a non-raw TIFF matched.
93
+ */
94
+ const SIZELESS_LAYOUT_MAKES = [
95
+ ["SAMSUNG", "SRW"],
96
+ ["EASTMAN KODAK COMPANY", "KDC"],
97
+ ];
98
+ /**
99
+ * The ImageMagick format name for a camera raw file, or `undefined` if the
100
+ * data is not one this recognises.
101
+ *
102
+ * | Format | Signature |
103
+ * |--------|-----------|
104
+ * | CR3 | ISO media file with brand `crx ` |
105
+ * | CR2 | TIFF with `CR` and major version 2 at byte 8 |
106
+ * | IIQ | TIFF with `IIII` at byte 8 (Phase One) |
107
+ * | DNG | TIFF whose first IFD carries `DNGVersion` |
108
+ * | NEF | TIFF whose first IFD is a thumbnail with sub-IFDs and Make `NIKON…` |
109
+ * | 3FR | the same layout with Make `Hasselblad` |
110
+ * | ARW | the same layout with Make `SONY` |
111
+ * | DCR | the same layout with Make `Kodak` |
112
+ * | SRW | TIFF whose first IFD has no image size, only sub-IFDs, and Make `SAMSUNG` |
113
+ * | KDC | the same with Make `EASTMAN KODAK COMPANY` |
114
+ * | RAF, RW2, ORF, CRW, MRW, RAW | the fixed headers in {@link HEADER_SIGNATURES} |
115
+ *
116
+ * The fixed-header formats would reach LibRaw without the hint, because
117
+ * ImageMagick's own magic table (`coders/dng.h`) lists the same signatures;
118
+ * they are recognised here so that the answer to "is this a raw?" does not
119
+ * depend on which formats ImageMagick happens to sniff.
120
+ */
121
+ export function detectRawFormat(data) {
122
+ const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
123
+ if (ascii(bytes, 4, "ftypcrx "))
124
+ return "CR3";
125
+ for (const [format, header] of HEADER_SIGNATURES) {
126
+ if (ascii(bytes, 0, header))
127
+ return format;
128
+ }
129
+ const tiff = bytes.length >= 8 &&
130
+ ((bytes[0] === 0x49 && bytes[1] === 0x49 && bytes[2] === 0x2a && bytes[3] === 0x00) ||
131
+ (bytes[0] === 0x4d && bytes[1] === 0x4d && bytes[2] === 0x00 && bytes[3] === 0x2a));
132
+ if (!tiff)
133
+ return undefined;
134
+ if (ascii(bytes, 8, "CR") && bytes[10] === 2)
135
+ return "CR2";
136
+ if (ascii(bytes, 8, "IIII"))
137
+ return "IIQ";
138
+ const ifd0 = readIfd0(bytes);
139
+ if (!ifd0)
140
+ return undefined;
141
+ if (ifd0.hasDNGVersion)
142
+ return "DNG";
143
+ if (ifd0.isThumbnail && ifd0.hasSubIFDs) {
144
+ return THUMBNAIL_LAYOUT_MAKES.find(([prefix]) => ifd0.make.startsWith(prefix))?.[1];
145
+ }
146
+ if (!ifd0.hasImageSize && ifd0.hasSubIFDs) {
147
+ return SIZELESS_LAYOUT_MAKES.find(([prefix]) => ifd0.make.startsWith(prefix))?.[1];
148
+ }
149
+ return undefined;
150
+ }
151
+ //# sourceMappingURL=raw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw.js","sourceRoot":"","sources":["../src/raw.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B,MAAM,KAAK,GAAG,CAAC,IAAgB,EAAE,MAAc,EA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