@basemaps/lambda-tiler 7.12.0 → 7.14.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 (162) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/routes/__tests__/tile.style.json.test.js +3 -1
  3. package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
  4. package/build/routes/tile.style.json.d.ts +4 -0
  5. package/build/routes/tile.style.json.js +1 -1
  6. package/build/routes/tile.style.json.js.map +1 -1
  7. package/build/util/__test__/nztm.style.test.js +16 -7
  8. package/build/util/__test__/nztm.style.test.js.map +1 -1
  9. package/build/util/nztm.style.js +0 -3
  10. package/build/util/nztm.style.js.map +1 -1
  11. package/dist/index.js +86646 -0
  12. package/dist/node_modules/.package-lock.json +179 -0
  13. package/dist/node_modules/@img/sharp-libvips-linux-arm64/README.md +47 -0
  14. package/dist/node_modules/@img/sharp-libvips-linux-arm64/lib/glib-2.0/include/glibconfig.h +219 -0
  15. package/dist/node_modules/@img/sharp-libvips-linux-arm64/lib/index.js +1 -0
  16. package/dist/node_modules/@img/sharp-libvips-linux-arm64/lib/libvips-cpp.so.42 +0 -0
  17. package/dist/node_modules/@img/sharp-libvips-linux-arm64/package.json +45 -0
  18. package/dist/node_modules/@img/sharp-libvips-linux-arm64/versions.json +31 -0
  19. package/dist/node_modules/@img/sharp-linux-arm64/LICENSE +191 -0
  20. package/dist/node_modules/@img/sharp-linux-arm64/README.md +18 -0
  21. package/dist/node_modules/@img/sharp-linux-arm64/lib/sharp-linux-arm64.node +0 -0
  22. package/dist/node_modules/@img/sharp-linux-arm64/package.json +47 -0
  23. package/dist/node_modules/color/LICENSE +21 -0
  24. package/dist/node_modules/color/README.md +123 -0
  25. package/dist/node_modules/color/index.js +496 -0
  26. package/dist/node_modules/color/package.json +47 -0
  27. package/dist/node_modules/color-convert/CHANGELOG.md +54 -0
  28. package/dist/node_modules/color-convert/LICENSE +21 -0
  29. package/dist/node_modules/color-convert/README.md +68 -0
  30. package/dist/node_modules/color-convert/conversions.js +839 -0
  31. package/dist/node_modules/color-convert/index.js +81 -0
  32. package/dist/node_modules/color-convert/package.json +48 -0
  33. package/dist/node_modules/color-convert/route.js +97 -0
  34. package/dist/node_modules/color-name/LICENSE +8 -0
  35. package/dist/node_modules/color-name/README.md +11 -0
  36. package/dist/node_modules/color-name/index.js +152 -0
  37. package/dist/node_modules/color-name/package.json +28 -0
  38. package/dist/node_modules/color-string/LICENSE +21 -0
  39. package/dist/node_modules/color-string/README.md +62 -0
  40. package/dist/node_modules/color-string/index.js +242 -0
  41. package/dist/node_modules/color-string/package.json +39 -0
  42. package/dist/node_modules/detect-libc/LICENSE +201 -0
  43. package/dist/node_modules/detect-libc/README.md +163 -0
  44. package/dist/node_modules/detect-libc/index.d.ts +14 -0
  45. package/dist/node_modules/detect-libc/lib/detect-libc.js +267 -0
  46. package/dist/node_modules/detect-libc/lib/filesystem.js +41 -0
  47. package/dist/node_modules/detect-libc/lib/process.js +24 -0
  48. package/dist/node_modules/detect-libc/package.json +40 -0
  49. package/dist/node_modules/is-arrayish/LICENSE +21 -0
  50. package/dist/node_modules/is-arrayish/README.md +16 -0
  51. package/dist/node_modules/is-arrayish/index.js +9 -0
  52. package/dist/node_modules/is-arrayish/package.json +45 -0
  53. package/dist/node_modules/is-arrayish/yarn-error.log +1443 -0
  54. package/dist/node_modules/lerc/CHANGELOG.md +69 -0
  55. package/dist/node_modules/lerc/LercDecode.d.ts +61 -0
  56. package/dist/node_modules/lerc/LercDecode.es.d.ts +61 -0
  57. package/dist/node_modules/lerc/LercDecode.es.js +434 -0
  58. package/dist/node_modules/lerc/LercDecode.es.min.js +17 -0
  59. package/dist/node_modules/lerc/LercDecode.js +448 -0
  60. package/dist/node_modules/lerc/LercDecode.min.js +17 -0
  61. package/dist/node_modules/lerc/README.md +123 -0
  62. package/dist/node_modules/lerc/lerc-wasm.wasm +0 -0
  63. package/dist/node_modules/lerc/package.json +30 -0
  64. package/dist/node_modules/semver/LICENSE +15 -0
  65. package/dist/node_modules/semver/README.md +654 -0
  66. package/dist/node_modules/semver/bin/semver.js +188 -0
  67. package/dist/node_modules/semver/classes/comparator.js +141 -0
  68. package/dist/node_modules/semver/classes/index.js +5 -0
  69. package/dist/node_modules/semver/classes/range.js +554 -0
  70. package/dist/node_modules/semver/classes/semver.js +302 -0
  71. package/dist/node_modules/semver/functions/clean.js +6 -0
  72. package/dist/node_modules/semver/functions/cmp.js +52 -0
  73. package/dist/node_modules/semver/functions/coerce.js +60 -0
  74. package/dist/node_modules/semver/functions/compare-build.js +7 -0
  75. package/dist/node_modules/semver/functions/compare-loose.js +3 -0
  76. package/dist/node_modules/semver/functions/compare.js +5 -0
  77. package/dist/node_modules/semver/functions/diff.js +65 -0
  78. package/dist/node_modules/semver/functions/eq.js +3 -0
  79. package/dist/node_modules/semver/functions/gt.js +3 -0
  80. package/dist/node_modules/semver/functions/gte.js +3 -0
  81. package/dist/node_modules/semver/functions/inc.js +19 -0
  82. package/dist/node_modules/semver/functions/lt.js +3 -0
  83. package/dist/node_modules/semver/functions/lte.js +3 -0
  84. package/dist/node_modules/semver/functions/major.js +3 -0
  85. package/dist/node_modules/semver/functions/minor.js +3 -0
  86. package/dist/node_modules/semver/functions/neq.js +3 -0
  87. package/dist/node_modules/semver/functions/parse.js +16 -0
  88. package/dist/node_modules/semver/functions/patch.js +3 -0
  89. package/dist/node_modules/semver/functions/prerelease.js +6 -0
  90. package/dist/node_modules/semver/functions/rcompare.js +3 -0
  91. package/dist/node_modules/semver/functions/rsort.js +3 -0
  92. package/dist/node_modules/semver/functions/satisfies.js +10 -0
  93. package/dist/node_modules/semver/functions/sort.js +3 -0
  94. package/dist/node_modules/semver/functions/valid.js +6 -0
  95. package/dist/node_modules/semver/index.js +89 -0
  96. package/dist/node_modules/semver/internal/constants.js +35 -0
  97. package/dist/node_modules/semver/internal/debug.js +9 -0
  98. package/dist/node_modules/semver/internal/identifiers.js +23 -0
  99. package/dist/node_modules/semver/internal/lrucache.js +40 -0
  100. package/dist/node_modules/semver/internal/parse-options.js +15 -0
  101. package/dist/node_modules/semver/internal/re.js +217 -0
  102. package/dist/node_modules/semver/package.json +77 -0
  103. package/dist/node_modules/semver/preload.js +2 -0
  104. package/dist/node_modules/semver/range.bnf +16 -0
  105. package/dist/node_modules/semver/ranges/gtr.js +4 -0
  106. package/dist/node_modules/semver/ranges/intersects.js +7 -0
  107. package/dist/node_modules/semver/ranges/ltr.js +4 -0
  108. package/dist/node_modules/semver/ranges/max-satisfying.js +25 -0
  109. package/dist/node_modules/semver/ranges/min-satisfying.js +24 -0
  110. package/dist/node_modules/semver/ranges/min-version.js +61 -0
  111. package/dist/node_modules/semver/ranges/outside.js +80 -0
  112. package/dist/node_modules/semver/ranges/simplify.js +47 -0
  113. package/dist/node_modules/semver/ranges/subset.js +247 -0
  114. package/dist/node_modules/semver/ranges/to-comparators.js +8 -0
  115. package/dist/node_modules/semver/ranges/valid.js +11 -0
  116. package/dist/node_modules/sharp/LICENSE +191 -0
  117. package/dist/node_modules/sharp/README.md +118 -0
  118. package/dist/node_modules/sharp/install/check.js +36 -0
  119. package/dist/node_modules/sharp/lib/channel.js +174 -0
  120. package/dist/node_modules/sharp/lib/colour.js +182 -0
  121. package/dist/node_modules/sharp/lib/composite.js +210 -0
  122. package/dist/node_modules/sharp/lib/constructor.js +444 -0
  123. package/dist/node_modules/sharp/lib/index.d.ts +1717 -0
  124. package/dist/node_modules/sharp/lib/index.js +16 -0
  125. package/dist/node_modules/sharp/lib/input.js +657 -0
  126. package/dist/node_modules/sharp/lib/is.js +169 -0
  127. package/dist/node_modules/sharp/lib/libvips.js +171 -0
  128. package/dist/node_modules/sharp/lib/operation.js +919 -0
  129. package/dist/node_modules/sharp/lib/output.js +1561 -0
  130. package/dist/node_modules/sharp/lib/resize.js +582 -0
  131. package/dist/node_modules/sharp/lib/sharp.js +86 -0
  132. package/dist/node_modules/sharp/lib/utility.js +287 -0
  133. package/dist/node_modules/sharp/package.json +219 -0
  134. package/dist/node_modules/sharp/src/binding.gyp +277 -0
  135. package/dist/node_modules/sharp/src/common.cc +1090 -0
  136. package/dist/node_modules/sharp/src/common.h +393 -0
  137. package/dist/node_modules/sharp/src/metadata.cc +287 -0
  138. package/dist/node_modules/sharp/src/metadata.h +82 -0
  139. package/dist/node_modules/sharp/src/operations.cc +471 -0
  140. package/dist/node_modules/sharp/src/operations.h +125 -0
  141. package/dist/node_modules/sharp/src/pipeline.cc +1724 -0
  142. package/dist/node_modules/sharp/src/pipeline.h +385 -0
  143. package/dist/node_modules/sharp/src/sharp.cc +40 -0
  144. package/dist/node_modules/sharp/src/stats.cc +183 -0
  145. package/dist/node_modules/sharp/src/stats.h +59 -0
  146. package/dist/node_modules/sharp/src/utilities.cc +269 -0
  147. package/dist/node_modules/sharp/src/utilities.h +19 -0
  148. package/dist/node_modules/simple-swizzle/LICENSE +21 -0
  149. package/dist/node_modules/simple-swizzle/README.md +39 -0
  150. package/dist/node_modules/simple-swizzle/index.js +29 -0
  151. package/dist/node_modules/simple-swizzle/package.json +36 -0
  152. package/dist/package-lock.json +610 -0
  153. package/dist/package.json +40 -0
  154. package/dist/static/expected_tile_2193_153_255_z7.png +0 -0
  155. package/dist/static/expected_tile_NZTM2000Quad_30_33_z6.png +0 -0
  156. package/dist/static/expected_tile_WebMercatorQuad_252_156_z8.png +0 -0
  157. package/package.json +6 -6
  158. package/src/routes/__tests__/tile.style.json.test.ts +3 -2
  159. package/src/routes/tile.style.json.ts +1 -1
  160. package/src/util/__test__/nztm.style.test.ts +18 -8
  161. package/src/util/nztm.style.ts +0 -3
  162. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,118 @@
