-
Notifications
You must be signed in to change notification settings - Fork 1
/
gaborConvolution2.js
70 lines (57 loc) · 1.68 KB
/
gaborConvolution2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict";
var Module = {
locateFile: function (s) {
return '../c/' + s;
},
onRuntimeInitialized: function() {
gaborConvolution2();
}
};
importScripts("../c/main.js");
var f = [];
var xi = 0;
var sigma = 0;
var lambda = 0;
var theta = 0;
var amount = 0;
var onmessage = function(messageEvent) {
f = messageEvent.data.f;
xi = messageEvent.data.xi;
sigma = messageEvent.data.sigma;
lambda = messageEvent.data.lambda;
theta = messageEvent.data.theta;
amount = messageEvent.data.amount;
}
var gaborConvolution2 = function() {
// Check size
if (f.length <= 0) {
console.error("Input data length is 0.");
return f;
}
const n = Math.sqrt(f.length);
if (n % 1 !== 0 || Math.log2(n) % 1 !== 0) {
console.error("Input data length is not power of 2.");
return f;
}
// Generate float arrays
var fConv = new Float32Array(f.length); // convoluted image
// Call c code
try {
const buffer1 = Module._malloc(f.length * f.BYTES_PER_ELEMENT);
const buffer2 = Module._malloc(fConv.length * fConv.BYTES_PER_ELEMENT);
Module.HEAPF32.set(f, buffer1 >> 2);
Module.HEAPF32.set(fConv, buffer2 >> 2);
Module.ccall(
"fgc2",
null,
["number", "number", "number", "number", "number", "number", "number", "number"],
[buffer1, buffer2, n, xi, sigma, lambda, theta, amount]
);
fConv = new Float32Array(Module.HEAPF32.buffer, buffer2, fConv.length);
Module._free(buffer1);
Module._free(buffer2);
} catch (e) {
console.error(e);
}
postMessage({fConv: Array.from(fConv)});
}