wasm-image-processor 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "wasm-image-processor",
3
- "type": "module",
4
3
  "collaborators": [
5
4
  "Stanley Masinde <hello@stanleymasinde.com>"
6
5
  ],
7
6
  "description": "High-performance client-side image processing toolkit powered by Rust and WebAssembly",
8
- "version": "0.4.0",
7
+ "version": "0.5.0",
9
8
  "license": "MIT",
10
9
  "repository": {
11
10
  "type": "git",
@@ -17,7 +16,7 @@
17
16
  "wasm_image_processor_bg.js",
18
17
  "wasm_image_processor.d.ts"
19
18
  ],
20
- "main": "wasm_image_processor.js",
19
+ "module": "wasm_image_processor.js",
21
20
  "homepage": "https://github.com/StanleyMasinde/wasm-image-processor",
22
21
  "types": "wasm_image_processor.d.ts",
23
22
  "sideEffects": [
@@ -1,5 +1,64 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * Invert the colors on this image.
5
+ */
6
+ export function invert(image_data: Uint8Array): Uint8Array;
7
+ /**
8
+ * Hue rotate the supplied image.
9
+ * `value` is the degrees to rotate each pixel by.
10
+ * 0 and 360 do nothing, the rest rotates by the given degree value.
11
+ * just like the css webkit filter hue-rotate(180)
12
+ */
13
+ export function hue_rotate(image_data: Uint8Array, degrees: number): Uint8Array;
14
+ /**
15
+ * Scale this image down to fit within a specific size.
16
+ * Returns a new image. The image's aspect ratio is preserved.
17
+ * The image is scaled to the maximum possible size that fits
18
+ * within the bounds specified by `nwidth` and `nheight`.
19
+ *
20
+ * This method uses a fast integer algorithm where each source
21
+ * pixel contributes to exactly one target pixel.
22
+ * May give aliasing artifacts if new size is close to old size.
23
+ */
24
+ export function thumbnail(image_data: Uint8Array, width: number, height: number): Uint8Array;
25
+ /**
26
+ * Adjust the contrast of this image.
27
+ * `contrast` is the amount to adjust the contrast by.
28
+ * Negative values decrease the contrast and positive values increase the contrast.
29
+ */
30
+ export function contrast(image_data: Uint8Array, value: number): Uint8Array;
31
+ /**
32
+ * Performs a Gaussian blur on this image.
33
+ * `sigma` is a measure of how much to blur by.
34
+ * Use a value of less than 5
35
+ */
36
+ export function blur(image_data: Uint8Array, sigma: number): Uint8Array;
37
+ /**
38
+ * Performs a fast blur on this image.
39
+ * `sigma` is the standard deviation of the
40
+ * (approximated) Gaussian
41
+ */
42
+ export function fast_blur(image_data: Uint8Array, sigma: number): Uint8Array;
43
+ /**
44
+ * Resize an image
45
+ * Take an array of bytes, the len and the width
46
+ * The image's aspect ratio is preserved.
47
+ * The image is scaled to the maximum possible size that fits
48
+ * within the bounds specified by `width` and `height`
49
+ */
50
+ export function resize(image_data: Uint8Array, width: number, height: number): Uint8Array;
51
+ /**
52
+ * Return a cut-out of this image delimited by the bounding rectangle.
53
+ */
54
+ export function crop(image_data: Uint8Array, x: number, y: number, width: number, height: number): Uint8Array;
55
+ /**
56
+ * Add grayscale effect to image
57
+ * Return a grayscale version of this image.
58
+ * Returns `Luma` images in most cases. However, for `f32` images,
59
+ * this will return a grayscale `Rgb/Rgba` image instead.
60
+ */
61
+ export function grayscale(image_data: Uint8Array): Uint8Array;
3
62
  /**
4
63
  * Resize an image by the given dimension.
5
64
  * The first parameter is an array of bytes.
@@ -9,3 +68,8 @@
9
68
  * It is is ideal for icon resizing.
10
69
  */
11
70
  export function resize_square(image_data: Uint8Array, side: number): Uint8Array;
71
+ /**
72
+ * Brighten image
73
+ * The value is -100 to 100
74
+ */
75
+ export function brighten(image_data: Uint8Array, value: number): Uint8Array;
@@ -43,6 +43,194 @@ function getArrayU8FromWasm0(ptr, len) {
43
43
  ptr = ptr >>> 0;
44
44
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
45
45
  }
46
+ /**
47
+ * Invert the colors on this image.
48
+ * @param {Uint8Array} image_data
49
+ * @returns {Uint8Array}
50
+ */
51
+ export function invert(image_data) {
52
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
53
+ const len0 = WASM_VECTOR_LEN;
54
+ const ret = wasm.invert(ptr0, len0);
55
+ if (ret[3]) {
56
+ throw takeFromExternrefTable0(ret[2]);
57
+ }
58
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
59
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
60
+ return v2;
61
+ }
62
+
63
+ /**
64
+ * Hue rotate the supplied image.
65
+ * `value` is the degrees to rotate each pixel by.
66
+ * 0 and 360 do nothing, the rest rotates by the given degree value.
67
+ * just like the css webkit filter hue-rotate(180)
68
+ * @param {Uint8Array} image_data
69
+ * @param {number} degrees
70
+ * @returns {Uint8Array}
71
+ */
72
+ export function hue_rotate(image_data, degrees) {
73
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
74
+ const len0 = WASM_VECTOR_LEN;
75
+ const ret = wasm.hue_rotate(ptr0, len0, degrees);
76
+ if (ret[3]) {
77
+ throw takeFromExternrefTable0(ret[2]);
78
+ }
79
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
80
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
81
+ return v2;
82
+ }
83
+
84
+ /**
85
+ * Scale this image down to fit within a specific size.
86
+ * Returns a new image. The image's aspect ratio is preserved.
87
+ * The image is scaled to the maximum possible size that fits
88
+ * within the bounds specified by `nwidth` and `nheight`.
89
+ *
90
+ * This method uses a fast integer algorithm where each source
91
+ * pixel contributes to exactly one target pixel.
92
+ * May give aliasing artifacts if new size is close to old size.
93
+ * @param {Uint8Array} image_data
94
+ * @param {number} width
95
+ * @param {number} height
96
+ * @returns {Uint8Array}
97
+ */
98
+ export function thumbnail(image_data, width, height) {
99
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
100
+ const len0 = WASM_VECTOR_LEN;
101
+ const ret = wasm.thumbnail(ptr0, len0, width, height);
102
+ if (ret[3]) {
103
+ throw takeFromExternrefTable0(ret[2]);
104
+ }
105
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
106
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
107
+ return v2;
108
+ }
109
+
110
+ /**
111
+ * Adjust the contrast of this image.
112
+ * `contrast` is the amount to adjust the contrast by.
113
+ * Negative values decrease the contrast and positive values increase the contrast.
114
+ * @param {Uint8Array} image_data
115
+ * @param {number} value
116
+ * @returns {Uint8Array}
117
+ */
118
+ export function contrast(image_data, value) {
119
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
120
+ const len0 = WASM_VECTOR_LEN;
121
+ const ret = wasm.contrast(ptr0, len0, value);
122
+ if (ret[3]) {
123
+ throw takeFromExternrefTable0(ret[2]);
124
+ }
125
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
126
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
127
+ return v2;
128
+ }
129
+
130
+ /**
131
+ * Performs a Gaussian blur on this image.
132
+ * `sigma` is a measure of how much to blur by.
133
+ * Use a value of less than 5
134
+ * @param {Uint8Array} image_data
135
+ * @param {number} sigma
136
+ * @returns {Uint8Array}
137
+ */
138
+ export function blur(image_data, sigma) {
139
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
140
+ const len0 = WASM_VECTOR_LEN;
141
+ const ret = wasm.blur(ptr0, len0, sigma);
142
+ if (ret[3]) {
143
+ throw takeFromExternrefTable0(ret[2]);
144
+ }
145
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
146
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
147
+ return v2;
148
+ }
149
+
150
+ /**
151
+ * Performs a fast blur on this image.
152
+ * `sigma` is the standard deviation of the
153
+ * (approximated) Gaussian
154
+ * @param {Uint8Array} image_data
155
+ * @param {number} sigma
156
+ * @returns {Uint8Array}
157
+ */
158
+ export function fast_blur(image_data, sigma) {
159
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
160
+ const len0 = WASM_VECTOR_LEN;
161
+ const ret = wasm.fast_blur(ptr0, len0, sigma);
162
+ if (ret[3]) {
163
+ throw takeFromExternrefTable0(ret[2]);
164
+ }
165
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
166
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
167
+ return v2;
168
+ }
169
+
170
+ /**
171
+ * Resize an image
172
+ * Take an array of bytes, the len and the width
173
+ * The image's aspect ratio is preserved.
174
+ * The image is scaled to the maximum possible size that fits
175
+ * within the bounds specified by `width` and `height`
176
+ * @param {Uint8Array} image_data
177
+ * @param {number} width
178
+ * @param {number} height
179
+ * @returns {Uint8Array}
180
+ */
181
+ export function resize(image_data, width, height) {
182
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
183
+ const len0 = WASM_VECTOR_LEN;
184
+ const ret = wasm.resize(ptr0, len0, width, height);
185
+ if (ret[3]) {
186
+ throw takeFromExternrefTable0(ret[2]);
187
+ }
188
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
189
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
190
+ return v2;
191
+ }
192
+
193
+ /**
194
+ * Return a cut-out of this image delimited by the bounding rectangle.
195
+ * @param {Uint8Array} image_data
196
+ * @param {number} x
197
+ * @param {number} y
198
+ * @param {number} width
199
+ * @param {number} height
200
+ * @returns {Uint8Array}
201
+ */
202
+ export function crop(image_data, x, y, width, height) {
203
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
204
+ const len0 = WASM_VECTOR_LEN;
205
+ const ret = wasm.crop(ptr0, len0, x, y, width, height);
206
+ if (ret[3]) {
207
+ throw takeFromExternrefTable0(ret[2]);
208
+ }
209
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
210
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
211
+ return v2;
212
+ }
213
+
214
+ /**
215
+ * Add grayscale effect to image
216
+ * Return a grayscale version of this image.
217
+ * Returns `Luma` images in most cases. However, for `f32` images,
218
+ * this will return a grayscale `Rgb/Rgba` image instead.
219
+ * @param {Uint8Array} image_data
220
+ * @returns {Uint8Array}
221
+ */
222
+ export function grayscale(image_data) {
223
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
224
+ const len0 = WASM_VECTOR_LEN;
225
+ const ret = wasm.grayscale(ptr0, len0);
226
+ if (ret[3]) {
227
+ throw takeFromExternrefTable0(ret[2]);
228
+ }
229
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
230
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
231
+ return v2;
232
+ }
233
+
46
234
  /**
47
235
  * Resize an image by the given dimension.
48
236
  * The first parameter is an array of bytes.
@@ -66,6 +254,25 @@ export function resize_square(image_data, side) {
66
254
  return v2;
67
255
  }
68
256
 
257
+ /**
258
+ * Brighten image
259
+ * The value is -100 to 100
260
+ * @param {Uint8Array} image_data
261
+ * @param {number} value
262
+ * @returns {Uint8Array}
263
+ */
264
+ export function brighten(image_data, value) {
265
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
266
+ const len0 = WASM_VECTOR_LEN;
267
+ const ret = wasm.brighten(ptr0, len0, value);
268
+ if (ret[3]) {
269
+ throw takeFromExternrefTable0(ret[2]);
270
+ }
271
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
272
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
273
+ return v2;
274
+ }
275
+
69
276
  export function __wbindgen_init_externref_table() {
70
277
  const table = wasm.__wbindgen_export_0;
71
278
  const offset = table.grow(4);
Binary file