1
+ # sharp
2
+
3
+ <img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
4
+
5
+ The typical use case for this high speed Node-API module
6
+ is to convert large images in common formats to
7
+ smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
8
+
9
+ It can be used with all JavaScript runtimes
10
+ that provide support for Node-API v9, including
11
+ Node.js >= 18.17.0, Deno and Bun.
12
+
13
+ Resizing an image is typically 4x-5x faster than using the
14
+ quickest ImageMagick and GraphicsMagick settings
15
+ due to its use of [libvips](https://github.com/libvips/libvips).
16
+
17
+ Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
18
+ Lanczos resampling ensures quality is not sacrificed for speed.
19
+
20
+ As well as image resizing, operations such as
21
+ rotation, extraction, compositing and gamma correction are available.
22
+
23
+ Most modern macOS, Windows and Linux systems
24
+ do not require any additional install or runtime dependencies.
25
+
26
+ ## Documentation
27
+
28
+ Visit [sharp.pixelplumbing.com](https://sharp.pixelplumbing.com/) for complete
29
+ [installation instructions](https://sharp.pixelplumbing.com/install),
30
+ [API documentation](https://sharp.pixelplumbing.com/api-constructor),
31
+ [benchmark tests](https://sharp.pixelplumbing.com/performance) and
32
+ [changelog](https://sharp.pixelplumbing.com/changelog).
33
+
34
+ ## Examples
35
+
36
+ ```sh
37
+ npm install sharp
38
+ ```
39
+
40
+ ```javascript
41
+ const sharp = require('sharp');
42
+ ```
43
+
44
+ ### Callback
45
+
46
+ ```javascript
47
+ sharp(inputBuffer)
48
+ .resize(320, 240)
49
+ .toFile('output.webp', (err, info) => { ... });
50
+ ```
51
+
52
+ ### Promise
53
+
54
+ ```javascript
55
+ sharp('input.jpg')
56
+ .rotate()
57
+ .resize(200)
58
+ .jpeg({ mozjpeg: true })
59
+ .toBuffer()
60
+ .then( data => { ... })
61
+ .catch( err => { ... });
62
+ ```
63
+
64
+ ### Async/await
65
+
66
+ ```javascript
67
+ const semiTransparentRedPng = await sharp({
68
+ create: {
69
+ width: 48,
70
+ height: 48,
71
+ channels: 4,
72
+ background: { r: 255, g: 0, b: 0, alpha: 0.5 }
73
+ }
74
+ })
75
+ .png()
76
+ .toBuffer();
77
+ ```
78
+
79
+ ### Stream
80
+
81
+ ```javascript
82
+ const roundedCorners = Buffer.from(
83
+ '<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
84
+ );
85
+
86
+ const roundedCornerResizer =
87
+ sharp()
88
+ .resize(200, 200)
89
+ .composite([{
90
+ input: roundedCorners,
91
+ blend: 'dest-in'
92
+ }])
93
+ .png();
94
+
95
+ readableStream
96
+ .pipe(roundedCornerResizer)
97
+ .pipe(writableStream);
98
+ ```
99
+
100
+ ## Contributing
101
+
102
+ A [guide for contributors](https://github.com/lovell/sharp/blob/main/.github/CONTRIBUTING.md)
103
+ covers reporting bugs, requesting features and submitting code changes.
104
+
105
+ ## Licensing
106
+
107
+ Copyright 2013 Lovell Fuller and others.
108
+
109
+ Licensed under the Apache License, Version 2.0 (the "License");
110
+ you may not use this file except in compliance with the License.
111
+ You may obtain a copy of the License at
112
+ [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
113
+
114
+ Unless required by applicable law or agreed to in writing, software
115
+ distributed under the License is distributed on an "AS IS" BASIS,
116
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117
+ See the License for the specific language governing permissions and
118
+ limitations under the License.
@@ -0,0 +1,36 @@
1
+ // Copyright 2013 Lovell Fuller and others.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
7
+
8
+ const buildFromSource = (msg) => {
9
+ log(msg);
10
+ log('Attempting to build from source via node-gyp');
11
+ try {
12
+ require('node-addon-api');
13
+ log('Found node-addon-api');
14
+ } catch (err) {
15
+ log('Please add node-addon-api to your dependencies');
16
+ return;
17
+ }
18
+ try {
19
+ const gyp = require('node-gyp');
20
+ log(`Found node-gyp version ${gyp().version}`);
21
+ } catch (err) {
22
+ log('Please add node-gyp to your dependencies');
23
+ return;
24
+ }
25
+ log('See https://sharp.pixelplumbing.com/install#building-from-source');
26
+ const status = spawnRebuild();
27
+ if (status !== 0) {
28
+ process.exit(status);
29
+ }
30
+ };
31
+
32
+ if (useGlobalLibvips()) {
33
+ buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
34
+ } else if (process.env.npm_config_build_from_source) {
35
+ buildFromSource('Detected --build-from-source flag');
36
+ }
@@ -0,0 +1,174 @@
1
+ // Copyright 2013 Lovell Fuller and others.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ const is = require('./is');
7
+
8
+ /**
9
+ * Boolean operations for bandbool.
10
+ * @private
11
+ */
12
+ const bool = {
13
+ and: 'and',
14
+ or: 'or',
15
+ eor: 'eor'
16
+ };
17
+
18
+ /**
19
+ * Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
20
+ *
21
+ * See also {@link /api-operation#flatten|flatten}.
22
+ *
23
+ * @example
24
+ * sharp('rgba.png')
25
+ * .removeAlpha()
26
+ * .toFile('rgb.png', function(err, info) {
27
+ * // rgb.png is a 3 channel image without an alpha channel
28
+ * });
29
+ *
30
+ * @returns {Sharp}
31
+ */
32
+ function removeAlpha () {
33
+ this.options.removeAlpha = true;
34
+ return this;
35
+ }
36
+
37
+ /**
38
+ * Ensure the output image has an alpha transparency channel.
39
+ * If missing, the added alpha channel will have the specified
40
+ * transparency level, defaulting to fully-opaque (1).
41
+ * This is a no-op if the image already has an alpha channel.
42
+ *
43
+ * @since 0.21.2
44
+ *
45
+ * @example
46
+ * // rgba.png will be a 4 channel image with a fully-opaque alpha channel
47
+ * await sharp('rgb.jpg')
48
+ * .ensureAlpha()
49
+ * .toFile('rgba.png')
50
+ *
51
+ * @example
52
+ * // rgba is a 4 channel image with a fully-transparent alpha channel
53
+ * const rgba = await sharp(rgb)
54
+ * .ensureAlpha(0)
55
+ * .toBuffer();
56
+ *
57
+ * @param {number} [alpha=1] - alpha transparency level (0=fully-transparent, 1=fully-opaque)
58
+ * @returns {Sharp}
59
+ * @throws {Error} Invalid alpha transparency level
60
+ */
61
+ function ensureAlpha (alpha) {
62
+ if (is.defined(alpha)) {
63
+ if (is.number(alpha) && is.inRange(alpha, 0, 1)) {
64
+ this.options.ensureAlpha = alpha;
65
+ } else {
66
+ throw is.invalidParameterError('alpha', 'number between 0 and 1', alpha);
67
+ }
68
+ } else {
69
+ this.options.ensureAlpha = 1;
70
+ }
71
+ return this;
72
+ }
73
+
74
+ /**
75
+ * Extract a single channel from a multi-channel image.
76
+ *
77
+ * @example
78
+ * // green.jpg is a greyscale image containing the green channel of the input
79
+ * await sharp(input)
80
+ * .extractChannel('green')
81
+ * .toFile('green.jpg');
82
+ *
83
+ * @example
84
+ * // red1 is the red value of the first pixel, red2 the second pixel etc.
85
+ * const [red1, red2, ...] = await sharp(input)
86
+ * .extractChannel(0)
87
+ * .raw()
88
+ * .toBuffer();
89
+ *
90
+ * @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
91
+ * @returns {Sharp}
92
+ * @throws {Error} Invalid channel
93
+ */
94
+ function extractChannel (channel) {
95
+ const channelMap = { red: 0, green: 1, blue: 2, alpha: 3 };
96
+ if (Object.keys(channelMap).includes(channel)) {
97
+ channel = channelMap[channel];
98
+ }
99
+ if (is.integer(channel) && is.inRange(channel, 0, 4)) {
100
+ this.options.extractChannel = channel;
101
+ } else {
102
+ throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
103
+ }
104
+ return this;
105
+ }
106
+
107
+ /**
108
+ * Join one or more channels to the image.
109
+ * The meaning of the added channels depends on the output colourspace, set with `toColourspace()`.
110
+ * By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
111
+ * Channel ordering follows vips convention:
112
+ * - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
113
+ * - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
114
+ *
115
+ * Buffers may be any of the image formats supported by sharp.
116
+ * For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
117
+ *
118
+ * @param {Array<string|Buffer>|string|Buffer} images - one or more images (file paths, Buffers).
119
+ * @param {Object} options - image options, see `sharp()` constructor.
120
+ * @returns {Sharp}
121
+ * @throws {Error} Invalid parameters
122
+ */
123
+ function joinChannel (images, options) {
124
+ if (Array.isArray(images)) {
125
+ images.forEach(function (image) {
126
+ this.options.joinChannelIn.push(this._createInputDescriptor(image, options));
127
+ }, this);
128
+ } else {
129
+ this.options.joinChannelIn.push(this._createInputDescriptor(images, options));
130
+ }
131
+ return this;
132
+ }
133
+
134
+ /**
135
+ * Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
136
+ *
137
+ * @example
138
+ * sharp('3-channel-rgb-input.png')
139
+ * .bandbool(sharp.bool.and)
140
+ * .toFile('1-channel-output.png', function (err, info) {
141
+ * // The output will be a single channel image where each pixel `P = R & G & B`.
142
+ * // If `I(1,1) = [247, 170, 14] = [0b11110111, 0b10101010, 0b00001111]`
143
+ * // then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
144
+ * });
145
+ *
146
+ * @param {string} boolOp - one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
147
+ * @returns {Sharp}
148
+ * @throws {Error} Invalid parameters
149
+ */
150
+ function bandbool (boolOp) {
151
+ if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
152
+ this.options.bandBoolOp = boolOp;
153
+ } else {
154
+ throw is.invalidParameterError('boolOp', 'one of: and, or, eor', boolOp);
155
+ }
156
+ return this;
157
+ }
158
+
159
+ /**
160
+ * Decorate the Sharp prototype with channel-related functions.
161
+ * @private
162
+ */
163
+ module.exports = function (Sharp) {
164
+ Object.assign(Sharp.prototype, {
165
+ // Public instance functions
166
+ removeAlpha,
167
+ ensureAlpha,
168
+ extractChannel,
169
+ joinChannel,
170
+ bandbool
171
+ });
172
+ // Class attributes
173
+ Sharp.bool = bool;
174
+ };
@@ -0,0 +1,182 @@
1
+ // Copyright 2013 Lovell Fuller and others.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ const color = require('color');
7
+ const is = require('./is');
8
+
9
+ /**
10
+ * Colourspaces.
11
+ * @private
12
+ */
13
+ const colourspace = {
14
+ multiband: 'multiband',
15
+ 'b-w': 'b-w',
16
+ bw: 'b-w',
17
+ cmyk: 'cmyk',
18
+ srgb: 'srgb'
19
+ };
20
+
21
+ /**
22
+ * Tint the image using the provided colour.
23
+ * An alpha channel may be present and will be unchanged by the operation.
24
+ *
25
+ * @example
26
+ * const output = await sharp(input)
27
+ * .tint({ r: 255, g: 240, b: 16 })
28
+ * .toBuffer();
29
+ *
30
+ * @param {string|Object} tint - Parsed by the [color](https://www.npmjs.org/package/color) module.
31
+ * @returns {Sharp}
32
+ * @throws {Error} Invalid parameter
33
+ */
34
+ function tint (tint) {
35
+ this._setBackgroundColourOption('tint', tint);
36
+ return this;
37
+ }
38
+
39
+ /**
40
+ * Convert to 8-bit greyscale; 256 shades of grey.
41
+ * This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
42
+ * By default the output image will be web-friendly sRGB and contain three (identical) color channels.
43
+ * This may be overridden by other sharp operations such as `toColourspace('b-w')`,
44
+ * which will produce an output image containing one color channel.
45
+ * An alpha channel may be present, and will be unchanged by the operation.
46
+ *
47
+ * @example
48
+ * const output = await sharp(input).greyscale().toBuffer();
49
+ *
50
+ * @param {Boolean} [greyscale=true]
51
+ * @returns {Sharp}
52
+ */
53
+ function greyscale (greyscale) {
54
+ this.options.greyscale = is.bool(greyscale) ? greyscale : true;
55
+ return this;
56
+ }
57
+
58
+ /**
59
+ * Alternative spelling of `greyscale`.
60
+ * @param {Boolean} [grayscale=true]
61
+ * @returns {Sharp}
62
+ */
63
+ function grayscale (grayscale) {
64
+ return this.greyscale(grayscale);
65
+ }
66
+
67
+ /**
68
+ * Set the pipeline colourspace.
69
+ *
70
+ * The input image will be converted to the provided colourspace at the start of the pipeline.
71
+ * All operations will use this colourspace before converting to the output colourspace,
72
+ * as defined by {@link #tocolourspace|toColourspace}.
73
+ *
74
+ * This feature is experimental and has not yet been fully-tested with all operations.
75
+ *
76
+ * @since 0.29.0
77
+ *
78
+ * @example
79
+ * // Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
80
+ * await sharp(input)
81
+ * .pipelineColourspace('rgb16')
82
+ * .toColourspace('srgb')
83
+ * .toFile('16bpc-pipeline-to-8bpc-output.png')
84
+ *
85
+ * @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774)
86
+ * @returns {Sharp}
87
+ * @throws {Error} Invalid parameters
88
+ */
89
+ function pipelineColourspace (colourspace) {
90
+ if (!is.string(colourspace)) {
91
+ throw is.invalidParameterError('colourspace', 'string', colourspace);
92
+ }
93
+ this.options.colourspaceInput = colourspace;
94
+ return this;
95
+ }
96
+
97
+ /**
98
+ * Alternative spelling of `pipelineColourspace`.
99
+ * @param {string} [colorspace] - pipeline colorspace.
100
+ * @returns {Sharp}
101
+ * @throws {Error} Invalid parameters
102
+ */
103
+ function pipelineColorspace (colorspace) {
104
+ return this.pipelineColourspace(colorspace);
105
+ }
106
+
107
+ /**
108
+ * Set the output colourspace.
109
+ * By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
110
+ *
111
+ * @example
112
+ * // Output 16 bits per pixel RGB
113
+ * await sharp(input)
114
+ * .toColourspace('rgb16')
115
+ * .toFile('16-bpp.png')
116
+ *
117
+ * @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794)
118
+ * @returns {Sharp}
119
+ * @throws {Error} Invalid parameters
120
+ */
121
+ function toColourspace (colourspace) {
122
+ if (!is.string(colourspace)) {
123
+ throw is.invalidParameterError('colourspace', 'string', colourspace);
124
+ }
125
+ this.options.colourspace = colourspace;
126
+ return this;
127
+ }
128
+
129
+ /**
130
+ * Alternative spelling of `toColourspace`.
131
+ * @param {string} [colorspace] - output colorspace.
132
+ * @returns {Sharp}
133
+ * @throws {Error} Invalid parameters
134
+ */
135
+ function toColorspace (colorspace) {
136
+ return this.toColourspace(colorspace);
137
+ }
138
+
139
+ /**
140
+ * Update a colour attribute of the this.options Object.
141
+ * @private
142
+ * @param {string} key
143
+ * @param {string|Object} value
144
+ * @throws {Error} Invalid value
145
+ */
146
+ function _setBackgroundColourOption (key, value) {
147
+ if (is.defined(value)) {
148
+ if (is.object(value) || is.string(value)) {
149
+ const colour = color(value);
150
+ this.options[key] = [
151
+ colour.red(),
152
+ colour.green(),
153
+ colour.blue(),
154
+ Math.round(colour.alpha() * 255)
155
+ ];
156
+ } else {
157
+ throw is.invalidParameterError('background', 'object or string', value);
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Decorate the Sharp prototype with colour-related functions.
164
+ * @private
165
+ */
166
+ module.exports = function (Sharp) {
167
+ Object.assign(Sharp.prototype, {
168
+ // Public
169
+ tint,
170
+ greyscale,
171
+ grayscale,
172
+ pipelineColourspace,
173
+ pipelineColorspace,
174
+ toColourspace,
175
+ toColorspace,
176
+ // Private
177
+ _setBackgroundColourOption
178
+ });
179
+ // Class attributes
180
+ Sharp.colourspace = colourspace;
181
+ Sharp.colorspace = colourspace;
182
+ };