rust-editor 0.3.3 → 0.3.5

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/README.md CHANGED
@@ -1 +1,66 @@
1
- # rust-img-editor
1
+ # rust-editor
2
+
3
+ This page is provide documentation of rust-editor package built with Rust compiled to WASM (WebAssembly), and simple implementation of use.
4
+
5
+ ## Key Feature
6
+ This package is provide several image processing algorithm such as:
7
+ 1. Transfer Color: Apply color scheme from "Image Reference" to "Image Target".
8
+ 2. Sharpen: Enhance edge definition using function from image dependencies.
9
+ 3. Color Adjustment: Fine-tune Saturation, Temperature, adn Tint of Image Target.
10
+ 4. Light Adjustment: Contrast and Exposure Adjustments.
11
+
12
+ ## Build WASM package
13
+
14
+ Before building the package, you must first install `wasm-pack`.
15
+
16
+ ```bash
17
+ cargo install wasm-pack
18
+ ```
19
+
20
+ Then you can clone this repository and build package with running command bellow.
21
+
22
+ ```bash
23
+ wasm-pack build --target web
24
+ ```
25
+
26
+ ```
27
+ .
28
+ └── RustEditor/
29
+ ├── pkg/ <--------------------build result
30
+ │ ├── package.json
31
+ │ ├── README.md
32
+ │ ├── rust_editor_bg.wasm
33
+ │ ├── rust_editor_bg.wasm.d.ts
34
+ │ └── rust_editor.d.ts
35
+ ├── site/
36
+ │ ├── index.html
37
+ │ ├── main.js
38
+ │ ├── style.css
39
+ │ ├── assets/
40
+ │ ├── README.md
41
+ │ └── package.json
42
+ ├── src/
43
+ │ ├── color.rs
44
+ │ ├── image_size.rs
45
+ │ ├── lab_converter.rs
46
+ │ ├── lib.rs
47
+ │ ├── light.rs
48
+ │ └── switch_color.rs
49
+ ├── .gitignore
50
+ ├── Cargo.lock
51
+ ├── Cargo.toml
52
+ └── LICENSE
53
+ ```
54
+
55
+ Then look in your project directory you must find new directory with folder name `pkg`, on that folder you'll find some file like js, ts, and wasm file. file `.wasm` is result of compile Rust code using `wasm-pack`, file `.js` and `.ts` is bridge for frontEnd can comunicate with `.wasm` file.
56
+
57
+ you can look published this documentation on this [link](https://www.npmjs.com/package/rust-editor)
58
+
59
+ ## Demo
60
+ This documentation is also provide demo, so you can try how to use and how the application work. You can jump to `/site` directory foolow command bellow.
61
+
62
+ ```bash
63
+ cd side
64
+ npm install // install all depencencies
65
+ npx parcel index.html // run project using parceljs
66
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rust-editor",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "files": [
6
6
  "rust_editor_bg.wasm",
7
7
  "rust_editor.js",
package/rust_editor.d.ts CHANGED
@@ -5,6 +5,7 @@ export function switch_color(image_source: Uint8Array, image_reference: Uint8Arr
5
5
  export function blur(image_data: Uint8Array, radius: number): Uint8Array;
6
6
  export function sharpen(image_data: Uint8Array, radius: number): Uint8Array;
7
7
  export function fix_size_image(image_data: Uint8Array): Uint8Array;
8
+ export function extend_size_image(image_data: Uint8Array, size_type: string): Uint8Array;
8
9
  export function grayscale_image(image_data: Uint8Array): Uint8Array;
9
10
  export function adjust_saturation_image(image_data: Uint8Array, saturation: number): Uint8Array;
10
11
  export function adjust_temperature_image(image_data: Uint8Array, temperature: number): Uint8Array;
@@ -23,6 +24,7 @@ export interface InitOutput {
23
24
  readonly blur: (a: number, b: number, c: number) => [number, number];
24
25
  readonly sharpen: (a: number, b: number, c: number) => [number, number];
25
26
  readonly fix_size_image: (a: number, b: number) => [number, number];
27
+ readonly extend_size_image: (a: number, b: number, c: number, d: number) => [number, number];
26
28
  readonly grayscale_image: (a: number, b: number) => [number, number];
27
29
  readonly adjust_saturation_image: (a: number, b: number, c: number) => [number, number];
28
30
  readonly adjust_temperature_image: (a: number, b: number, c: number) => [number, number];
@@ -34,6 +36,7 @@ export interface InitOutput {
34
36
  readonly __wbindgen_export_0: WebAssembly.Table;
35
37
  readonly __wbindgen_malloc: (a: number, b: number) => number;
36
38
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
39
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
37
40
  readonly __wbindgen_start: () => void;
38
41
  }
39
42
 
package/rust_editor.js CHANGED
@@ -105,6 +105,75 @@ export function fix_size_image(image_data) {
105
105
  return v2;
106
106
  }
107
107
 
108
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
109
+
110
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
111
+ ? function (arg, view) {
112
+ return cachedTextEncoder.encodeInto(arg, view);
113
+ }
114
+ : function (arg, view) {
115
+ const buf = cachedTextEncoder.encode(arg);
116
+ view.set(buf);
117
+ return {
118
+ read: arg.length,
119
+ written: buf.length
120
+ };
121
+ });
122
+
123
+ function passStringToWasm0(arg, malloc, realloc) {
124
+
125
+ if (realloc === undefined) {
126
+ const buf = cachedTextEncoder.encode(arg);
127
+ const ptr = malloc(buf.length, 1) >>> 0;
128
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
129
+ WASM_VECTOR_LEN = buf.length;
130
+ return ptr;
131
+ }
132
+
133
+ let len = arg.length;
134
+ let ptr = malloc(len, 1) >>> 0;
135
+
136
+ const mem = getUint8ArrayMemory0();
137
+
138
+ let offset = 0;
139
+
140
+ for (; offset < len; offset++) {
141
+ const code = arg.charCodeAt(offset);
142
+ if (code > 0x7F) break;
143
+ mem[ptr + offset] = code;
144
+ }
145
+
146
+ if (offset !== len) {
147
+ if (offset !== 0) {
148
+ arg = arg.slice(offset);
149
+ }
150
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
151
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
152
+ const ret = encodeString(arg, view);
153
+
154
+ offset += ret.written;
155
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
156
+ }
157
+
158
+ WASM_VECTOR_LEN = offset;
159
+ return ptr;
160
+ }
161
+ /**
162
+ * @param {Uint8Array} image_data
163
+ * @param {string} size_type
164
+ * @returns {Uint8Array}
165
+ */
166
+ export function extend_size_image(image_data, size_type) {
167
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
168
+ const len0 = WASM_VECTOR_LEN;
169
+ const ptr1 = passStringToWasm0(size_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
+ const len1 = WASM_VECTOR_LEN;
171
+ const ret = wasm.extend_size_image(ptr0, len0, ptr1, len1);
172
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
173
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
174
+ return v3;
175
+ }
176
+
108
177
  /**
109
178
  * @param {Uint8Array} image_data
110
179
  * @returns {Uint8Array}
Binary file